-
Notifications
You must be signed in to change notification settings - Fork 407
Add #set and #toJSON to RC ServerTemplate #2522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b171d2b
f427727
3d8d3d4
18f5630
44101ea
05ba48c
9bbe9e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -955,10 +955,6 @@ describe('RemoteConfig', () => { | |
| }); | ||
|
|
||
| describe('set', () => { | ||
| const INVALID_PARAMETERS: any[] = [null, '', 'abc', 1, true, []]; | ||
| const INVALID_CONDITIONS: any[] = [null, '', 'abc', 1, true, {}]; | ||
| let sourceTemplate = deepCopy(SERVER_REMOTE_CONFIG_RESPONSE); | ||
|
|
||
| it('should set template when passed', () => { | ||
| const template = deepCopy(SERVER_REMOTE_CONFIG_RESPONSE) as ServerTemplateData; | ||
| template.parameters = { | ||
|
|
@@ -970,13 +966,14 @@ describe('RemoteConfig', () => { | |
| valueType: 'STRING' | ||
| } | ||
| }; | ||
| template.version = { | ||
| ...deepCopy(VERSION_INFO), | ||
| updateTime: new Date(VERSION_INFO.updateTime).toUTCString() | ||
| } as Version; | ||
| const initializedTemplate = remoteConfig.initServerTemplate(); | ||
| initializedTemplate.set(template); | ||
| const parsed = initializedTemplate.toJSON(); | ||
| const expectedVersion = deepCopy(VERSION_INFO); | ||
| expectedVersion.updateTime = new Date(expectedVersion.updateTime).toUTCString(); | ||
| template.version = expectedVersion as Version; | ||
| expect(parsed).deep.equals(deepCopy(template)); | ||
| expect(parsed).deep.equals(template); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very readable 👍 |
||
| }); | ||
|
|
||
| it('should set and instantiates template when json string is passed', () => { | ||
|
|
@@ -990,44 +987,54 @@ describe('RemoteConfig', () => { | |
| valueType: 'STRING' | ||
| } | ||
| }; | ||
| template.version = { | ||
| ...deepCopy(VERSION_INFO), | ||
| updateTime: new Date(VERSION_INFO.updateTime).toUTCString() | ||
| } as Version; | ||
| const templateJson = JSON.stringify(template); | ||
| const initializedTemplate = remoteConfig.initServerTemplate(); | ||
| initializedTemplate.set(templateJson); | ||
| const parsed = initializedTemplate.toJSON(); | ||
| const expectedVersion = deepCopy(VERSION_INFO); | ||
| expectedVersion.updateTime = new Date(expectedVersion.updateTime).toUTCString(); | ||
| template.version = expectedVersion as Version; | ||
| expect(parsed).deep.equals(deepCopy(template)); | ||
| expect(parsed).deep.equals(template); | ||
| }); | ||
|
|
||
| it('should throw if template is an invalid JSON', () => { | ||
| describe('should throw error if there are any JSON or tempalte parsing errors', () => { | ||
| const INVALID_PARAMETERS: any[] = [null, '', 'abc', 1, true, []]; | ||
| const INVALID_CONDITIONS: any[] = [null, '', 'abc', 1, true, {}]; | ||
|
|
||
| let sourceTemplate = deepCopy(SERVER_REMOTE_CONFIG_RESPONSE); | ||
| const jsonString = '{invalidJson: null}'; | ||
| const initializedTemplate = remoteConfig.initServerTemplate(); | ||
| expect(() => initializedTemplate.set(jsonString)) | ||
| .to.throw(/Failed to parse the JSON string: ([\D\w]*)\./); | ||
| }); | ||
|
|
||
| INVALID_PARAMETERS.forEach((invalidParameter) => { | ||
| sourceTemplate.parameters = invalidParameter; | ||
| it(`should throw if the parameters is ${JSON.stringify(invalidParameter)}`, () => { | ||
| const jsonString = JSON.stringify(sourceTemplate); | ||
| const initializedTemplate = remoteConfig.initServerTemplate(); | ||
| expect(() => initializedTemplate.set(jsonString)) | ||
| it('should throw if template is an invalid JSON', () => { | ||
| expect(() => remoteConfig.initServerTemplate({ template: jsonString })) | ||
| .to.throw(/Failed to parse the JSON string: ([\D\w]*)\./); | ||
| }); | ||
| }); | ||
|
|
||
| sourceTemplate = deepCopy(SERVER_REMOTE_CONFIG_RESPONSE); | ||
| INVALID_CONDITIONS.forEach((invalidConditions) => { | ||
| sourceTemplate.conditions = invalidConditions; | ||
| it(`should throw if the conditions is ${JSON.stringify(invalidConditions)}`, () => { | ||
|
|
||
| INVALID_PARAMETERS.forEach((invalidParameter) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking: it feels like we're re-testing the cases covered by the tests on |
||
| sourceTemplate.parameters = invalidParameter; | ||
| const jsonString = JSON.stringify(sourceTemplate); | ||
| const initializedTemplate = remoteConfig.initServerTemplate(); | ||
| expect(() => initializedTemplate.set(jsonString)) | ||
| .to.throw(/Failed to parse the JSON string: ([\D\w]*)\./); | ||
| it(`should throw if the template is invalid - parameters is ${JSON.stringify(invalidParameter)}`, () => { | ||
| expect(() => remoteConfig.initServerTemplate({ template: jsonString })) | ||
| .to.throw('Remote Config parameters must be a non-null object'); | ||
| }); | ||
| }); | ||
|
|
||
| sourceTemplate = deepCopy(SERVER_REMOTE_CONFIG_RESPONSE); | ||
| INVALID_CONDITIONS.forEach((invalidConditions) => { | ||
| sourceTemplate.conditions = invalidConditions; | ||
| const jsonString = JSON.stringify(sourceTemplate); | ||
| it(`should throw if the template is invalid - conditions is ${JSON.stringify(invalidConditions)}`, () => { | ||
| expect(() => remoteConfig.initServerTemplate({ template: jsonString })) | ||
| .to.throw('Remote Config conditions must be an array'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it('should throw if template is an invalid JSON', () => { | ||
| const jsonString = '{invalidJson: null}'; | ||
| const initializedTemplate = remoteConfig.initServerTemplate(); | ||
| expect(() => initializedTemplate.set(jsonString)) | ||
| .to.throw(/Failed to parse the JSON string: ([\D\w]*)\./); | ||
| }); | ||
| }); | ||
|
|
||
| describe('evaluate', () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious (because I think either is fine) so we need a separate type for this or should this just be
ServerTemplateData | stringhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either works, I originally had it as
ServerTemplateData | stringbut we are defining it in quite a few places across multiple files, so I moved it to a type 😃