Skip to content

Commit

Permalink
test: addApiWithDefaultSchemaAndConflictDetection
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilch committed Nov 20, 2023
1 parent 476aef4 commit 0fd19bf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
29 changes: 29 additions & 0 deletions packages/amplify-codegen-e2e-core/src/categories/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,35 @@ export function addApiWithBlankSchemaAndConflictDetection(cwd: string) {
});
}

export function addApiWithDefaultSchemaAndConflictDetection(cwd: string) {
return new Promise<void>((resolve, reject) => {
spawn(getCLIPath(defaultOptions.testingWithLatestCodebase), ['add', 'api'], { cwd, stripColors: true })
.wait('Select from one of the below mentioned services:')
.sendCarriageReturn()
.wait(/.*Here is the GraphQL API that we will create. Select a setting to edit or continue.*/)
.sendKeyUp()
.sendCarriageReturn()
.wait(/.*Enable conflict detection.*/)
.sendConfirmYes()
.wait(/.*Select the default resolution strategy.*/)
.sendCarriageReturn()
.wait(/.*Here is the GraphQL API that we will create. Select a setting to edit or continue.*/)
.sendCarriageReturn()
.wait('Choose a schema template:')
.sendCarriageReturn()
.wait('Do you want to edit the schema now?')
.sendConfirmNo()
.wait('"amplify publish" will build all your local backend and frontend resources')
.run((err: Error) => {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}

export function updateApiSchema(cwd: string, projectName: string, schemaName: string, forceUpdate: boolean = false) {
const testSchemaPath = getSchemaPath(schemaName);
let schemaText = fs.readFileSync(testSchemaPath).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
initProjectWithProfile,
DEFAULT_ANDROID_CONFIG,
updateApiSchemaWithText,
addApiWithBlankSchemaAndConflictDetection,
addApiWithDefaultSchemaAndConflictDetection,
generateModels,
generateStatementsAndTypes,
androidBuild,
Expand All @@ -28,10 +28,9 @@ describe('build app - Android', () => {

beforeAll(async () => {
await initProjectWithProfile(projectRoot, { ...config });
await addApiWithBlankSchemaAndConflictDetection(projectRoot);
await addApiWithDefaultSchemaAndConflictDetection(projectRoot);
apiName = readdirSync(path.join(projectRoot, 'amplify', 'backend', 'api'))[0];
const schemaText = `input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }\n${schemas[0].sdl}`;
updateApiSchemaWithText(projectRoot, apiName, schemaText);
apiGqlCompile(projectRoot);
await amplifyPush(projectRoot);
await addCodegen(projectRoot, {
frontendType: AmplifyFrontend.android,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
initProjectWithProfile,
addApiWithBlankSchemaAndConflictDetection,
addApiWithDefaultSchemaAndConflictDetection,
DEFAULT_IOS_CONFIG,
updateApiSchemaWithText,
generateModels,
Expand Down Expand Up @@ -30,10 +30,8 @@ describe('build app - Swift', () => {

beforeAll(async () => {
await initProjectWithProfile(projectRoot, { ...config });
await addApiWithBlankSchemaAndConflictDetection(projectRoot);
await addApiWithDefaultSchemaAndConflictDetection(projectRoot);
apiName = readdirSync(path.join(projectRoot, 'amplify', 'backend', 'api'))[0];
const schemaText = `input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }\n${schemas[0].sdl}`;
updateApiSchemaWithText(projectRoot, apiName, schemaText);
apiGqlCompile(projectRoot);
await amplifyPush(projectRoot);
await addCodegen(projectRoot, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
initProjectWithProfile,
DEFAULT_JS_CONFIG,
addApiWithBlankSchemaAndConflictDetection,
addApiWithDefaultSchemaAndConflictDetection,
updateApiSchemaWithText,
generateModels,
generateStatementsAndTypes,
Expand All @@ -25,10 +25,9 @@ describe('build app - JS', () => {

beforeAll(async () => {
await initProjectWithProfile(projectRoot, { ...config });
await addApiWithBlankSchemaAndConflictDetection(projectRoot);
await addApiWithDefaultSchemaAndConflictDetection(projectRoot);
apiName = readdirSync(path.join(projectRoot, 'amplify', 'backend', 'api'))[0];
const schemaText = `input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }\n${schemas[0].sdl}`;
updateApiSchemaWithText(projectRoot, apiName, schemaText);
apiGqlCompile(projectRoot);
await amplifyPush(projectRoot);
await addCodegen(projectRoot, {
frontendType: AmplifyFrontend.javascript,
Expand Down

0 comments on commit 0fd19bf

Please sign in to comment.