Skip to content

Commit 471fd5b

Browse files
Merge pull request #297 from aws-amplify/e2e-test-api-flow-change
fix(amplify-codegen-e2e-core): API walkthrough changes
2 parents aab5e7d + ff8bf76 commit 471fd5b

File tree

13 files changed

+428
-145
lines changed

13 files changed

+428
-145
lines changed

packages/amplify-codegen-e2e-core/src/categories/api.ts

Lines changed: 262 additions & 62 deletions
Large diffs are not rendered by default.

packages/amplify-codegen-e2e-core/src/init/initProjectHelper.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { nspawn as spawn, getCLIPath, singleSelect, addCircleCITags } from '..';
22
import { KEY_DOWN_ARROW, AmplifyFrontend } from '../utils';
33
import { amplifyRegions } from '../configure';
4+
import { v4 as uuid } from 'uuid';
45

56
const defaultSettings = {
67
name: '\r',
@@ -430,3 +431,9 @@ export async function initProjectWithProfile(cwd: string, settings: any) : Promi
430431
throw Error(`${settings.frontendType} is an invalid frontend type`);
431432
}
432433
}
434+
435+
export function createRandomName() {
436+
const length = 20;
437+
const regExp = new RegExp('-', 'g');
438+
return uuid().replace(regExp, '').substring(0, length);
439+
}

