Skip to content

Commit 5ee4897

Browse files
Merge pull request #301 from aws-amplify/master
fix(amplify-codegen-e2e-core): API walkthrough changes #299
2 parents 9716c47 + d2c6e71 commit 5ee4897

File tree

20 files changed

+432
-191
lines changed

20 files changed

+432
-191
lines changed

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

Lines changed: 229 additions & 88 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/__tests__/add-codegen-js.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
22
createNewProjectDir,
33
initProjectWithProfile,
4-
addApiWithSchema,
54
addCodegen,
6-
DEFAULT_JS_CONFIG
5+
DEFAULT_JS_CONFIG,
6+
createRandomName,
7+
addApiWithoutSchema,
8+
updateApiSchema
79
} from "amplify-codegen-e2e-core";
810
import { existsSync } from "fs";
911
import path from 'path';
@@ -46,7 +48,9 @@ describe('codegen add tests - JS', () => {
4648
it(`Adding codegen twice gives appropriate message`, async () => {
4749
// init project and add API category
4850
await initProjectWithProfile(projectRoot, { ...config });
49-
await addApiWithSchema(projectRoot, schema);
51+
const projectName = createRandomName();
52+
await addApiWithoutSchema(projectRoot, { apiName: projectName });
53+
await updateApiSchema(projectRoot, projectName, schema);
5054

5155
const userSourceCodePath = testSetupBeforeAddCodegen(projectRoot, config);
5256

packages/amplify-codegen-e2e-tests/src/__tests__/env-codegen.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import {
22
createNewProjectDir,
33
deleteProjectDir,
44
deleteProject,
5-
addApiWithSchema,
65
initJSProjectWithProfile,
76
amplifyPush,
87
generateModels,
8+
addApiWithoutSchema,
99
updateApiSchema
1010
} from "amplify-codegen-e2e-core";
1111
import { addEnvironment, checkoutEnvironment } from "../environment/env";
@@ -27,7 +27,9 @@ describe('env codegen tests', () => {
2727
it('should generate models in different environments', async () => {
2828
//create amplify project with enva
2929
await initJSProjectWithProfile(projectRoot, { envName: 'enva' });
30-
await addApiWithSchema(projectRoot, schema, { apiName });
30+
await addApiWithoutSchema(projectRoot, { apiName: apiName });
31+
await updateApiSchema(projectRoot, apiName, schema);
32+
3133
await amplifyPush(projectRoot);
3234
//create new envb
3335
await addEnvironment(projectRoot, { envName: 'envb' });

packages/amplify-codegen-e2e-tests/src/__tests__/pull-codegen.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
deleteProjectDir,
44
deleteProject,
55
initJSProjectWithProfile,
6-
addApiWithSchemaAndConflictDetection,
6+
addApiWithBlankSchemaAndConflictDetection,
7+
updateApiSchema,
8+
createRandomName,
79
amplifyPush,
810
amplifyPull,
911
getAppId,
@@ -37,9 +39,11 @@ describe('Amplify pull in amplify app with codegen tests', () => {
3739
let projectRoot: string;
3840
let appId: string;
3941
beforeAll(async () => {
42+
const name = createRandomName();
4043
projectRoot = await createNewProjectDir('pullCodegen');
41-
await initJSProjectWithProfile(projectRoot, { envName, disableAmplifyAppCreation: false });
42-
await addApiWithSchemaAndConflictDetection(projectRoot, schema);
44+
await initJSProjectWithProfile(projectRoot, { name, envName, disableAmplifyAppCreation: false });
45+
await addApiWithBlankSchemaAndConflictDetection(projectRoot);
46+
await updateApiSchema(projectRoot, name, schema);
4347
await amplifyPush(projectRoot);
4448
appId = getAppId(projectRoot);
4549
expect(appId).toBeDefined();

packages/amplify-codegen-e2e-tests/src/__tests__/remove-codegen-js.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
DEFAULT_JS_CONFIG,
44
removeCodegen,
55
initProjectWithProfile,
6-
addApiWithSchema
6+
addApiWithoutSchema,
7+
updateApiSchema,
8+
createRandomName
79
} from "amplify-codegen-e2e-core";
810
import { deleteAmplifyProject, testRemoveCodegen } from '../codegen-tests-base';
911

@@ -23,7 +25,9 @@ describe('codegen remove tests - JS', () => {
2325
it(`Give appropriate message during remove when codegen is not added in JS project`, async () => {
2426
// init project and add API category
2527
await initProjectWithProfile(projectRoot, DEFAULT_JS_CONFIG);
26-
await addApiWithSchema(projectRoot, schema);
28+
const projectName = createRandomName();
29+
await addApiWithoutSchema(projectRoot, { apiName: projectName });
30+
await updateApiSchema(projectRoot, projectName, schema);
2731

2832
// remove command should give expected message
2933
await expect(removeCodegen(projectRoot, false)).resolves.not.toThrow();

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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
initProjectWithProfile,
3-
addApiWithSchemaAndConflictDetection,
3+
addApiWithBlankSchemaAndConflictDetection,
4+
updateApiSchema,
5+
createRandomName,
46
generateModels,
57
AmplifyFrontendConfig
68
} from "amplify-codegen-e2e-core";
@@ -9,11 +11,14 @@ import path from 'path';
911
import { isNotEmptyDir, generateSourceCode } from '../utils';
1012

1113
export async function testCodegenModels(config: AmplifyFrontendConfig, projectRoot: string, schema: string) {
14+
const name = createRandomName();
15+
1216
// init project and add API category
13-
await initProjectWithProfile(projectRoot, { ...config });
17+
await initProjectWithProfile(projectRoot, { name, ...config });
1418

1519
//enable datastore
16-
await addApiWithSchemaAndConflictDetection(projectRoot, schema);
20+
await addApiWithBlankSchemaAndConflictDetection(projectRoot);
21+
await updateApiSchema(projectRoot, name, schema);
1722

1823
//generate pre existing user file
1924
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);

0 commit comments

Comments
 (0)