-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(amplify-appsync-simulator): appsync scalars
- Loading branch information
Showing
5 changed files
with
108 additions
and
5 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
62 changes: 62 additions & 0 deletions
62
packages/amplify-appsync-simulator/src/__tests__/scalars/AWSJSON.test.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,62 @@ | ||
import { scalars } from '../../schema/appsync-scalars'; | ||
|
||
describe('AWSJSON parse', () => { | ||
it('Should reject an invalid json encoded object', () => { | ||
function parse() { | ||
scalars.AWSJSON.parseValue('{Foo: "Not Valid"}'); | ||
} | ||
expect(parse).toThrowErrorMatchingSnapshot(); | ||
}); | ||
it('Should reject a non json string', () => { | ||
function parse() { | ||
scalars.AWSJSON.parseValue('hello world'); | ||
} | ||
expect(parse).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
it('Should reject a non json boolean', () => { | ||
function parse() { | ||
scalars.AWSJSON.parseValue(true); | ||
} | ||
expect(parse).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
it('Should reject a non json int', () => { | ||
function parse() { | ||
scalars.AWSJSON.parseValue(1); | ||
} | ||
expect(parse).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
it('Should accept a json encoded object', () => { | ||
expect(scalars.AWSJSON.parseValue('{"Foo": "Bar"}')).toMatchObject({ | ||
Foo: 'Bar', | ||
}); | ||
}); | ||
|
||
it('Should accept a json string', () => { | ||
expect(scalars.AWSJSON.parseValue('"Hello world"')).toEqual('Hello world'); | ||
}); | ||
|
||
it('Should accept a json boolean', () => { | ||
expect(scalars.AWSJSON.parseValue('true')).toEqual(true); | ||
}); | ||
|
||
it('Should accept a json int', () => { | ||
expect(scalars.AWSJSON.parseValue('1')).toEqual(1); | ||
}); | ||
}); | ||
|
||
describe('AWSJSON serialize', () => { | ||
it('Should serialize an obkect', () => { | ||
expect(scalars.AWSJSON.serialize({ foo: 'Bar' })).toEqual('{"foo":"Bar"}'); | ||
}); | ||
|
||
it('Should serialize a boolean', () => { | ||
expect(scalars.AWSJSON.serialize(true)).toEqual('true'); | ||
}); | ||
|
||
it('Should serialize an integer', () => { | ||
expect(scalars.AWSJSON.serialize(1)).toEqual('1'); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/amplify-appsync-simulator/src/__tests__/scalars/__snapshots__/AWSJSON.test.ts.snap
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,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`AWSJSON parse Should reject a non json boolean 1`] = `"Unable to parse true as valid JSON."`; | ||
|
||
exports[`AWSJSON parse Should reject a non json int 1`] = `"Unable to parse 1 as valid JSON."`; | ||
|
||
exports[`AWSJSON parse Should reject a non json string 1`] = `"Unable to parse hello world as valid JSON."`; | ||
|
||
exports[`AWSJSON parse Should reject an invalid json encoded object 1`] = `"Unable to parse {Foo: \\"Not Valid\\"} as valid JSON."`; |
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