This repository has been archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #357 from Financial-Times/rhys/test-schema-properties
- Loading branch information
Showing
17 changed files
with
335 additions
and
27 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
50 changes: 50 additions & 0 deletions
50
packages/tc-schema-publisher/scripts/__tests__/deploy-test.spec.js
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,50 @@ | ||
const mockS3Instance = { | ||
upload: jest.fn().mockReturnThis(), | ||
promise: jest.fn(), | ||
}; | ||
|
||
jest.mock('aws-sdk', () => { | ||
return { S3: jest.fn(() => mockS3Instance) }; | ||
}); | ||
|
||
const { deploy } = require('../deploy'); | ||
|
||
describe('tc-schema-sdk/deploy test', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('can deploy with test properties', async () => { | ||
require('../deploy'); | ||
|
||
await deploy({ | ||
schemaDirectory: `packages/tc-schema-publisher/scripts/__tests__/schema`, | ||
bucketName: 'blah', | ||
includeTestDefinitions: true, | ||
env: 'latest', | ||
}); | ||
|
||
expect(mockS3Instance.upload).toHaveBeenCalled(); | ||
const body = mockS3Instance.upload.mock.calls[0][0].Body; | ||
let content = ''; | ||
body.on('data', chunk => { | ||
content += chunk.toString('utf8'); | ||
}); | ||
await new Promise(res => { | ||
body.on('end', res); | ||
}); | ||
const { schema } = JSON.parse(content); | ||
expect(schema.types.length).toEqual(2); | ||
expect(schema.types[0].name).toEqual('TypeA'); | ||
expect(schema.types[1].name).toEqual('TypeB'); | ||
expect(Object.keys(schema.types[0].properties)).toEqual([ | ||
'code', | ||
'stringPropertyA', | ||
'stringPropertyB', | ||
]); | ||
expect(Object.keys(schema.enums)).toEqual(['AnEnum', 'ATestEnum']); | ||
expect(Object.keys(schema.typeHierarchy)).toEqual(['prod', 'test']); | ||
expect(schema.typeHierarchy.prod.types).toEqual(['TypeA']); | ||
expect(schema.typeHierarchy.test.types).toEqual(['TypeB']); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -3,3 +3,8 @@ prod: | |
description: Prod types | ||
types: | ||
- TypeA | ||
test: | ||
label: Test | ||
description: Test types | ||
types: | ||
- TypeB |
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
11 changes: 11 additions & 0 deletions
11
packages/tc-schema-publisher/scripts/__tests__/schema/types/TypeB.yaml
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,11 @@ | ||
name: TypeB | ||
description: type b | ||
isTest: true | ||
properties: | ||
code: | ||
type: Code | ||
unique: true | ||
canIdentify: true | ||
description: Code description. | ||
label: Code label | ||
pattern: CODE |
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
142 changes: 142 additions & 0 deletions
142
packages/tc-schema-sdk/__tests__/test-schema-properties.spec.js
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,142 @@ | ||
const { SDK } = require('../sdk'); | ||
|
||
const schemaFixture = { | ||
types: [ | ||
{ | ||
name: 'TypeA', | ||
description: 'type a', | ||
properties: { | ||
code: { | ||
type: 'Code', | ||
unique: true, | ||
canIdentify: true, | ||
description: 'Code description.', | ||
label: 'Code label', | ||
pattern: 'CODE', | ||
}, | ||
stringPropertyA: { | ||
type: 'Word', | ||
description: 'stringPropertyA description.', | ||
label: 'stringPropertyA label', | ||
}, | ||
stringPropertyB: { | ||
type: 'Word', | ||
description: 'stringPropertyB description.', | ||
label: 'stringPropertyB label', | ||
isTest: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: 'TypeB', | ||
description: 'type b', | ||
isTest: true, | ||
properties: { | ||
code: { | ||
type: 'Code', | ||
unique: true, | ||
canIdentify: true, | ||
description: 'Code description.', | ||
label: 'Code label', | ||
pattern: 'CODE', | ||
}, | ||
}, | ||
}, | ||
], | ||
relationshipTypes: [], | ||
stringPatterns: { | ||
CODE: '^(?=.{2,64}$)[a-z0-9]+(?:-[a-z0-9]+)*$', | ||
}, | ||
enums: { | ||
AnEnum: { | ||
description: 'Another example enum\n', | ||
options: { | ||
First: 'First option', | ||
}, | ||
}, | ||
ATestEnum: { | ||
description: 'Another example enum\n', | ||
isTest: true, | ||
options: { | ||
First: 'First option', | ||
}, | ||
}, | ||
}, | ||
primitiveTypes: { | ||
Code: { | ||
graphql: 'String', | ||
component: 'Text', | ||
}, | ||
Word: { | ||
graphql: 'String', | ||
component: 'Text', | ||
}, | ||
Document: { | ||
graphql: 'String', | ||
component: 'LargeText', | ||
}, | ||
Url: { | ||
graphql: 'String', | ||
component: 'Text', | ||
}, | ||
}, | ||
typeHierarchy: { | ||
prod: { | ||
label: 'Prod', | ||
description: 'Prod types', | ||
types: ['TypeA'], | ||
}, | ||
test: { | ||
label: 'Test', | ||
description: 'Test types', | ||
types: ['TypeB'], | ||
}, | ||
}, | ||
}; | ||
|
||
describe('test schema properties', () => { | ||
it('excludes test properties by default', async () => { | ||
const schema = new SDK({ schemaData: { schema: schemaFixture } }); | ||
await schema.ready(); | ||
expect(schema.getTypes().length).toEqual(1); | ||
expect(schema.getTypes()[0].name).toEqual('TypeA'); | ||
expect(Object.keys(schema.getTypes()[0].properties)).toEqual([ | ||
'code', | ||
'stringPropertyA', | ||
]); | ||
expect(Object.keys(schema.getEnums())).toEqual(['AnEnum']); | ||
expect(Object.keys(schema.getTypes({ grouped: true }))).toEqual([ | ||
'prod', | ||
]); | ||
expect(schema.getTypes({ grouped: true }).prod.types[0].name).toEqual( | ||
'TypeA', | ||
); | ||
}); | ||
|
||
it('includes test properties on demand', async () => { | ||
const schema = new SDK({ | ||
schemaData: { schema: schemaFixture }, | ||
includeTestDefinitions: true, | ||
}); | ||
await schema.ready(); | ||
expect(schema.getTypes().length).toEqual(2); | ||
expect(schema.getTypes()[0].name).toEqual('TypeA'); | ||
expect(schema.getTypes()[1].name).toEqual('TypeB'); | ||
expect(Object.keys(schema.getTypes()[0].properties)).toEqual([ | ||
'code', | ||
'stringPropertyA', | ||
'stringPropertyB', | ||
]); | ||
expect(Object.keys(schema.getEnums())).toEqual(['AnEnum', 'ATestEnum']); | ||
expect(Object.keys(schema.getTypes({ grouped: true }))).toEqual([ | ||
'prod', | ||
'test', | ||
]); | ||
expect(schema.getTypes({ grouped: true }).prod.types[0].name).toEqual( | ||
'TypeA', | ||
); | ||
expect(schema.getTypes({ grouped: true }).test.types[0].name).toEqual( | ||
'TypeB', | ||
); | ||
}); | ||
}); |
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
Oops, something went wrong.