Skip to content

Commit

Permalink
test create list lambda function
Browse files Browse the repository at this point in the history
  • Loading branch information
ebisbe committed Jul 7, 2024
1 parent 5a548cb commit d9fc365
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
Empty file removed src/functions/list.ts
Empty file.
30 changes: 29 additions & 1 deletion src/functions/list/__tests__/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,35 @@ describe("CREATE List", () => {
});
});

it("creates a new list", () => {});
it("creates a new list", async () => {
const event = {
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
userId: "userId",
name: "My Wedding List",
description: "This is my wedding gift list.",
}),
};
const response = await handler(event);

expect(response.statusCode).toBe(200);

const body = JSON.parse(response.body);

expect(body.id).toMatch(/^[A-Z0-9]{26}$/);
expect(body.userId).toBe("userId");
expect(body.name).toBe("My Wedding List");
expect(body.description).toBe("This is my wedding gift list.");
expect(body.totalValue).toBe(0);
expect(body.totalItems).toBe(0);

const dateRegExp =
/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z$/;
expect(body.createdAt).toMatch(dateRegExp);
expect(body.updatedAt).toMatch(dateRegExp);
});

it("does not received all required properties", async () => {
const event = {
Expand Down
2 changes: 0 additions & 2 deletions src/functions/list/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const createListHandler: Handler<APIGatewayProxyEventV2> = async (event) => {
}

const createdList = await List.create(list.data);
delete createdList.pk;
delete createdList.sk;

return {
statusCode: 200,
Expand Down
15 changes: 7 additions & 8 deletions src/models/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const MySchema = {
primary: { hash: "pk", sort: "sk" },
},
params: {
typeField: "__typename",
isoDates: true,
typeField: "__typeName",
separator: "#",
timestamps: true,
createdField: "createdAt",
Expand All @@ -37,8 +36,8 @@ const MySchema = {
description: { type: String },
totalValue: { type: Number, default: 0 },
totalItems: { type: Number, default: 0 },
createdAt: { type: String },
updatedAt: { type: String },
createdAt: { type: Date },
updatedAt: { type: Date },
},
Item: {
pk: { type: String, value: "LIST#${listId}" },
Expand All @@ -48,17 +47,17 @@ const MySchema = {
name: { type: String },
description: { type: String },
value: { type: Number, default: 0 },
createdAt: { type: String },
updatedAt: { type: String },
createdAt: { type: Date },
updatedAt: { type: Date },
},
Buyer: {
pk: { type: String, value: "ITEM#${itemId}" },
sk: { type: String, value: "BUYER#${userId}" },
userId: { type: String, required: true },
name: { type: String, required: true },
itemId: { type: String, required: true },
createdAt: { type: String },
updatedAt: { type: String },
createdAt: { type: Date },
updatedAt: { type: Date },
},
} as const,
};
Expand Down

0 comments on commit d9fc365

Please sign in to comment.