-
Notifications
You must be signed in to change notification settings - Fork 816
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): remove graphql-scalars dependency (#6680
) This commit removes the dependency on graphql-scalars and adds the implementations for the AWSEmail and AWSURL scalars. Fixes: #6656
- Loading branch information
Showing
6 changed files
with
121 additions
and
7 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
17 changes: 17 additions & 0 deletions
17
packages/amplify-appsync-simulator/src/__tests__/scalars/AWSEmail.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,17 @@ | ||
import { scalars } from '../../schema/appsync-scalars'; | ||
|
||
describe('AWSEmail parse', () => { | ||
it('Should reject a non-string', () => { | ||
function parse() { | ||
scalars.AWSEmail.parseValue(1); | ||
} | ||
expect(parse).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
it('Should reject an invalid email address', () => { | ||
function parse() { | ||
scalars.AWSEmail.parseValue('@@'); | ||
} | ||
expect(parse).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/amplify-appsync-simulator/src/__tests__/scalars/AWSURL.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,37 @@ | ||
import { URL } from 'url'; | ||
import { scalars } from '../../schema/appsync-scalars'; | ||
|
||
describe('AWSURL parse', () => { | ||
it('Returns falsy values unchanged', () => { | ||
expect(scalars.AWSURL.parseValue(0)).toEqual(0); | ||
}); | ||
|
||
it('Returns valid URL objects', () => { | ||
const parsed = new URL('http://www.amazon.com'); | ||
expect(scalars.AWSURL.parseValue('http://www.amazon.com')).toEqual(parsed); | ||
}); | ||
|
||
it('Should reject an invalid URL', () => { | ||
function serialize() { | ||
scalars.AWSURL.parseValue('invalid-url'); | ||
} | ||
expect(serialize).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('AWSURL serialize', () => { | ||
it('Returns falsy values unchanged', () => { | ||
expect(scalars.AWSURL.serialize(0)).toEqual(0); | ||
}); | ||
|
||
it('Returns valid URLs', () => { | ||
expect(scalars.AWSURL.serialize('http://www.amazon.com')).toEqual('http://www.amazon.com/'); | ||
}); | ||
|
||
it('Should reject an invalid URL', () => { | ||
function serialize() { | ||
scalars.AWSURL.serialize('invalid-url'); | ||
} | ||
expect(serialize).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
packages/amplify-appsync-simulator/src/__tests__/scalars/__snapshots__/AWSEmail.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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`AWSEmail parse Should reject a non-string 1`] = `"Value is not string: 1"`; | ||
|
||
exports[`AWSEmail parse Should reject an invalid email address 1`] = `"Value is not a valid email address: @@"`; |
5 changes: 5 additions & 0 deletions
5
packages/amplify-appsync-simulator/src/__tests__/scalars/__snapshots__/AWSURL.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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`AWSURL parse Should reject an invalid URL 1`] = `"Invalid URL: invalid-url"`; | ||
|
||
exports[`AWSURL serialize Should reject an invalid URL 1`] = `"Invalid URL: invalid-url"`; |
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