Skip to content

Commit

Permalink
test(lib-dynamodb): enhance type safety (#6074)
Browse files Browse the repository at this point in the history
  • Loading branch information
siddsriv authored May 8, 2024
1 parent 67fbd23 commit 74e4c14
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/lib-dynamodb/src/test/lib-dynamodb.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ import {
jest.setTimeout(180000);

describe(DynamoDBDocument.name, () => {
type NestedList = (string | NumberValue | boolean | Set<string> | Set<NumberValue> | null | NestedList | NestedMap)[];
type NestedMap = {
[key: string]: string | NumberValue | boolean | Set<string> | Set<NumberValue> | null | NestedList | NestedMap;
};

type DataType = {
null: null;
string: string;
number: NumberValue;
bigInt: NumberValue;
bigNumber: NumberValue;
boolean: boolean;
sSet: Set<string>;
nSet: Set<NumberValue>;
list: NestedList;
map: NestedMap;
[key: string]: any;
};

const dynamodb = new DynamoDB({ region: "us-west-2", maxAttempts: 10 });
const doc = DynamoDBDocument.from(dynamodb, {
marshallOptions: {
Expand Down Expand Up @@ -82,7 +101,7 @@ describe(DynamoDBDocument.name, () => {
},
};

const data = {
const data: DataType = {
null: null,
string: "myString",
number: NumberValue.from(1),
Expand Down Expand Up @@ -137,7 +156,7 @@ describe(DynamoDBDocument.name, () => {
if (input instanceof NumberValue) {
return NumberValue.from(input.toString()) as T;
}
return Object.entries(input).reduce((acc, [k, v]) => {
return Object.entries(input).reduce((acc: { [key: string]: any }, [k, v]) => {
acc[updateTransform(k)] = updateTransform(v);
return acc;
}, {}) as T;
Expand All @@ -151,7 +170,7 @@ describe(DynamoDBDocument.name, () => {
return input;
};

const passError = (e) => e;
const passError = (e: any) => e;

beforeAll(async () => {
log.describe = await dynamodb
Expand Down

0 comments on commit 74e4c14

Please sign in to comment.