@aws-amplify/amplify-util-uibuilder 1.10.1-sobkamil-test-0822.0 → 1.11.0-noinit-codegen.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/package.json +6 -6
  3. package/src/__tests__/.eslintrc.js +0 -9
  4. package/src/__tests__/__snapshots__/syncAmplifyUiComponents.test.ts.snap +0 -46
  5. package/src/__tests__/cloneComponentsFromEnv.test.ts +0 -79
  6. package/src/__tests__/detachedFormCleanup.test.ts +0 -77
  7. package/src/__tests__/generateComponents.test.ts +0 -342
  8. package/src/__tests__/getAmplifyDataSchema.test.ts +0 -82
  9. package/src/__tests__/handleEvents.test.ts +0 -27
  10. package/src/__tests__/help.test.ts +0 -10
  11. package/src/__tests__/mock.json +0 -1
  12. package/src/__tests__/notifyMissingPackages.test.ts +0 -86
  13. package/src/__tests__/package.json +0 -3
  14. package/src/__tests__/prePushHandler.test.ts +0 -116
  15. package/src/__tests__/shouldRenderComponents.test.ts +0 -112
  16. package/src/__tests__/storageManager.test.ts +0 -45
  17. package/src/__tests__/syncAmplifyUiComponents.test.ts +0 -309
  18. package/src/__tests__/utils/getApiConfiguration.test.ts +0 -41
  19. package/src/__tests__/utils.ts +0 -72
  20. package/src/__tests__/version.test.ts +0 -10
  21. package/src/clients/amplify-studio-client.ts +0 -320
  22. package/src/clients/index.ts +0 -1
  23. package/src/commands/cloneComponentsFromEnv.ts +0 -53
  24. package/src/commands/generateComponents.ts +0 -125
  25. package/src/commands/help.ts +0 -8
  26. package/src/commands/utils/codegenResources.ts +0 -23
  27. package/src/commands/utils/detachedFormCleanup.ts +0 -54
  28. package/src/commands/utils/environmentHelpers.ts +0 -32
  29. package/src/commands/utils/extractArgs.ts +0 -25
  30. package/src/commands/utils/featureFlags.ts +0 -61
  31. package/src/commands/utils/getApiConfiguration.ts +0 -73
  32. package/src/commands/utils/getUiBuilderComponentsPath.ts +0 -21
  33. package/src/commands/utils/index.ts +0 -9
  34. package/src/commands/utils/notifyMissingPackages.ts +0 -47
  35. package/src/commands/utils/shouldRenderComponents.ts +0 -48
  36. package/src/commands/utils/storageManager.ts +0 -13
  37. package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +0 -232
  38. package/src/commands/version.ts +0 -9
  39. package/src/event-handlers/handle-PostEnvAdd.ts +0 -16
  40. package/src/event-handlers/handle-PostPull.ts +0 -15
  41. package/src/event-handlers/handle-PostPush.ts +0 -15
  42. package/src/event-handlers/handle-PrePush.ts +0 -15
  43. package/src/index.ts +0 -26
  44. package/src/utils/prePushHandler.ts +0 -51
  45. package/tsconfig.json +0 -9
  46. package/tsconfig.tsbuildinfo +0 -1
package/CHANGELOG.md CHANGED
@@ -3,9 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [1.10.1-sobkamil-test-0822.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/amplify-util-uibuilder@1.10.0...@aws-amplify/amplify-util-uibuilder@1.10.1-sobkamil-test-0822.0) (2023-08-22)
6
+ # [1.11.0-noinit-codegen.0](https://github.com/aws-amplify/amplify-cli/compare/@aws-amplify/amplify-util-uibuilder@1.10.0...@aws-amplify/amplify-util-uibuilder@1.11.0-noinit-codegen.0) (2023-09-19)
7
7
 
