forked from aws-amplify/amplify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(graphql-model-transformer): graphql model transformer tests (aws…
…-amplify#7836) * Add .circleci/config.yml * test: ported @model v1 test suite to v2 * chore(graphql-model-transformer): removed improvePluralization check, V2 uses improvePluralization * chore(graphql-model-transformer): added parse() to tests that generate a valid schema * test(graphql-model-transformer): added validateModelSchema check to existing model v2 tests
- Loading branch information
Showing
5 changed files
with
695 additions
and
2 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
261 changes: 261 additions & 0 deletions
261
packages/amplify-graphql-model-transformer/src/__tests__/model-directive-arguments.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,261 @@ | ||
import { ModelTransformer } from '@aws-amplify/graphql-model-transformer'; | ||
import { GraphQLTransform, validateModelSchema } from '@aws-amplify/graphql-transformer-core'; | ||
import { parse } from 'graphql'; | ||
import { getFieldOnObjectType, getObjectType } from './test-utils/helpers'; | ||
|
||
describe('createdAt field tests', () => { | ||
it('should return createdAt when there is no timestamps configuration', () => { | ||
const doc = /* GraphQL */ ` | ||
type Post @model { | ||
id: ID! | ||
title: String | ||
} | ||
`; | ||
|
||
const transformer = new GraphQLTransform({ | ||
transformers: [new ModelTransformer()], | ||
}); | ||
|
||
const out = transformer.transform(doc); | ||
expect(out).toBeDefined(); | ||
|
||
const definition = out.schema; | ||
expect(definition).toBeDefined(); | ||
|
||
const parsed = parse(definition); | ||
validateModelSchema(parsed); | ||
const postModelObject = getObjectType(parsed, 'Post'); | ||
const postModelField = getFieldOnObjectType(postModelObject!, 'createdAt'); | ||
|
||
expect(postModelField).toBeDefined(); | ||
}); | ||
|
||
it('should return null when timestamps are set to null', () => { | ||
const doc = /* GraphQL */ ` | ||
type Post @model(timestamps: null) { | ||
id: ID! | ||
title: String | ||
} | ||
`; | ||
const transformer = new GraphQLTransform({ | ||
transformers: [new ModelTransformer()], | ||
}); | ||
|
||
const out = transformer.transform(doc); | ||
expect(out).toBeDefined(); | ||
|
||
const definition = out.schema; | ||
expect(definition).toBeDefined(); | ||
|
||
const parsed = parse(definition); | ||
validateModelSchema(parsed); | ||
const postModelObject = getObjectType(parsed, 'Post'); | ||
const postModelField = getFieldOnObjectType(postModelObject!, 'createdAt'); | ||
|
||
expect(postModelField).toBeUndefined(); | ||
}); | ||
|
||
it('should return null when createdAt is set to null', () => { | ||
const doc = /* GraphQL */ ` | ||
type Post @model(timestamps: { createdAt: null }) { | ||
id: ID! | ||
title: String | ||
} | ||
`; | ||
const transformer = new GraphQLTransform({ | ||
transformers: [new ModelTransformer()], | ||
}); | ||
|
||
const out = transformer.transform(doc); | ||
expect(out).toBeDefined(); | ||
|
||
const definition = out.schema; | ||
expect(definition).toBeDefined(); | ||
|
||
const parsed = parse(definition); | ||
validateModelSchema(parsed); | ||
const postModelObject = getObjectType(parsed, 'Post'); | ||
const postModelField = getFieldOnObjectType(postModelObject!, 'createdAt'); | ||
|
||
expect(postModelField).toBeUndefined(); | ||
}); | ||
|
||
it('should return createdOn when createdAt is set to createdOn', () => { | ||
const doc = /* GraphQL */ ` | ||
type Post @model(timestamps: { createdAt: "createdOn" }) { | ||
id: ID! | ||
title: String | ||
} | ||
`; | ||
|
||
const transformer = new GraphQLTransform({ | ||
transformers: [new ModelTransformer()], | ||
}); | ||
const out = transformer.transform(doc); | ||
expect(out).toBeDefined(); | ||
|
||
const definition = out.schema; | ||
expect(definition).toBeDefined(); | ||
|
||
const parsed = parse(definition); | ||
validateModelSchema(parsed); | ||
const postModelObject = getObjectType(parsed, 'Post'); | ||
const postModelField = getFieldOnObjectType(postModelObject!, 'createdOn'); | ||
|
||
expect(postModelField).toBeDefined(); | ||
}); | ||
|
||
it('should return createdAt when createdAt is not set in timestamps', () => { | ||
const doc = /* GraphQL */ ` | ||
type Post @model(timestamps: { updatedAt: "updatedOn" }) { | ||
id: ID! | ||
title: String | ||
} | ||
`; | ||
|
||
const transformer = new GraphQLTransform({ | ||
transformers: [new ModelTransformer()], | ||
}); | ||
const out = transformer.transform(doc); | ||
expect(out).toBeDefined(); | ||
|
||
const definition = out.schema; | ||
expect(definition).toBeDefined(); | ||
|
||
const parsed = parse(definition); | ||
validateModelSchema(parsed); | ||
const postModelObject = getObjectType(parsed, 'Post'); | ||
const postModelField = getFieldOnObjectType(postModelObject!, 'createdAt'); | ||
|
||
expect(postModelField).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('updatedAt field tests', () => { | ||
it('should return updatedAt when there is no timestamps configuration', () => { | ||
const doc = /* GraphQL */ ` | ||
type Post @model { | ||
id: ID! | ||
title: String | ||
} | ||
`; | ||
|
||
const transformer = new GraphQLTransform({ | ||
transformers: [new ModelTransformer()], | ||
}); | ||
|
||
const out = transformer.transform(doc); | ||
expect(out).toBeDefined(); | ||
|
||
const definition = out.schema; | ||
expect(definition).toBeDefined(); | ||
|
||
const parsed = parse(definition); | ||
validateModelSchema(parsed); | ||
const postModelObject = getObjectType(parsed, 'Post'); | ||
const postModelField = getFieldOnObjectType(postModelObject!, 'updatedAt'); | ||
|
||
expect(postModelField).toBeDefined(); | ||
}); | ||
|
||
it('should return null for updatedAt when timestamps are set to null', () => { | ||
const doc = /* GraphQL */ ` | ||
type Post @model(timestamps: null) { | ||
id: ID! | ||
title: String | ||
} | ||
`; | ||
|
||
const transformer = new GraphQLTransform({ | ||
transformers: [new ModelTransformer()], | ||
}); | ||
|
||
const out = transformer.transform(doc); | ||
expect(out).toBeDefined(); | ||
|
||
const definition = out.schema; | ||
expect(definition).toBeDefined(); | ||
|
||
const parsed = parse(definition); | ||
validateModelSchema(parsed); | ||
const postModelObject = getObjectType(parsed, 'Post'); | ||
const postModelField = getFieldOnObjectType(postModelObject!, 'updatedAt'); | ||
|
||
expect(postModelField).toBeUndefined(); | ||
}); | ||
|
||
it('should return null when updatedAt is set to null', () => { | ||
const doc = /* GraphQL */ ` | ||
type Post @model(timestamps: { updatedAt: null }) { | ||
id: ID! | ||
title: String | ||
} | ||
`; | ||
const transformer = new GraphQLTransform({ | ||
transformers: [new ModelTransformer()], | ||
}); | ||
|
||
const out = transformer.transform(doc); | ||
expect(out).toBeDefined(); | ||
|
||
const definition = out.schema; | ||
expect(definition).toBeDefined(); | ||
|
||
const parsed = parse(definition); | ||
validateModelSchema(parsed); | ||
const postModelObject = getObjectType(parsed, 'Post'); | ||
const postModelField = getFieldOnObjectType(postModelObject!, 'updatedAt'); | ||
|
||
expect(postModelField).toBeUndefined(); | ||
}); | ||
|
||
it('should return updatedOn when updatedAt is set to updatedOn', () => { | ||
const doc = /* GraphQL */ ` | ||
type Post @model(timestamps: { updatedAt: "updatedOn" }) { | ||
id: ID! | ||
title: String | ||
} | ||
`; | ||
|
||
const transformer = new GraphQLTransform({ | ||
transformers: [new ModelTransformer()], | ||
}); | ||
const out = transformer.transform(doc); | ||
expect(out).toBeDefined(); | ||
|
||
const definition = out.schema; | ||
expect(definition).toBeDefined(); | ||
|
||
const parsed = parse(definition); | ||
validateModelSchema(parsed); | ||
const postModelObject = getObjectType(parsed, 'Post'); | ||
const postModelField = getFieldOnObjectType(postModelObject!, 'updatedOn'); | ||
|
||
expect(postModelField).toBeDefined(); | ||
}); | ||
|
||
it('should return updatedAt when updatedAt is not set in timestamps', () => { | ||
const doc = /* GraphQL */ ` | ||
type Post @model(timestamps: { createdAt: "createdOnOn" }) { | ||
id: ID! | ||
title: String | ||
} | ||
`; | ||
|
||
const transformer = new GraphQLTransform({ | ||
transformers: [new ModelTransformer()], | ||
}); | ||
const out = transformer.transform(doc); | ||
expect(out).toBeDefined(); | ||
|
||
const definition = out.schema; | ||
expect(definition).toBeDefined(); | ||
|
||
const parsed = parse(definition); | ||
validateModelSchema(parsed); | ||
const postModelObject = getObjectType(parsed, 'Post'); | ||
const postModelField = getFieldOnObjectType(postModelObject!, 'updatedAt'); | ||
|
||
expect(postModelField).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.