-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathpreview-schema-service.ts
89 lines (78 loc) · 2.62 KB
/
preview-schema-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { Yok } from "../../../lib/common/yok";
import { PreviewSchemaService } from "../../../lib/services/livesync/playground/preview-schema-service";
import { PubnubKeys } from "../../../lib/services/livesync/playground/preview-app-constants";
import { assert } from "chai";
function createTestInjector(): IInjector {
const injector = new Yok();
injector.register("previewSchemaService", PreviewSchemaService);
injector.register("projectDataService", () => ({}));
injector.register("errors", () => ({}));
return injector;
}
const nsPlaySchema = {
name: 'nsplay',
scannerAppId: 'org.nativescript.play',
scannerAppStoreId: '1263543946',
previewAppId: 'org.nativescript.preview',
previewAppStoreId: '1264484702',
msvKey: 'cli',
publishKey: PubnubKeys.PUBLISH_KEY,
subscribeKey: PubnubKeys.SUBSCRIBE_KEY,
default: true
};
const ksPlaySchema = {
name: 'ksplay',
scannerAppId: 'com.kinvey.scanner',
scannerAppStoreId: '1263543946',
previewAppId: 'com.kinvey.preview',
previewAppStoreId: '1264484702',
msvKey: 'kinveyStudio',
publishKey: PubnubKeys.PUBLISH_KEY,
subscribeKey: PubnubKeys.SUBSCRIBE_KEY
};
describe("PreviewSchemaService", () => {
let injector: IInjector;
let previewSchemaService: IPreviewSchemaService;
beforeEach(() => {
injector = createTestInjector();
previewSchemaService = injector.resolve("previewSchemaService");
});
const testCases = [
{
name: "should return default nsplay schema when no previewAppSchema in nsconfig",
previewAppSchema: <any>null,
expectedSchema: nsPlaySchema
},
{
name: "should return nsplay schema when { 'previewAppSchema': 'nsplay' } in nsconfig",
previewAppSchema: "nsplay",
expectedSchema: nsPlaySchema
},
{
name: "should return ksplay schema when { 'previewAppSchema': 'ksplay' } in nsconfig",
previewAppSchema: "ksplay",
expectedSchema: ksPlaySchema
},
{
name: "should throw an error when invalid previewAppSchema is specified in nsconfig",
previewAppSchema: "someInvalidSchema",
expectedToThrow: true
}
];
_.each(testCases, testCase => {
it(`${testCase.name}`, () => {
const projectDataService = injector.resolve("projectDataService");
projectDataService.getProjectData = () => ({ previewAppSchema: testCase.previewAppSchema });
let actualError = null;
if (testCase.expectedToThrow) {
const errors = injector.resolve("errors");
errors.failWithoutHelp = (err: string) => actualError = err;
}
const schemaData = previewSchemaService.getSchemaData("someTestProjectDir");
assert.deepEqual(schemaData, testCase.expectedSchema);
if (testCase.expectedToThrow) {
assert.isNotNull(actualError);
}
});
});
});