|
| 1 | +import { describe, expect, test } from '@jest/globals'; |
| 2 | +import * as child_process from 'child_process'; |
| 3 | +import { ExecException } from 'child_process'; |
| 4 | + |
| 5 | +describe('from dynamodb record transformation errors', () => { |
| 6 | + test('should raise error when the type parameter is missing', async () => { |
| 7 | + const err = await new Promise<ExecException | null>(resolve => { |
| 8 | + child_process.exec( |
| 9 | + 'NODE_NO_WARNINGS=true TS_DYNAMODB_ATTR_TRANSFORMER_LENIENT_TYPE_CHECK= npx ts-node -C ttypescript ./tests/from_dynamodb_record_transformer_error_src/no_type_parameter.ts', |
| 10 | + err => { |
| 11 | + resolve(err); |
| 12 | + }, |
| 13 | + ); |
| 14 | + }); |
| 15 | + |
| 16 | + expect(err).not.toBeNull(); |
| 17 | + expect(err?.message).toMatch( |
| 18 | + /Error: No type argument on fromDynamodbRecord\(\)\. Please put a type argument on the function/, |
| 19 | + ); |
| 20 | + }); |
| 21 | + |
| 22 | + test('should raise error when the type parameter is class', async () => { |
| 23 | + const err = await new Promise<ExecException | null>(resolve => { |
| 24 | + child_process.exec( |
| 25 | + 'NODE_NO_WARNINGS=true TS_DYNAMODB_ATTR_TRANSFORMER_LENIENT_TYPE_CHECK= npx ts-node -C ttypescript ./tests/from_dynamodb_record_transformer_error_src/class_type_parameter.ts', |
| 26 | + err => { |
| 27 | + resolve(err); |
| 28 | + }, |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + expect(err).not.toBeNull(); |
| 33 | + expect(err?.message).toMatch( |
| 34 | + /Error: A type parameter of fromDynamodbRecord\(\) must be interface, but Clazz is a class/, |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + test('should raise error when the type parameter is not class and interface', async () => { |
| 39 | + const err = await new Promise<ExecException | null>(resolve => { |
| 40 | + child_process.exec( |
| 41 | + 'NODE_NO_WARNINGS=true TS_DYNAMODB_ATTR_TRANSFORMER_LENIENT_TYPE_CHECK= npx ts-node -C ttypescript ./tests/from_dynamodb_record_transformer_error_src/object_literal_type_parameter.ts', |
| 42 | + err => { |
| 43 | + resolve(err); |
| 44 | + }, |
| 45 | + ); |
| 46 | + }); |
| 47 | + |
| 48 | + expect(err).not.toBeNull(); |
| 49 | + expect(err?.message).toMatch( |
| 50 | + /Error: A type parameter of fromDynamodbRecord\(\) must be interface, but \{\} is not/, |
| 51 | + ); |
| 52 | + }); |
| 53 | +}); |
0 commit comments