Skip to content

Commit 7f1a3b7

Browse files
committed
feat: add unit tests
1 parent f2d7507 commit 7f1a3b7

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

packages/amplify-cli/src/__tests__/commands/gen2-migration/generate/amplify/rest-api/rest-api.renderer.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,27 @@ describe('RestApiRenderer', () => {
574574
`);
575575
});
576576

577+
it('sanitizes hyphenated path names into valid variable names', () => {
578+
const renderer = new RestApiRenderer(false, new Set(['myFunc']));
579+
const restApi = createBasicRestApi({
580+
paths: [{ path: '/auth-test', methods: ['GET'], lambdaFunction: 'myFunc' }],
581+
});
582+
const output = printStatements(renderer.renderApi(restApi));
583+
584+
expect(output).toContain('const authtest = ');
585+
expect(output).not.toContain('const auth-test');
586+
});
587+
588+
it('sanitizes hyphenated api names into valid variable names', () => {
589+
const renderer = new RestApiRenderer(false, new Set(['myFunc']));
590+
const restApi = createBasicRestApi({ apiName: 'my-api' });
591+
const output = printStatements(renderer.renderApi(restApi));
592+
593+
expect(output).toContain('const myapiStack = ');
594+
expect(output).toContain('const myapiApi = ');
595+
expect(output).not.toContain('const my-api');
596+
});
597+
577598
it('handles no uniqueFunctions gracefully', () => {
578599
const renderer = new RestApiRenderer(false, new Set());
579600
const restApi = createBasicRestApi({ uniqueFunctions: undefined });

0 commit comments

Comments
 (0)