-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(type-safe-api): generate handler tests for typescript
Generate example jest tests for typescript handlers. Fixes #570
- Loading branch information
Showing
9 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...pi/scripts/type-safe-api/generators/typescript-lambda-handlers/templates/tests.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
###TSAPI_SPLIT_FILE### | ||
{{#apiInfo ~}} | ||
{{#apis ~}} | ||
{{#operations ~}} | ||
{{#operation ~}} | ||
{{#if vendorExtensions.x-handler}} | ||
{{#startsWith vendorExtensions.x-handler.language 'typescript'}} | ||
###TSAPI_WRITE_FILE### | ||
{ | ||
"id": "{{nickname}}Test", | ||
"dir": ".", | ||
"name": "{{nickname}}", | ||
"ext": ".test.ts", | ||
"overwrite": false, | ||
"kebabCaseFileName": true, | ||
"generateConditionallyId": "{{nickname}}" | ||
} | ||
###/TSAPI_WRITE_FILE###import { | ||
InternalFailureErrorResponseContent, | ||
{{operationIdCamelCase}}ChainedRequestInput, | ||
} from "{{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-package-name}}{{/apis.0}}{{/apiInfo}}"; | ||
import { | ||
{{nickname}} | ||
} from "../src/###TSAPI_FN###{ "function": "kebabCase", "args": ["{{nickname}}"] }###/TSAPI_FN###"; | ||
|
||
// Common request arguments | ||
const requestArguments = { | ||
chain: undefined as never, | ||
event: {} as any, | ||
context: {} as any, | ||
interceptorContext: { | ||
logger: { | ||
info: jest.fn(), | ||
}, | ||
}, | ||
} satisfies Omit<{{operationIdCamelCase}}ChainedRequestInput, 'input'>; | ||
|
||
describe('{{operationIdCamelCase}}', () => { | ||
|
||
it('should return not implemented error', async () => { | ||
// TODO: Update the test as appropriate when you implement your handler | ||
const response = await {{nickname}}({ | ||
...requestArguments, | ||
input: { | ||
// TODO: remove the "as any" below and fill in test values for the requestParameters{{#if bodyParam}} and body{{/if}} | ||
requestParameters: {} as any, | ||
body: {} as {{#if bodyParam}}any{{else}}never{{/if}}, | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(500); | ||
expect((response.body as InternalFailureErrorResponseContent).message).toEqual('Not Implemented!'); | ||
}); | ||
|
||
}); | ||
|
||
{{~/startsWith}} | ||
{{~/if}} | ||
{{~/operation}} | ||
{{~/operations}} | ||
{{~/apis}} | ||
{{~/apiInfo}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...project/codegen/handlers/__snapshots__/generated-typescript-handlers-project.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
...pe-safe-api/test/scripts/generators/__snapshots__/typescript-lambda-handlers.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters