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