From 9a80a0d96527586423bd3ef6a7fbeaab61422562 Mon Sep 17 00:00:00 2001 From: Colin Ihrig Date: Fri, 30 Jul 2021 18:08:32 -0400 Subject: [PATCH] test: improve schema validation in tests (#7845) This commit exposes the validateModelSchema() function from the GraphQL Transformer core. This function is helpful for validating the Transformer output schema's correctness. This commit also applies the validation to @predictions v2 test suite. Co-authored-by: Colin Ihrig --- .../amplify-graphql-predictions-transformer.test.ts | 9 +++++---- packages/amplify-graphql-transformer-core/src/index.ts | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/amplify-graphql-predictions-transformer/src/__tests__/amplify-graphql-predictions-transformer.test.ts b/packages/amplify-graphql-predictions-transformer/src/__tests__/amplify-graphql-predictions-transformer.test.ts index 0913a57803f..1147d68ec4e 100644 --- a/packages/amplify-graphql-predictions-transformer/src/__tests__/amplify-graphql-predictions-transformer.test.ts +++ b/packages/amplify-graphql-predictions-transformer/src/__tests__/amplify-graphql-predictions-transformer.test.ts @@ -1,6 +1,6 @@ 'use strict'; import { anything, countResources, expect as cdkExpect, haveResourceLike } from '@aws-cdk/assert'; -import { GraphQLTransform } from '@aws-amplify/graphql-transformer-core'; +import { GraphQLTransform, validateModelSchema } from '@aws-amplify/graphql-transformer-core'; import { parse } from 'graphql'; import { PredictionsTransformer } from '..'; @@ -14,6 +14,7 @@ test('does not generate any resources if @predictions is unused', () => { }); const out = transformer.transform(schema); + validateModelSchema(parse(out.schema)); expect(out).toBeDefined(); expect(out.stacks).toBeDefined(); expect(out.stacks.PredictionsDirectiveStack).toEqual(undefined); @@ -31,7 +32,7 @@ test('lambda function is added to pipeline when lambda dependent action is added const out = transformer.transform(validSchema); expect(out).toBeDefined(); expect(out.stacks).toBeDefined(); - parse(out.schema); + validateModelSchema(parse(out.schema)); expect(out.schema).toMatchSnapshot(); const stack = out.stacks.PredictionsDirectiveStack; expect(stack).toBeDefined(); @@ -157,7 +158,7 @@ test('return type is a list based on the action', () => { const out = transformer.transform(validSchema); expect(out).toBeDefined(); expect(out.stacks).toBeDefined(); - parse(out.schema); + validateModelSchema(parse(out.schema)); expect(out.schema).toMatchSnapshot(); const stack = out.stacks.PredictionsDirectiveStack; expect(stack).toBeDefined(); @@ -186,7 +187,7 @@ test('can use actions individually and in supported sequences', () => { const out = transformer.transform(validSchema); expect(out).toBeDefined(); expect(out.stacks).toBeDefined(); - parse(out.schema); + validateModelSchema(parse(out.schema)); expect(out.schema).toMatchSnapshot(); const stack = out.stacks.PredictionsDirectiveStack; expect(stack).toBeDefined(); diff --git a/packages/amplify-graphql-transformer-core/src/index.ts b/packages/amplify-graphql-transformer-core/src/index.ts index e3488cb0be9..d3f991998b2 100644 --- a/packages/amplify-graphql-transformer-core/src/index.ts +++ b/packages/amplify-graphql-transformer-core/src/index.ts @@ -14,6 +14,7 @@ export { UserPoolConfig, } from './transformation'; export { DeploymentResources } from './transformation/types'; +export { validateModelSchema } from './transformation/validation'; export { ConflictDetectionType, ConflictHandlerType,