packages/amplify-codegen-e2e-tests/src/codegen-tests-base/add-codegen.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {
22
initProjectWithProfile,
3-
addApiWithSchema,
3+
addApiWithoutSchema,
4+
updateApiSchema,
45
addCodegen,
5-
AmplifyFrontendConfig
6+
AmplifyFrontendConfig,
7+
createRandomName
68
} from "amplify-codegen-e2e-core";
79
import { existsSync } from "fs";
810
import path from 'path';
@@ -12,7 +14,9 @@ import { testSetupBeforeAddCodegen, testValidGraphQLConfig } from "./test-setup"
1214
export async function testAddCodegen(config: AmplifyFrontendConfig, projectRoot: string, schema: string) {
1315
// init project and add API category
1416
await initProjectWithProfile(projectRoot, { ...config });
15-
await addApiWithSchema(projectRoot, schema);
17+
const projectName = createRandomName();
18+
await addApiWithoutSchema(projectRoot, { apiName: projectName });
19+
await updateApiSchema(projectRoot, projectName, schema);
1620

1721
const userSourceCodePath = testSetupBeforeAddCodegen(projectRoot, config);
1822

packages/amplify-codegen-e2e-tests/src/codegen-tests-base/configure-codegen.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
22
initProjectWithProfile,
3-
addApiWithSchema,
3+
addApiWithoutSchema,
44
addCodegen,
5+
updateApiSchema,
56
configureCodegen,
6-
AmplifyFrontendConfig
7+
AmplifyFrontendConfig,
8+
createRandomName
79
} from "amplify-codegen-e2e-core";
810
import { existsSync, readFileSync } from "fs";
911
import path from 'path';
@@ -13,7 +15,9 @@ import { testSetupBeforeAddCodegen, testValidGraphQLConfig, getGraphQLConfigFile
1315
export async function testConfigureCodegen(config: AmplifyFrontendConfig, projectRoot: string, schema: string) {
1416
// init project and add API category
1517
await initProjectWithProfile(projectRoot, { ...config });
16-
await addApiWithSchema(projectRoot, schema);
18+
const projectName = createRandomName();
19+
await addApiWithoutSchema(projectRoot, { apiName: projectName });
20+
await updateApiSchema(projectRoot, projectName, schema);
1721

1822
const userSourceCodePath = testSetupBeforeAddCodegen(projectRoot, config);
1923

packages/amplify-codegen-e2e-tests/src/codegen-tests-base/datastore-modelgen.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {
22
initProjectWithProfile,
3-
addApiWithSchemaAndConflictDetection,
3+
addApiWithBlankSchemaAndConflictDetection,
44
generateModels,
5-
AmplifyFrontendConfig
5+
AmplifyFrontendConfig,
6+
createRandomName,
7+
updateApiSchema
68
} from "amplify-codegen-e2e-core";
79
import { existsSync } from "fs";
810
import path from 'path';
@@ -13,7 +15,9 @@ export async function testCodegenModels(config: AmplifyFrontendConfig, projectRo
1315
await initProjectWithProfile(projectRoot, { ...config });
1416

1517
//enable datastore
16-
await addApiWithSchemaAndConflictDetection(projectRoot, schema);
18+
const projectName = createRandomName();
19+
await addApiWithBlankSchemaAndConflictDetection(projectRoot);
20+
await updateApiSchema(projectRoot, projectName, schema);
1721

1822
//generate pre existing user file
1923
const userSourceCodePath = generateSourceCode(projectRoot, config.srcDir);

packages/amplify-codegen-e2e-tests/src/codegen-tests-base/graphql-codegen.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
22
initProjectWithProfile,
3-
addApiWithSchema,
3+
addApiWithoutSchema,
4+
updateApiSchema,
45
addCodegen,
56
AmplifyFrontendConfig,
6-
generateStatementsAndTypes
7+
generateStatementsAndTypes,
8+
createRandomName
79
} from "amplify-codegen-e2e-core";
810
import { existsSync } from "fs";
911
import path from 'path';
@@ -12,7 +14,9 @@ import { isNotEmptyDir, generateSourceCode } from '../utils';
1214
export async function testGraphQLCodegen(config: AmplifyFrontendConfig, projectRoot: string, schema: string) {
1315
// init project and add API category
1416
await initProjectWithProfile(projectRoot, { ...config });
15-
await addApiWithSchema(projectRoot, schema);
17+
const projectName = createRandomName();
18+
await addApiWithoutSchema(projectRoot, { apiName: projectName });
19+
await updateApiSchema(projectRoot, projectName, schema);
1620

1721
// generate pre-existing user file
1822
const userSourceCodePath = generateSourceCode(projectRoot, config.srcDir);

packages/amplify-codegen-e2e-tests/src/codegen-tests-base/push-codegen.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
initProjectWithProfile,
3-
addApiWithSchema,
3+
addApiWithoutSchema,
4+
updateApiSchema,
5+
createRandomName,
46
amplifyPushWithCodegenAdd,
57
AmplifyFrontendConfig,
68
apiUpdateToggleDataStore,
@@ -14,7 +16,9 @@ import { testSetupBeforeAddCodegen } from "./test-setup";
1416
export async function testPushCodegen(config: AmplifyFrontendConfig, projectRoot: string, schema: string) {
1517
// init project and add API category
1618
await initProjectWithProfile(projectRoot, { ...config });
17-
await addApiWithSchema(projectRoot, schema);
19+
const projectName = createRandomName();
20+
await addApiWithoutSchema(projectRoot, { apiName: projectName });
21+
await updateApiSchema(projectRoot, projectName, schema);
1822

1923
const userSourceCodePath = testSetupBeforeAddCodegen(projectRoot, config);
2024

packages/amplify-codegen-e2e-tests/src/codegen-tests-base/remove-codegen.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
initProjectWithProfile,
3-
addApiWithSchema,
3+
addApiWithoutSchema,
4+
updateApiSchema,
5+
createRandomName,
46
addCodegen,
57
removeCodegen,
68
AmplifyFrontendConfig
@@ -14,7 +16,9 @@ import { load } from 'js-yaml';
1416
export async function testRemoveCodegen(config: AmplifyFrontendConfig, projectRoot: string, schema: string) {
1517
// init project and add API category
1618
await initProjectWithProfile(projectRoot, { ...config });
17-
await addApiWithSchema(projectRoot, schema);
19+
const projectName = createRandomName();
20+
await addApiWithoutSchema(projectRoot, { apiName: projectName });
21+
await updateApiSchema(projectRoot, projectName, schema);
1822

1923
const userSourceCodePath = testSetupBeforeAddCodegen(projectRoot, config);
2024

0 commit comments

Comments
 (0)