8
- **Note:** Version bump only for package @aws-amplify/amplify-util-uibuilder
8
+
9
+ ### Bug Fixes
10
+
11
+ * exclude tests from publish ([#13153](https://github.com/aws-amplify/amplify-cli/issues/13153)) ([1b1fe09](https://github.com/aws-amplify/amplify-cli/commit/1b1fe09a1c08be0262a1013f71354abd7160722a))
12
+
13
+
14
+ ### Features
15
+
16
+ * support codegen and modelgen commands in non-amplify directories ([448a90e](https://github.com/aws-amplify/amplify-cli/commit/448a90e5080f6abf738890aca025d7c00f2d8f28))
9
17
 
10
18
 
11
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/amplify-util-uibuilder",
3
- "version": "1.10.1-sobkamil-test-0822.0",
3
+ "version": "1.11.0-noinit-codegen.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -14,12 +14,12 @@
14
14
  "access": "public"
15
15
  },
16
16
  "dependencies": {
17
- "@aws-amplify/amplify-category-api": "^5.5.2",
18
- "@aws-amplify/amplify-cli-core": "4.2.6-sobkamil-test-0822.0",
19
- "@aws-amplify/amplify-prompts": "2.8.2",
17
+ "@aws-amplify/amplify-category-api": "^5.6.4",
18
+ "@aws-amplify/amplify-cli-core": "4.2.6-noinit-codegen.0",
19
+ "@aws-amplify/amplify-prompts": "2.8.3-noinit-codegen.0",
20
20
  "@aws-amplify/codegen-ui": "2.14.2",
21
21
  "@aws-amplify/codegen-ui-react": "2.14.2",
22
- "amplify-codegen": "^4.3.0",
22
+ "amplify-codegen": "^4.6.0",
23
23
  "aws-sdk": "^2.1426.0",
24
24
  "fs-extra": "^8.1.0",
25
25
  "node-fetch": "^2.6.7",
@@ -82,5 +82,5 @@
82
82
  "@yarn/plugin-typescript"
83
83
  ]
84
84
  },
85
- "gitHead": "b7e47e32644ad88ff71423f49fa8207a05ad2229"
85
+ "gitHead": "939507e67a292f7dd6f88ab56449a6bb85f5fb39"
86
86
  }
@@ -1,9 +0,0 @@
1
- module.exports = {
2
- rules: {
3
- // Tests in this directory use an empty package.json file
4
- // that triggers import/no-extraneous-dependencies rule
5
- // as it looks for closest package.json.
6
- // This is false positive.
7
- 'import/no-extraneous-dependencies': 'off',
8
- },
9
- };
@@ -1,46 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`should sync amplify ui builder components can map generic data schema to start codegen job request 1`] = `
4
- {
5
- "dataSourceType": "DataStore",
6
- "enums": {
7
- "Status": {
8
- "values": [
9
- "ENABLED",
10
- "DISABLED",
11
- "HIDDEN",
12
- ],
13
- },
14
- },
15
- "models": {
16
- "Blog": {
17
- "fields": {
18
- "id": {
19
- "dataType": "ID",
20
- "dataTypeValue": "ID",
21
- "isArray": false,
22
- "readOnly": false,
23
- "required": true,
24
- },
25
- },
26
- "isJoinTable": undefined,
27
- "primaryKeys": [
28
- "id",
29
- ],
30
- },
31
- },
32
- "nonModels": {
33
- "Metadata": {
34
- "fields": {
35
- "name": {
36
- "dataType": "String",
37
- "dataTypeValue": "String",
38
- "isArray": false,
39
- "readOnly": false,
40
- "required": false,
41
- },
42
- },
43
- },
44
- },
45
- }
46
- `;
@@ -1,79 +0,0 @@
1
- import aws from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
2
- import * as extractArgsDependency from '../commands/utils/extractArgs';
3
- import { run } from '../commands/cloneComponentsFromEnv';
4
- import { isDataStoreEnabled } from '@aws-amplify/amplify-category-api';
5
-
6
- const extractArgsDependencyMock = extractArgsDependency as any;
7
- const awsMock = aws as any;
8
-
9
- jest.mock('../commands/utils/featureFlags', () => ({
10
- getTransformerVersion: jest.fn().mockReturnValue(2),
11
- }));
12
- jest.mock('@aws-amplify/amplify-category-api', () => ({
13
- ...jest.requireActual('@aws-amplify/amplify-category-api'),
14
- isDataStoreEnabled: jest.fn(),
15
- }));
16
- jest.mock('../commands/utils/extractArgs');
17
- jest.mock('@aws-amplify/amplify-cli-core');
18
-
19
- const isDataStoreEnabledMocked = jest.mocked(isDataStoreEnabled);
20
-
21
- const mockedComponentExport = jest.fn((envName: string) => {
22
- if (envName === 'newEnvName') {
23
- return {
24
- entities: [],
25
- };
26
- }
27
- return {
28
- entities: [{}],
29
- };
30
- });
31
- const mockedComponentCreate = jest.fn().mockReturnValue({ entity: {} });
32
-
33
- describe('can clone components to new environment', () => {
34
- let context: any;
35
- beforeEach(() => {
36
- isDataStoreEnabledMocked.mockResolvedValue(true);
37
- context = {
38
- amplify: {
39
- invokePluginMethod: () => ({}),
40
- },
41
- input: {
42
- options: {
43
- appId: 'testAppId',
44
- envName: 'testEnvName',
45
- },
46
- },
47
- };
48
- extractArgsDependencyMock.extractArgs = jest.fn().mockReturnValue({
49
- sourceEnvName: 'sourceEnvName',
50
- newEnvName: 'newEnvName',
51
- appId: 'appId',
52
- environmentName: 'environmentName',
53
- });
54
- awsMock.AmplifyUIBuilder = jest.fn().mockReturnValue({
55
- exportComponents: jest.fn(({ environmentName }) => ({
56
- promise: () => mockedComponentExport(environmentName),
57
- })),
58
- createComponent: jest.fn().mockReturnValue({ promise: () => mockedComponentCreate() }),
59
- getMetadata: jest.fn().mockReturnValue({
60
- promise: jest.fn().mockReturnValue({
61
- features: {
62
- autoGenerateForms: 'true',
63
- autoGenerateViews: 'true',
64
- formFeatureFlags: {
65
- isRelationshipSupported: 'false',
66
- isNonModelSupported: 'false',
67
- },
68
- },
69
- }),
70
- }),
71
- });
72
- });
73
-
74
- it('clones components to a new env', async () => {
75
- await run(context);
76
- expect(mockedComponentExport).toBeCalledTimes(2);
77
- expect(mockedComponentCreate).toBeCalledTimes(1);
78
- });
79
- });
@@ -1,77 +0,0 @@
1
- import { AmplifyStudioClient } from '../clients'; // eslint-disable-line import/no-extraneous-dependencies
2
- import { isFormDetachedFromModel, isFormSchemaCustomized, isStudioForm, deleteDetachedForms } from '../commands/utils';
3
- import { Form } from 'aws-sdk/clients/amplifyuibuilder';
4
-
5
- const amplifyStudioClientMock = AmplifyStudioClient as any;
6
-
7
- const formWithNoCustomization: Form = {
8
- id: 'f-123456',
9
- appId: 'd1234',
10
- environmentName: 'staging',
11
- name: 'BlogCreateForm',
12
- formActionType: 'create',
13
- dataType: {
14
- dataSourceType: 'DataStore',
15
- dataTypeName: 'Blog',
16
- },
17
- fields: {},
18
- sectionalElements: {},
19
- style: {},
20
- cta: {},
21
- schemaVersion: '1.0',
22
- };
23
-
24
- const formWithStyle: Form = {
25
- ...formWithNoCustomization,
26
- dataType: { dataSourceType: 'Custom', dataTypeName: 'Blog' },
27
- style: {
28
- horizontalGap: { value: '20px' },
29
- },
30
- };
31
-
32
- const formWithFields: Form = {
33
- ...formWithNoCustomization,
34
- dataType: { dataSourceType: 'Custom', dataTypeName: 'Blog' },
35
- fields: {
36
- name: { inputType: { type: 'TextField' } },
37
- },
38
- };
39
-
40
- describe('detachedFormCleanup', () => {
41
- it('isStudioForm should return true', () => {
42
- expect(isStudioForm(formWithNoCustomization)).toBe(true);
43
- });
44
-
45
- it('isStudioForm should return false', () => {
46
- expect(isStudioForm(undefined)).toBe(false);
47
- });
48
-
49
- it('isFormSchemaCustomized should return false', () => {
50
- expect(isFormSchemaCustomized(formWithNoCustomization)).toBe(false);
51
- });
52
-
53
- it('isFormSchemaCustomized should return true', () => {
54
- expect(isFormSchemaCustomized(formWithStyle)).toBe(true);
55
- expect(isFormSchemaCustomized(formWithFields)).toBe(true);
56
- });
57
-
58
- it('isFormDetachedFromModel should return true for a DataStore form with detached model', () => {
59
- expect(isFormDetachedFromModel(formWithNoCustomization, new Set<string>())).toBe(true);
60
- });
61
-
62
- it('isFormDetachedFromModel should return false for a Custom form', () => {
63
- expect(isFormDetachedFromModel(formWithStyle, new Set<string>())).toBe(false);
64
- });
65
-
66
- it('isFormDetachedFromModel should return false for a DataStore form with an attached model', () => {
67
- expect(isFormDetachedFromModel(formWithNoCustomization, new Set<string>().add('Blog'))).toBe(false);
68
- });
69
-
70
- it('should delete detached forms', async () => {
71
- const mockedDeleteForm = jest.fn().mockReturnValue(undefined);
72
- amplifyStudioClientMock.deleteForm = mockedDeleteForm;
73
- await deleteDetachedForms([{ id: '12345', name: 'BlogCreateForm' }], amplifyStudioClientMock);
74
- expect(mockedDeleteForm).toBeCalledTimes(1);
75
- expect(mockedDeleteForm).toHaveBeenCalledWith('12345');
76
- });
77
- });
@@ -1,342 +0,0 @@
1
- import aws from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
2
- import * as utils from '../commands/utils';
3
- import { run } from '../commands/generateComponents';
4
- import { isDataStoreEnabled } from '@aws-amplify/amplify-category-api';
5
- import { getTransformerVersion } from '../commands/utils/featureFlags';
6
- import { getCodegenConfig } from 'amplify-codegen';
7
- import { getUiBuilderComponentsPath } from '../commands/utils/getUiBuilderComponentsPath';
8
-
9
- jest.mock('../commands/utils');
10
- jest.mock('@aws-amplify/amplify-cli-core');
11
- jest.mock('@aws-amplify/amplify-category-api', () => ({
12
- ...jest.requireActual('@aws-amplify/amplify-category-api'),
13
- isDataStoreEnabled: jest.fn(),
14
- }));
15
- jest.mock('../commands/utils/featureFlags', () => ({
16
- ...jest.requireActual('../commands/utils/featureFlags'),
17
- getTransformerVersion: jest.fn(),
18
- }));
19
- jest.mock('../commands/utils/getUiBuilderComponentsPath', () => ({
20
- ...jest.requireActual('../commands/utils/getUiBuilderComponentsPath'),
21
- getUiBuilderComponentsPath: jest.fn(),
22
- }));
23
- jest.mock('amplify-codegen', () => ({
24
- ...jest.requireActual('amplify-codegen'),
25
- getCodegenConfig: jest.fn(),
26
- }));
27
-
28
- const awsMock = aws as any;
29
- const utilsMock = utils as any;
30
- const isDataStoreEnabledMocked = isDataStoreEnabled as any;
31
- const getTransformerVersionMocked = getTransformerVersion as any;
32
- const getCodegenConfigMocked = getCodegenConfig as any;
33
- const getUiBuilderComponentsPathMocked = getUiBuilderComponentsPath as any;
34
-
35
- utilsMock.shouldRenderComponents = jest.fn().mockReturnValue(true);
36
- utilsMock.notifyMissingPackages = jest.fn().mockReturnValue(true);
37
- utilsMock.getAmplifyDataSchema = jest.fn().mockReturnValue({});
38
- utilsMock.isFormDetachedFromModel = jest.fn().mockReturnValue(false);
39
- utilsMock.extractUIComponents = jest.fn().mockReturnValue(undefined);
40
- utilsMock.waitForSucceededJob = jest
41
- .fn()
42
- .mockReturnValue({ asset: { downloadUrl: 'amazon.com' }, statusMessage: `{\"codegenErrors\": [{\"schemaName\": \"BlogUpdateForm\"}]}` });
43
-
44
- jest.mock('../commands/utils/featureFlags', () => ({
45
- getTransformerVersion: jest.fn().mockReturnValue(2),
46
- }));
47
-
48
- const defaultStudioFeatureFlags = {
49
- autoGenerateForms: 'true',
50
- autoGenerateViews: 'true',
51
- isRelationshipSupported: 'false',
52
- isNonModelSupported: 'false',
53
- isGraphQLEnabled: 'true',
54
- };
55
-
56
- const projectPath = '/usr/test/test-project';
57
-
58
- describe('can generate components', () => {
59
- let context: any;
60
- let schemas: any;
61
- let mockedExport: jest.Mock<any, any>;
62
- const getMetadataPromise = jest.fn().mockReturnValue({
63
- features: {
64
- ...defaultStudioFeatureFlags,
65
- },
66
- });
67
- const startCodegenJobPromise = jest.fn().mockReturnValue({
68
- entity: { id: 'jobId123' },
69
- });
70
- const mockStartCodegenJob = jest.fn().mockReturnValue({
71
- promise: startCodegenJobPromise,
72
- });
73
- beforeEach(() => {
74
- jest.clearAllMocks();
75
- isDataStoreEnabledMocked.mockResolvedValue(true);
76
- getTransformerVersionMocked.mockResolvedValue(2);
77
- context = {
78
- amplify: {
79
- invokePluginMethod: () => ({}),
80
- },
81
- input: {
82
- options: {
83
- appId: 'testAppId',
84
- envName: 'testEnvName',
85
- },
86
- },
87
- exeInfo: {
88
- localEnvInfo: {
89
- projectPath,
90
- },
91
- },
92
- };
93
- schemas = {
94
- entities: [
95
- {
96
- schemaName: 'testSchema',
97
- name: 'testSchema',
98
- schemaVersion: '1.0',
99
- },
100
- {
101
- schemaName: 'testSchema',
102
- name: 'testSchema',
103
- schemaVersion: '1.0',
104
- schema: { id: 'f-123456', name: 'testSchema' },
105
- },
106
- ],
107
- };
108
-
109
- getCodegenConfigMocked.mockReturnValue({
110
- getGeneratedTypesPath: jest.fn().mockReturnValue(undefined),
111
- getGeneratedQueriesPath: jest.fn().mockReturnValue(projectPath + '/src/graphql/queries.js'),
112
- getGeneratedMutationsPath: jest.fn().mockReturnValue(projectPath + '/src/graphql/mutations.js'),
113
- getGeneratedSubscriptionsPath: jest.fn().mockReturnValue(projectPath + '/src/graphql/subscriptions.js'),
114
- getGeneratedFragmentsPath: jest.fn().mockReturnValue(projectPath + '/src/graphql/fragments.js'),
115
- getQueryMaxDepth: jest.fn().mockReturnValue(3),
116
- });
117
-
118
- mockedExport = jest.fn().mockReturnValue({
119
- entities: schemas.entities,
120
- });
121
- awsMock.AmplifyUIBuilder = jest.fn().mockReturnValue({
122
- exportComponents: jest.fn().mockReturnValue({
123
- promise: () => mockedExport(),
124
- }),
125
- exportThemes: jest.fn().mockReturnValue({
126
- promise: () => mockedExport(),
127
- }),
128
- exportForms: jest.fn().mockReturnValue({
129
- promise: () => mockedExport(),
130
- }),
131
- exportViews: jest.fn().mockReturnValue({
132
- promise: () => mockedExport(),
133
- }),
134
- getMetadata: jest.fn().mockReturnValue({
135
- promise: getMetadataPromise,
136
- }),
137
- startCodegenJob: mockStartCodegenJob,
138
- getCodegenJob: jest.fn().mockReturnValue({
139
- promise: jest.fn().mockReturnValue({ status: 'succeeded' }),
140
- }),
141
- });
142
- getUiBuilderComponentsPathMocked.mockReturnValue(projectPath + '/src/ui-components');
143
- utilsMock.generateUiBuilderComponents = jest.fn().mockReturnValue(schemas.entities);
144
- utilsMock.generateUiBuilderThemes = jest.fn().mockReturnValue(schemas.entities);
145
- utilsMock.generateUiBuilderForms = jest.fn().mockReturnValue(schemas.entities);
146
- utilsMock.generateAmplifyUiBuilderIndexFile = jest.fn().mockReturnValue(true);
147
- utilsMock.generateAmplifyUiBuilderUtilFile = jest.fn().mockReturnValue(true);
148
- utilsMock.deleteDetachedForms = jest.fn();
149
- });
150
-
151
- it('runs generateComponents', async () => {
152
- utilsMock.isFormDetachedFromModel = jest.fn().mockReturnValueOnce(true);
153
- await run(context, 'PostPull');
154
- expect(mockedExport).toBeCalledTimes(3);
155
- expect(startCodegenJobPromise).toBeCalledTimes(1);
156
- expect(utilsMock.waitForSucceededJob).toBeCalledTimes(1);
157
- expect(getUiBuilderComponentsPathMocked).toBeCalledTimes(1);
158
- expect(utilsMock.extractUIComponents).toBeCalledTimes(1);
159
- expect(utilsMock.deleteDetachedForms).toBeCalledTimes(1);
160
- });
161
-
162
- it('should autogenerate forms if transformer v2 and datastore and feature flag are enabled', async () => {
163
- isDataStoreEnabledMocked.mockResolvedValue(true);
164
- getTransformerVersionMocked.mockResolvedValue(2);
165
- getMetadataPromise.mockReturnValue({
166
- features: {
167
- ...defaultStudioFeatureFlags,
168
- },
169
- });
170
- await run(context, 'PostPull');
171
- expect(mockStartCodegenJob).toHaveBeenCalledWith({
172
- appId: 'testAppId',
173
- environmentName: 'testEnvName',
174
- codegenJobToCreate: expect.objectContaining({ autoGenerateForms: true }),
175
- });
176
- });
177
-
178
- it('should not autogenerate forms if transformer v1', async () => {
179
- isDataStoreEnabledMocked.mockResolvedValue(true);
180
- getTransformerVersionMocked.mockResolvedValue(1);
181
- getMetadataPromise.mockReturnValue({
182
- features: {
183
- ...defaultStudioFeatureFlags,
184
- },
185
- });
186
- await run(context, 'PostPull');
187
- expect(mockStartCodegenJob).toHaveBeenCalledWith({
188
- appId: 'testAppId',
189
- environmentName: 'testEnvName',
190
- codegenJobToCreate: expect.objectContaining({ autoGenerateForms: false }),
191
- });
192
- });
193
-
194
- it('should not autogenerate forms if datastore is not enabled and GraphQL is not enabled', async () => {
195
- isDataStoreEnabledMocked.mockResolvedValue(false);
196
- getMetadataPromise.mockReturnValue({
197
- features: {
198
- ...defaultStudioFeatureFlags,
199
- isGraphQLEnabled: 'false',
200
- },
201
- });
202
- await run(context, 'PostPull');
203
- expect(mockStartCodegenJob).toHaveBeenCalledWith({
204
- appId: 'testAppId',
205
- environmentName: 'testEnvName',
206
- codegenJobToCreate: expect.objectContaining({ autoGenerateForms: false }),
207
- });
208
- });
209
-
210
- it('should not autogenerate forms if datastore is not enabled and GraphQL is enabled with invalid config', async () => {
211
- isDataStoreEnabledMocked.mockResolvedValue(false);
212
- getMetadataPromise.mockReturnValue({
213
- features: {
214
- ...defaultStudioFeatureFlags,
215
- isGraphQLEnabled: 'true',
216
- },
217
- });
218
- getCodegenConfigMocked.mockImplementation(() => {
219
- throw new Error();
220
- });
221
- await run(context, 'PostPull');
222
- expect(mockStartCodegenJob).toHaveBeenCalledWith({
223
- appId: 'testAppId',
224
- environmentName: 'testEnvName',
225
- codegenJobToCreate: expect.objectContaining({ autoGenerateForms: false }),
226
- });
227
- });
228
-
229
- it('should autogenerate forms if datastore is not enabled and GraphQL is enabled with valid config', async () => {
230
- isDataStoreEnabledMocked.mockResolvedValue(false);
231
- getMetadataPromise.mockReturnValue({
232
- features: {
233
- ...defaultStudioFeatureFlags,
234
- isGraphQLEnabled: 'true',
235
- },
236
- });
237
- await run(context, 'PostPull');
238
- expect(mockStartCodegenJob).toHaveBeenCalledWith({
239
- appId: 'testAppId',
240
- environmentName: 'testEnvName',
241
- codegenJobToCreate: expect.objectContaining({ autoGenerateForms: true }),
242
- });
243
- });
244
-
245
- it('should not autogenerate forms if feature flag is not enabled', async () => {
246
- isDataStoreEnabledMocked.mockResolvedValue(true);
247
- getMetadataPromise.mockReturnValue({
248
- features: {
249
- ...defaultStudioFeatureFlags,
250
- autoGenerateForms: 'false',
251
- },
252
- });
253
- await run(context, 'PostPull');
254
- expect(mockStartCodegenJob).toHaveBeenCalledWith({
255
- appId: 'testAppId',
256
- environmentName: 'testEnvName',
257
- codegenJobToCreate: expect.objectContaining({ autoGenerateForms: false }),
258
- });
259
- });
260
-
261
- describe('codegen job creation', () => {
262
- it('should inclue dataStore configuration when dataStore is enabled', async () => {
263
- isDataStoreEnabledMocked.mockResolvedValue(true);
264
- getMetadataPromise.mockReturnValue({
265
- features: {
266
- ...defaultStudioFeatureFlags,
267
- },
268
- });
269
- await run(context, 'PostPull');
270
- expect(mockStartCodegenJob).toHaveBeenCalledWith({
271
- appId: 'testAppId',
272
- environmentName: 'testEnvName',
273
- codegenJobToCreate: expect.objectContaining({
274
- renderConfig: {
275
- react: expect.objectContaining({
276
- apiConfiguration: {
277
- dataStoreConfig: {},
278
- },
279
- }),
280
- },
281
- }),
282
- });
283
- });
284
-
285
- it('should inclue GraphQL configuration when dataStore is disabled and valid api configuration is found', async () => {
286
- isDataStoreEnabledMocked.mockResolvedValue(false);
287
- getMetadataPromise.mockReturnValue({
288
- features: {
289
- ...defaultStudioFeatureFlags,
290
- isGraphQLEnabled: 'true',
291
- },
292
- });
293
- await run(context, 'PostPull');
294
- expect(mockStartCodegenJob).toHaveBeenCalledWith({
295
- appId: 'testAppId',
296
- environmentName: 'testEnvName',
297
- codegenJobToCreate: expect.objectContaining({
298
- renderConfig: {
299
- react: expect.objectContaining({
300
- apiConfiguration: {
301
- graphQLConfig: {
302
- fragmentsFilePath: '../graphql/fragments.js',
303
- mutationsFilePath: '../graphql/mutations.js',
304
- queriesFilePath: '../graphql/queries.js',
305
- subscriptionsFilePath: '../graphql/subscriptions.js',
306
- typesFilePath: '',
307
- },
308
- },
309
- }),
310
- },
311
- }),
312
- });
313
- });
314
-
315
- it('should inclue noApi configuration when dataStore is disabled and no valid GraphQL Api', async () => {
316
- isDataStoreEnabledMocked.mockResolvedValue(false);
317
- getMetadataPromise.mockReturnValue({
318
- features: {
319
- ...defaultStudioFeatureFlags,
320
- isGraphQLEnabled: 'true',
321
- },
322
- });
323
- getCodegenConfigMocked.mockImplementation(() => {
324
- throw new Error();
325
- });
326
- await run(context, 'PostPull');
327
- expect(mockStartCodegenJob).toHaveBeenCalledWith({
328
- appId: 'testAppId',
329
- environmentName: 'testEnvName',
330
- codegenJobToCreate: expect.objectContaining({
331
- renderConfig: {
332
- react: expect.objectContaining({
333
- apiConfiguration: {
334
- noApiConfig: {},
335
- },
336
- }),
337
- },
338
- }),
339
- });
340
- });
341
- });
342
- });
@@ -1,82 +0,0 @@
1
- import { printer } from '@aws-amplify/amplify-prompts'; // eslint-disable-line import/no-extraneous-dependencies
2
- import { getAmplifyDataSchema } from '../commands/utils';
3
-
4
- jest.mock('@aws-amplify/amplify-prompts');
5
-
6
- const printerMock = jest.mocked(printer);
7
-
8
- const sampleIntrospectionSchema = {
9
- version: 1,
10
- models: {
11
- Blog: {
12
- name: 'Blog',
13
- fields: {
14
- id: {
15
- name: 'id',
16
- isArray: false,
17
- type: 'ID',
18
- isRequired: true,
19
- attributes: [],
20
- },
21
- },
22
- syncable: true,
23
- pluralName: 'Users',
24
- attributes: [
25
- {
26
- type: 'model',
27
- properties: {},
28
- },
29
- ],
30
- primaryKeyInfo: {
31
- isCustomPrimaryKey: false,
32
- primaryKeyFieldName: 'id',
33
- sortKeyFieldNames: [],
34
- },
35
- },
36
- },
37
- enums: {},
38
- nonModels: {},
39
- };
40
-
41
- const mockedGetModelIntrospection = jest.fn();
42
-
43
- describe('should sync amplify backend models', () => {
44
- let context: any;
45
-
46
- beforeEach(() => {
47
- context = {
48
- amplify: {
49
- invokePluginMethod: mockedGetModelIntrospection,
50
- },
51
- };
52
-
53
- mockedGetModelIntrospection.mockReset();
54
- });
55
-
56
- it('should get generic schema from introspection schema', async () => {
57
- mockedGetModelIntrospection.mockReturnValue(sampleIntrospectionSchema);
58
-
59
- const dataSchema = await getAmplifyDataSchema(context);
60
- expect(dataSchema).toBeDefined();
61
- expect(Object.keys(dataSchema!.models)).toContain('Blog');
62
- });
63
-
64
- it('should handle schema not found', async () => {
65
- mockedGetModelIntrospection.mockReturnValue(undefined);
66
-
67
- const dataSchema = await getAmplifyDataSchema(context);
68
- expect(dataSchema).toBeUndefined();
69
- expect(printerMock.debug).toHaveBeenCalledWith('Local schema not found');
70
- });
71
-
72
- it('should handle error', async () => {
73
- const error = new Error('Something went wrong');
74
- mockedGetModelIntrospection.mockImplementation(() => {
75
- throw error;
76
- });
77
-
78
- const dataSchema = await getAmplifyDataSchema(context);
79
- expect(dataSchema).toBeUndefined();
80
- expect(printerMock.debug).toHaveBeenCalledWith(error.toString());
81
- });
82
- });