Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: searchable fix and migration e2e tests (#8666)
- Loading branch information
Showing
7 changed files
with
136 additions
and
4 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/amplify-e2e-tests/schemas/transformer_migration/searchable-v1.graphql
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,6 @@ | ||
type Todo @model @searchable { | ||
id: ID! | ||
name: String! | ||
description: String | ||
count: Int | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/amplify-e2e-tests/schemas/transformer_migration/searchable-v2.graphql
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,6 @@ | ||
type Todo @model @searchable @auth(rules: [{ allow: public }]) { | ||
id: ID! | ||
name: String! | ||
description: String | ||
count: Int | ||
} |
115 changes: 115 additions & 0 deletions
115
packages/amplify-e2e-tests/src/__tests__/transformer-migrations/searchable-migration.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,115 @@ | ||
import { | ||
initJSProjectWithProfile, | ||
deleteProject, | ||
amplifyPush, | ||
amplifyPushUpdate, | ||
addFeatureFlag, | ||
createRandomName, | ||
addAuthWithDefault, | ||
} from 'amplify-e2e-core'; | ||
import { addApiWithoutSchema, updateApiSchema, getProjectMeta } from 'amplify-e2e-core'; | ||
import { createNewProjectDir, deleteProjectDir } from 'amplify-e2e-core'; | ||
import gql from 'graphql-tag'; | ||
import AWSAppSyncClient, { AUTH_TYPE } from 'aws-appsync'; | ||
(global as any).fetch = require('node-fetch'); | ||
|
||
describe('transformer model searchable migration test', () => { | ||
let projRoot: string; | ||
let projectName: string; | ||
let appSyncClient = undefined; | ||
|
||
beforeEach(async () => { | ||
projectName = createRandomName(); | ||
projRoot = await createNewProjectDir(createRandomName()); | ||
await initJSProjectWithProfile(projRoot, { | ||
name: projectName, | ||
}); | ||
await addAuthWithDefault(projRoot, {}); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteProject(projRoot); | ||
deleteProjectDir(projRoot); | ||
}); | ||
|
||
it('migration of searchable directive - search should return expected results', async () => { | ||
const v1Schema = 'transformer_migration/searchable-v1.graphql'; | ||
const v2Schema = 'transformer_migration/searchable-v2.graphql'; | ||
|
||
await addApiWithoutSchema(projRoot, { apiName: projectName }); | ||
await updateApiSchema(projRoot, projectName, v1Schema); | ||
await amplifyPush(projRoot); | ||
|
||
appSyncClient = getAppSyncClientFromProj(projRoot); | ||
await runAndValidateQuery('test1', 'test1', 10); | ||
|
||
await addFeatureFlag(projRoot, 'graphqltransformer', 'transformerVersion', 2); | ||
await addFeatureFlag(projRoot, 'graphqltransformer', 'useExperimentalPipelinedTransformer', true); | ||
|
||
await updateApiSchema(projRoot, projectName, v2Schema); | ||
await amplifyPushUpdate(projRoot); | ||
|
||
appSyncClient = getAppSyncClientFromProj(projRoot); | ||
await runAndValidateQuery('test2', 'test2', 10); | ||
}); | ||
|
||
const getAppSyncClientFromProj = (projRoot: string) => { | ||
const meta = getProjectMeta(projRoot); | ||
const region = meta['providers']['awscloudformation']['Region'] as string; | ||
const { output } = meta.api[projectName]; | ||
const url = output.GraphQLAPIEndpointOutput as string; | ||
const apiKey = output.GraphQLAPIKeyOutput as string; | ||
|
||
return new AWSAppSyncClient({ | ||
url, | ||
region, | ||
disableOffline: true, | ||
auth: { | ||
type: AUTH_TYPE.API_KEY, | ||
apiKey, | ||
}, | ||
}); | ||
}; | ||
|
||
const fragments = [`fragment FullTodo on Todo { id name description count }`]; | ||
|
||
const runMutation = async (query: string) => { | ||
try { | ||
const q = [query, ...fragments].join('\n'); | ||
const response = await appSyncClient.mutate({ | ||
mutation: gql(q), | ||
fetchPolicy: 'no-cache', | ||
}); | ||
return response; | ||
} catch (e) { | ||
console.error(e); | ||
return null; | ||
} | ||
}; | ||
|
||
const createEntry = async (name: string, description: string, count: number) => { | ||
return await runMutation(getCreateTodosMutation(name, description, count)); | ||
}; | ||
|
||
function getCreateTodosMutation( | ||
name: string, | ||
description: string, | ||
count: number, | ||
): string { | ||
return `mutation { | ||
createTodo(input: { | ||
name: "${name}" | ||
description: "${description}" | ||
count: ${count} | ||
}) { ...FullTodo } | ||
}`; | ||
} | ||
|
||
const runAndValidateQuery = async (name: string, description: string, count: number) => { | ||
const response = await createEntry(name, description, count); | ||
expect(response).toBeDefined(); | ||
expect(response.errors).toBeUndefined(); | ||
expect(response.data).toBeDefined(); | ||
expect(response.data.createTodo).toBeDefined(); | ||
} | ||
}); |
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
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