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
This commit is contained in:
2024-11-26 16:37:33 +07:00
parent 11e61829f1
commit e293ab3c2c
31 changed files with 4864 additions and 75 deletions

View File

@@ -0,0 +1,94 @@
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}`,
}),
});
});
});