-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4492 from NativeScript/fatme/kinvey-schema
feat(kinvey): provide correct data to preview-sdk based on the schema
- Loading branch information
Showing
13 changed files
with
206 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
lib/services/livesync/playground/preview-schema-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { PubnubKeys } from "./preview-app-constants"; | ||
|
||
export class PreviewSchemaService implements IPreviewSchemaService { | ||
private previewSchemas: IDictionary<IPreviewSchemaData> = { | ||
"nsplay": { | ||
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 | ||
}, | ||
"ksplay": { | ||
name: "ksplay", | ||
scannerAppId: "com.kinvey.scanner", | ||
scannerAppStoreId: "1263543946", | ||
previewAppId: "com.kinvey.preview", | ||
previewAppStoreId: "1264484702", | ||
msvKey: "kinveyStudio", | ||
publishKey: PubnubKeys.PUBLISH_KEY, | ||
subscribeKey: PubnubKeys.SUBSCRIBE_KEY | ||
} | ||
}; | ||
|
||
constructor(private $errors: IErrors, | ||
private $projectDataService: IProjectDataService) { } | ||
|
||
public getSchemaData(projectDir: string): IPreviewSchemaData { | ||
let schemaName = this.getSchemaNameFromProject(projectDir); | ||
if (!schemaName) { | ||
schemaName = _.findKey(this.previewSchemas, previewSchema => previewSchema.default); | ||
} | ||
|
||
const result = this.previewSchemas[schemaName]; | ||
if (!result) { | ||
this.$errors.failWithoutHelp(`Invalid schema. The valid schemas are ${_.keys(this.previewSchemas)}.`); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private getSchemaNameFromProject(projectDir: string): string { | ||
try { | ||
const projectData = this.$projectDataService.getProjectData(projectDir); | ||
return projectData.previewAppSchema; | ||
} catch (err) { /* ignore the error */ } | ||
|
||
return null; | ||
} | ||
} | ||
$injector.register("previewSchemaService", PreviewSchemaService); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.