This repository has been archived on 2025-12-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tasker/tasker-server/tests/createProject.test.ts
Andrew Trieu e293ab3c2c Config ci cd (#5)
* feat: Add GitHub Actions workflow for Amplify deployment and configuration

* feat: Update Amplify deployment workflow and add Serverless deployment workflow

* feat: Set environment variables for Amplify monorepo deployment

* feat: Refactor Amplify deployment configuration for monorepo structure

* feat: Update environment variable naming and refactor image URL handling across the application

* feat: Add Jest configuration and tests for project and user handlers
2024-11-27 11:33:41 +02:00

95 lines
2.2 KiB
TypeScript

const mockPut = jest.fn();
import { handler } from "../src/handlers/createProject";
import { v4 as uuidv4 } from "uuid";
jest.mock("@aws-sdk/lib-dynamodb", () => ({
DynamoDBDocument: {
from: jest.fn(() => ({
put: mockPut,
})),
},
}));
jest.mock("uuid", () => ({
v4: jest.fn(),
}));
describe("handler", () => {
afterAll(() => {
jest.restoreAllMocks();
});
it("should create a new project and return 201 response", async () => {
const mockUUID = "mock-uuid";
(uuidv4 as jest.Mock).mockReturnValue(mockUUID);
const event = {
body: JSON.stringify({
name: "Test Project",
description: "This is a test project.",
startDate: "2024-01-01",
endDate: "2024-12-31",
}),
};
mockPut.mockResolvedValue({});
const response = await handler(event);
expect(mockPut).toHaveBeenCalledWith({
TableName: "mock-project-table",
Item: {
category: "projects",
projectId: `project_${mockUUID}`,
name: "Test Project",
description: "This is a test project.",
startDate: "2024-01-01",
endDate: "2024-12-31",
},
});
expect(response).toEqual({
statusCode: 201,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
category: "projects",
projectId: `project_${mockUUID}`,
name: "Test Project",
description: "This is a test project.",
startDate: "2024-01-01",
endDate: "2024-12-31",
}),
});
});
it("should return 500 response on error", async () => {
const event = {
body: JSON.stringify({
name: "Test Project",
description: "This is a test project.",
startDate: "2024-01-01",
endDate: "2024-12-31",
}),
};
const mockError = new Error("DynamoDB error");
mockPut.mockRejectedValue(mockError);
const response = await handler(event);
expect(response).toEqual({
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error creating project: ${mockError.message}`,
}),
});
});
});