-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(api): split api_5 test into two (#9782)
* test(api): split api_5 test into two * test(api): split api_5 test into two * correct file name * correct file name * address code review comments
- Loading branch information
Showing
3 changed files
with
114 additions
and
105 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
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,74 @@ | ||
import { | ||
addApiWithoutSchema, | ||
addFeatureFlag, | ||
addFunction, | ||
addRestApi, | ||
amplifyPushGraphQlWithCognitoPrompt, | ||
amplifyPushUpdate, | ||
createNewProjectDir, | ||
deleteProject, | ||
deleteProjectDir, | ||
getAppSyncApi, | ||
getProjectMeta, | ||
initJSProjectWithProfile, | ||
updateApiSchema, | ||
validateRestApiMeta, | ||
} from 'amplify-e2e-core'; | ||
import { readdirSync, readFileSync } from 'fs'; | ||
import * as path from 'path'; | ||
|
||
describe('amplify add api (REST and GRAPHQL)', () => { | ||
let projRoot: string; | ||
beforeEach(async () => { | ||
projRoot = await createNewProjectDir('rest-api'); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteProject(projRoot); | ||
deleteProjectDir(projRoot); | ||
}); | ||
|
||
it('adds a rest api and then adds a path to the existing api', async () => { | ||
await initJSProjectWithProfile(projRoot, {}); | ||
await addFunction(projRoot, { functionTemplate: 'Hello World' }, 'nodejs'); | ||
await addRestApi(projRoot, { existingLambda: true }); | ||
await addRestApi(projRoot, { isFirstRestApi: false, existingLambda: true, path: '/newpath' }); | ||
await amplifyPushUpdate(projRoot); | ||
validateRestApiMeta(projRoot); | ||
|
||
const apisDirectory = path.join(projRoot, 'amplify', 'backend', 'api'); | ||
const apis = readdirSync(apisDirectory); | ||
const apiName = apis[0]; | ||
const apiDirectory = path.join(apisDirectory, apiName); | ||
const cfnTemplateFile = path.join(apiDirectory, 'build', `${apiName}-cloudformation-template.json`); | ||
const cfnTemplate = JSON.parse(readFileSync(cfnTemplateFile, 'utf8')); | ||
// The ApiId output is required | ||
expect(cfnTemplate.Outputs.ApiId).toBeDefined(); | ||
}); | ||
|
||
it('amplify push prompt for cognito configuration if auth mode is missing', async () => { | ||
const envName = 'devtest'; | ||
const projName = 'lambdaauthmode'; | ||
await initJSProjectWithProfile(projRoot, { name: projName, envName }); | ||
await addFeatureFlag(projRoot, 'graphqltransformer', 'useexperimentalpipelinedtransformer', true); | ||
await addFeatureFlag(projRoot, 'graphqltransformer', 'transformerversion', 2); | ||
await addApiWithoutSchema(projRoot, { transformerVersion: 1 }); | ||
await addFunction(projRoot, { functionTemplate: 'Hello World' }, 'nodejs'); | ||
await updateApiSchema(projRoot, projName, 'cognito_simple_model.graphql'); | ||
await amplifyPushGraphQlWithCognitoPrompt(projRoot); | ||
|
||
const meta = getProjectMeta(projRoot); | ||
const region = meta.providers.awscloudformation.Region; | ||
const { output } = meta.api.lambdaauthmode; | ||
const { GraphQLAPIIdOutput, GraphQLAPIEndpointOutput, GraphQLAPIKeyOutput } = output; | ||
const { graphqlApi } = await getAppSyncApi(GraphQLAPIIdOutput, region); | ||
|
||
expect(GraphQLAPIIdOutput).toBeDefined(); | ||
expect(GraphQLAPIEndpointOutput).toBeDefined(); | ||
expect(GraphQLAPIKeyOutput).toBeDefined(); | ||
|
||
expect(graphqlApi).toBeDefined(); | ||
expect(graphqlApi.apiId).toEqual(GraphQLAPIIdOutput); | ||
validateRestApiMeta(projRoot, meta); | ||
}); | ||
}); |