Config ci cd #5

Merged
AndrewTrieu merged 6 commits from config-ci-cd into main 2024-11-26 09:37:33 +00:00
31 changed files with 4844 additions and 69 deletions

View File

@@ -0,0 +1,81 @@
name: Set Amplify Environment Variables and Trigger Deployment
permissions:
id-token: write
contents: read
on:
push:
branches:
- main
paths:
- "tasker-client/**"
jobs:
checkout-code:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
install-cli:
runs-on: ubuntu-latest
needs: checkout-code
steps:
- name: Install AWS CLI
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
- name: Verify AWS CLI Installation
run: aws --version
- name: Install Amplify CLI
run: |
npm install -g @aws-amplify/cli
- name: Verify Amplify CLI Installation
run: amplify --version
assume-role:
runs-on: ubuntu-latest
needs: install-cli
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: ${{ secrets.AWS_REGION }}
deploy-amplify:
runs-on: ubuntu-latest
needs: [checkout-code, assume-role, install-cli]
steps:
- name: Fetch API URL from SSM
id: fetch-ssm
run: |
export NEXT_PUBLIC_API_BASE_URL=$(aws ssm get-parameter --name "/tasker/api/base-url" --query "Parameter.Value" --output text)
export NEXT_PUBLIC_COGNITO_USER_POOL_ID=$(aws ssm get-parameter --name "/tasker/cognito/user-pool-id" --query "Parameter.Value" --output text)
export NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID=$(aws ssm get-parameter --name "/tasker/cognito/client-id" --query "Parameter.Value" --output text)
export NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL=$(aws ssm get-parameter --name "/tasker/s3/public-images-url" --query "Parameter.Value" --output text)
echo "NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL" >> $GITHUB_ENV
echo "NEXT_PUBLIC_COGNITO_USER_POOL_ID=$NEXT_PUBLIC_COGNITO_USER_POOL_ID" >> $GITHUB_ENV
echo "NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID=$NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID" >> $GITHUB_ENV
echo "NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL=$NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL" >> $GITHUB_ENV
- name: Set Amplify Environment Variables
run: |
amplify env set NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
amplify env set NEXT_PUBLIC_COGNITO_USER_POOL_ID=$NEXT_PUBLIC_COGNITO_USER_POOL_ID
amplify env set NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID=$NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID
amplify env set NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL=$NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL
- name: Deploy Amplify App
run: |
export AMPLIFY_MONOREPO_APP_ROOT=tasker-client
export AMPLIFY_DIFF_DEPLOY=false
aws amplify start-deployment \
--app-id ${{ secrets.AWS_AMPLIFY_APP_ID }} \
--branch-name main

View File

@@ -0,0 +1,69 @@
name: Deploy with Serverless Framework
permissions:
id-token: write
contents: read
on:
push:
branches:
- main
paths:
- "tasker-server/**"
jobs:
checkout-code:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
install-deps:
runs-on: ubuntu-latest
needs: checkout-code
steps:
- name: Install AWS CLI
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
- name: Verify AWS CLI Installation
run: aws --version
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install Serverless Framework
run: npm install -g serverless
run-tests:
runs-on: ubuntu-latest
needs: install-deps
steps:
- name: Run Tests
run: |
cd tasker-server
npm install
npm test:ci
assume-role:
runs-on: ubuntu-latest
needs: install-deps
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: ${{ secrets.AWS_REGION }}
deploy-serverless:
runs-on: ubuntu-latest
needs: [checkout-code, assume-role, install-deps]
steps:
- name: Deploy Serverless Application
run: |
cd tasker-server
serverless deploy

26
tasker-client/amplify.yml Normal file
View File

@@ -0,0 +1,26 @@
version: 1.0
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- "**/*"
cache:
paths:
- node_modules/**/*
- .next/cache/**/*
- .npm/**/*
env:
variables:
AMPLIFY_MONOREPO_APP_ROOT: tasker-client
AMPLIFY_DIFF_DEPLOY: false
NEXT_PUBLIC_API_BASE_URL: ""
NEXT_PUBLIC_COGNITO_USER_POOL_ID: ""
NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID: ""
NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL: ""

View File

@@ -1,7 +1,17 @@
import type { NextConfig } from "next"; import type { NextConfig } from "next";
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
/* config options here */ images: {
remotePatterns: [
{
protocol: "https",
hostname: new URL(process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL || "")
.hostname,
port: "",
pathname: "/**",
},
],
},
}; };
export default nextConfig; export default nextConfig;

View File

@@ -1,6 +1,11 @@
import Modal from "@/app/components/Modal"; import Modal from "@/app/components/Modal";
import { Priority, Status, useCreateTaskMutation } from "@/state/api"; import {
import React, { useState } from "react"; Priority,
Status,
useCreateTaskMutation,
useGetAuthUserQuery,
} from "@/state/api";
import React, { useEffect, useState } from "react";
import { formatISO } from "date-fns"; import { formatISO } from "date-fns";
type Props = { type Props = {
@@ -22,22 +27,28 @@ const ModalNewTask = ({ isOpen, onClose, id = null }: Props) => {
const [assignedUserId, setAssignedUserId] = useState(""); const [assignedUserId, setAssignedUserId] = useState("");
const [projectId, setProjectId] = useState(""); const [projectId, setProjectId] = useState("");
const { data: currentUser } = useGetAuthUserQuery({});
const userId = currentUser?.userDetails?.userId ?? null;
useEffect(() => {
setAuthorUserId(userId || "");
}, [userId]);
const handleSubmit = async () => { const handleSubmit = async () => {
console.log(title, authorUserId, id, projectId); if (!(title && authorUserId && (id !== null || projectId))) return;
console.log("Creating task 1.."); const finalAssignedUserId = assignedUserId.trim() || authorUserId;
if (
!(title && authorUserId && assignedUserId && (id !== null || projectId))
)
return;
console.log("Creating task 2...");
const formattedStartDate = formatISO(new Date(startDate), { const formattedStartDate =
representation: "complete", startDate ??
}); formatISO(new Date(startDate), {
const formattedDueDate = formatISO(new Date(dueDate), { representation: "complete",
representation: "complete", });
}); const formattedDueDate =
dueDate ??
formatISO(new Date(dueDate), {
representation: "complete",
});
await createTask({ await createTask({
title, title,
@@ -48,16 +59,15 @@ const ModalNewTask = ({ isOpen, onClose, id = null }: Props) => {
startDate: formattedStartDate, startDate: formattedStartDate,
dueDate: formattedDueDate, dueDate: formattedDueDate,
authorUserId: authorUserId, authorUserId: authorUserId,
assignedUserId: assignedUserId, assignedUserId: finalAssignedUserId,
projectId: id !== null ? id : projectId, projectId: id !== null ? id : projectId,
}); });
onClose();
}; };
const isFormValid = () => { const isFormValid = () => {
console.log(title, authorUserId, id, projectId); return title && authorUserId && (id !== null || projectId);
return (
title && authorUserId && assignedUserId && (id !== null || projectId)
);
}; };
const selectStyles = const selectStyles =
@@ -92,9 +102,13 @@ const ModalNewTask = ({ isOpen, onClose, id = null }: Props) => {
<select <select
className={selectStyles} className={selectStyles}
value={status} value={status}
onChange={(e) => onChange={(e) => {
setStatus(Status[e.target.value as keyof typeof Status]) const selectedStatus = Object.entries(Status).find(
} ([, value]) => value === e.target.value,
)?.[0] as keyof typeof Status;
setStatus(selectedStatus ? Status[selectedStatus] : Status.ToDo);
}}
> >
<option value="">Select Status</option> <option value="">Select Status</option>
<option value={Status.ToDo}>To Do</option> <option value={Status.ToDo}>To Do</option>
@@ -139,13 +153,15 @@ const ModalNewTask = ({ isOpen, onClose, id = null }: Props) => {
onChange={(e) => setDueDate(e.target.value)} onChange={(e) => setDueDate(e.target.value)}
/> />
</div> </div>
<input {authorUserId === "" && (
type="text" <input
className={inputStyles} type="text"
placeholder="Author User ID" className={inputStyles}
value={authorUserId} placeholder="Author User ID"
onChange={(e) => setAuthorUserId(e.target.value)} value={authorUserId}
/> onChange={(e) => setAuthorUserId(e.target.value)}
/>
)}
<input <input
type="text" type="text"
className={inputStyles} className={inputStyles}

View File

@@ -77,7 +77,7 @@ const Navbar = () => {
<div className="align-center flex h-9 w-9 justify-center"> <div className="align-center flex h-9 w-9 justify-center">
{!!currentUserDetails?.profilePictureUrl ? ( {!!currentUserDetails?.profilePictureUrl ? (
<Image <Image
src={`${process.env.S3_PUBLIC_IMAGE_URL}/${currentUserDetails?.profilePictureUrl}`} src={`${process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL}/${currentUserDetails?.profilePictureUrl}`}
alt={currentUserDetails?.username || "User Profile Picture"} alt={currentUserDetails?.username || "User Profile Picture"}
width={100} width={100}
height={50} height={50}

View File

@@ -71,7 +71,7 @@ const Sidebar = () => {
</div> </div>
<div className="flex items-center gap-5 border-y-[1.5px] border-gray-200 px-8 py-4 dark:border-gray-700"> <div className="flex items-center gap-5 border-y-[1.5px] border-gray-200 px-8 py-4 dark:border-gray-700">
<Image <Image
src={`${process.env.S3_PUBLIC_IMAGE_URL}/logo.png`} src={`${process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL}/logo.png`}
alt="logo" alt="logo"
width={40} width={40}
height={40} height={40}
@@ -162,7 +162,7 @@ const Sidebar = () => {
<div className="align-center flex h-9 w-9 justify-center"> <div className="align-center flex h-9 w-9 justify-center">
{!!currentUserDetails?.profilePictureUrl ? ( {!!currentUserDetails?.profilePictureUrl ? (
<Image <Image
src={`${process.env.S3_PUBLIC_IMAGE_URL}/${currentUserDetails?.profilePictureUrl}`} src={`${process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL}/${currentUserDetails?.profilePictureUrl}`}
alt={currentUserDetails?.username || "User Profile Picture"} alt={currentUserDetails?.username || "User Profile Picture"}
width={100} width={100}
height={50} height={50}

View File

@@ -16,7 +16,7 @@ const TaskCard = ({ task }: Props) => {
<div className="flex flex-wrap"> <div className="flex flex-wrap">
{task.attachments && task.attachments.length > 0 && ( {task.attachments && task.attachments.length > 0 && (
<Image <Image
src={`${process.env.S3_PUBLIC_IMAGE_URL}/${task.attachments[0].fileURL}`} src={`${process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL}/${task.attachments[0].fileURL}`}
alt={task.attachments[0].fileName} alt={task.attachments[0].fileName}
width={400} width={400}
height={200} height={200}

View File

@@ -11,7 +11,7 @@ const UserCard = ({ user }: Props) => {
<div className="flex items-center rounded border p-4 shadow"> <div className="flex items-center rounded border p-4 shadow">
{user.profilePictureUrl && ( {user.profilePictureUrl && (
<Image <Image
src={`${process.env.S3_PUBLIC_IMAGE_URL}/${user.profilePictureUrl}`} src={`${process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL}/${user.profilePictureUrl}`}
alt="profile picture" alt="profile picture"
width={32} width={32}
height={32} height={32}

View File

@@ -24,6 +24,7 @@ const BoardView = ({ projectId, setIsModalNewTaskOpen }: BoardProps) => {
data: fetchedTasks, data: fetchedTasks,
isLoading, isLoading,
error, error,
refetch,
} = useGetTasksQuery({ projectId }); } = useGetTasksQuery({ projectId });
const [updateTaskStatus] = useUpdateTaskStatusMutation(); const [updateTaskStatus] = useUpdateTaskStatusMutation();
const [tasks, setTasks] = useState<TaskType[]>([]); const [tasks, setTasks] = useState<TaskType[]>([]);
@@ -43,6 +44,7 @@ const BoardView = ({ projectId, setIsModalNewTaskOpen }: BoardProps) => {
try { try {
await updateTaskStatus({ taskId, status: toStatus }); await updateTaskStatus({ taskId, status: toStatus });
await refetch();
} catch (error) { } catch (error) {
console.error("Failed to update task status:", error); console.error("Failed to update task status:", error);
setTasks(fetchedTasks || []); setTasks(fetchedTasks || []);
@@ -197,7 +199,7 @@ const Task = ({ task }: TaskProps) => {
> >
{task.attachments && task.attachments.length > 0 && ( {task.attachments && task.attachments.length > 0 && (
<Image <Image
src={`${process.env.S3_PUBLIC_IMAGE_URL}/${task.attachments[0].fileURL}`} src={`${process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL}/${task.attachments[0].fileURL}`}
alt={task.attachments[0].fileName} alt={task.attachments[0].fileName}
width={400} width={400}
height={200} height={200}
@@ -248,8 +250,8 @@ const Task = ({ task }: TaskProps) => {
<div className="flex -space-x-[6px] overflow-hidden"> <div className="flex -space-x-[6px] overflow-hidden">
{task.assignee && ( {task.assignee && (
<Image <Image
key={task.assignee.userId} key={`assignee#${task.assignee.userId}`}
src={`${process.env.S3_PUBLIC_IMAGE_URL}/${task.assignee.profilePictureUrl!}`} src={`${process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL}/${task.assignee.profilePictureUrl!}`}
alt={task.assignee.username} alt={task.assignee.username}
width={30} width={30}
height={30} height={30}
@@ -258,8 +260,8 @@ const Task = ({ task }: TaskProps) => {
)} )}
{task.author && ( {task.author && (
<Image <Image
key={task.author.userId} key={`author#${task.author.userId}`}
src={`${process.env.S3_PUBLIC_IMAGE_URL}/${task.author.profilePictureUrl!}`} src={`${process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL}/${task.author.profilePictureUrl!}`}
alt={task.author.username} alt={task.author.username}
width={30} width={30}
height={30} height={30}

View File

@@ -21,16 +21,19 @@ const Timeline = ({ projectId, setIsModalNewTaskOpen }: Props) => {
}); });
const ganttTasks = useMemo(() => { const ganttTasks = useMemo(() => {
if (!tasks || tasks.length === 0) return [];
return ( return (
tasks?.map((task) => ({ tasks
start: new Date(task.startDate as string), ?.filter((task) => task.startDate && task.dueDate)
end: new Date(task.dueDate as string), .map((task) => ({
name: task.title, start: new Date(task.startDate as string),
id: `Task-${task.taskId}`, end: new Date(task.dueDate as string),
type: "task" as TaskTypeItems, name: task.title,
progress: task.points ? (task.points / 10) * 100 : 0, id: `Task-${task.taskId}`,
isDisabled: false, type: "task" as TaskTypeItems,
})) || [] progress: task.points ? (task.points / 10) * 100 : 0,
isDisabled: false,
})) || []
); );
}, [tasks]); }, [tasks]);
@@ -66,16 +69,20 @@ const Timeline = ({ projectId, setIsModalNewTaskOpen }: Props) => {
</div> </div>
<div className="overflow-hidden rounded-md bg-white shadow dark:bg-dark-secondary dark:text-white"> <div className="overflow-hidden rounded-md bg-white shadow dark:bg-dark-secondary dark:text-white">
<div className="timeline"> {ganttTasks.length > 0 && (
<Gantt <div className="timeline">
tasks={ganttTasks} <Gantt
{...displayOptions} tasks={ganttTasks}
columnWidth={displayOptions.viewMode === ViewMode.Month ? 150 : 100} {...displayOptions}
listCellWidth="100px" columnWidth={
barBackgroundColor={isDarkMode ? "#101214" : "#aeb8c2"} displayOptions.viewMode === ViewMode.Month ? 150 : 100
barBackgroundSelectedColor={isDarkMode ? "#000" : "#9ba1a6"} }
/> listCellWidth="100px"
</div> barBackgroundColor={isDarkMode ? "#101214" : "#aeb8c2"}
barBackgroundSelectedColor={isDarkMode ? "#000" : "#9ba1a6"}
/>
</div>
)}
<div className="px-4 pb-5 pt-1"> <div className="px-4 pb-5 pt-1">
<button <button
className="flex items-center rounded bg-blue-primary px-3 py-2 text-white hover:bg-blue-600" className="flex items-center rounded bg-blue-primary px-3 py-2 text-white hover:bg-blue-600"

View File

@@ -31,7 +31,7 @@ const columns: GridColDef[] = [
<div className="flex h-full w-full items-center justify-center"> <div className="flex h-full w-full items-center justify-center">
<div className="h-9 w-9"> <div className="h-9 w-9">
<Image <Image
src={`${process.env.S3_PUBLIC_IMAGE_URL}/${params.value}`} src={`${process.env.NEXT_PUBLIC_S3_PUBLIC_IMAGE_URL}/${params.value}`}
alt={params.row.username} alt={params.row.username}
width={100} width={100}
height={50} height={50}

View File

@@ -0,0 +1,13 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"setupFiles": ["<rootDir>/jest.env.js"],
"moduleFileExtensions": ["ts", "js"],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testMatch": ["**/tests/**/*.test.ts"],
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
}
}

View File

@@ -0,0 +1,6 @@
process.env.SLS_REGION = "mock-region";
process.env.TASKER_TASK_TABLE_NAME = "mock-task-table";
process.env.TASKER_PROJECT_TABLE_NAME = "mock-project-table";
process.env.TASKER_USER_TABLE_NAME = "mock-user-table";
process.env.TASKER_TASK_EXTRA_TABLE_NAME = "mock-task-extra-table";
process.env.TASKER_TEAM_TABLE_NAME = "mock-team-table";

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,9 @@
"infra:destroy": "cd terraform && AWS_PROFILE=default terraform destroy", "infra:destroy": "cd terraform && AWS_PROFILE=default terraform destroy",
"sls:package": "AWS_PROFILE=default sls package", "sls:package": "AWS_PROFILE=default sls package",
"sls:deploy": "AWS_PROFILE=default sls deploy", "sls:deploy": "AWS_PROFILE=default sls deploy",
"sls:remove": "AWS_PROFILE=default sls remove" "sls:remove": "AWS_PROFILE=default sls remove",
"test": "jes --coverage",
"test:ci": "jest --no-coverage --ci"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
@@ -22,10 +24,13 @@
"uuid": "^11.0.3" "uuid": "^11.0.3"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.9.1", "@types/node": "^22.9.1",
"eslint": "^9.15.0", "eslint": "^9.15.0",
"jest": "^29.7.0",
"prettier": "^3.3.3", "prettier": "^3.3.3",
"serverless-prune-plugin": "^2.1.0", "serverless-prune-plugin": "^2.1.0",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3" "typescript": "^5.6.3"
} }
} }

View File

@@ -1174,7 +1174,7 @@ export const handler = async () => {
console.info(`Data population for table ${tableName} complete.`); console.info(`Data population for table ${tableName} complete.`);
} }
console.log("Data population complete."); console.info("Data population complete.");
} catch (error) { } catch (error) {
console.error("Failed to populate data:", error); console.error("Failed to populate data:", error);
} }

View File

@@ -10,7 +10,6 @@ provider:
runtime: nodejs20.x runtime: nodejs20.x
environment: environment:
SLS_REGION: ${self:provider.region} SLS_REGION: ${self:provider.region}
API_BASE_URL: ${ssm:/tasker/api/base-url}
TASKER_TASK_TABLE_NAME: ${ssm:/tasker/dynamodb/task-table-name} TASKER_TASK_TABLE_NAME: ${ssm:/tasker/dynamodb/task-table-name}
TASKER_PROJECT_TABLE_NAME: ${ssm:/tasker/dynamodb/project-table-name} TASKER_PROJECT_TABLE_NAME: ${ssm:/tasker/dynamodb/project-table-name}
TASKER_USER_TABLE_NAME: ${ssm:/tasker/dynamodb/user-table-name} TASKER_USER_TABLE_NAME: ${ssm:/tasker/dynamodb/user-table-name}

View File

@@ -10,10 +10,9 @@ const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client); const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => { export const handler = async (event: any): Promise<any> => {
console.info(`Event: ${JSON.stringify(event)}`);
const username = const username =
event.request.userAttributes["preferred_username"] || event.userName; event.request.userAttributes["preferred_username"] || event.userName;
const cognitoId = event.userName; const cognitoId = event.request.userAttributes["sub"];
const teamId = await fetchRandomTeamId(); const teamId = await fetchRandomTeamId();
try { try {

View File

@@ -17,13 +17,17 @@ export const handler = async (event: any): Promise<any> => {
const userTasks = [...authorTasks, ...assigneeTasks]; const userTasks = [...authorTasks, ...assigneeTasks];
const uniqueTasks = Array.from(
new Map(userTasks.map((task) => [task.taskId, task])).values()
);
return { return {
statusCode: 200, statusCode: 200,
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Access-Control-Allow-Origin": "*", "Access-Control-Allow-Origin": "*",
}, },
body: JSON.stringify(userTasks), body: JSON.stringify(uniqueTasks),
}; };
} catch (error: any) { } catch (error: any) {
return { return {

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}`,
}),
});
});
});

View File

@@ -0,0 +1,122 @@
const mockPut = jest.fn();
import { handler } from "../src/handlers/createTask";
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("createTask handler", () => {
afterAll(() => {
jest.restoreAllMocks();
});
it("should create a new task and return 201 response", async () => {
const mockUUID = "mock-uuid";
(uuidv4 as jest.Mock).mockReturnValue(mockUUID);
const event = {
body: JSON.stringify({
title: "Test Task",
description: "This is a test task.",
status: "In Progress",
priority: "High",
tags: ["test", "jest"],
startDate: "2024-01-01",
dueDate: "2024-01-15",
points: 5,
projectId: "project_12345",
authorUserId: "user_abc",
assignedUserId: "user_xyz",
}),
};
mockPut.mockResolvedValue({});
const response = await handler(event);
expect(mockPut).toHaveBeenCalledWith({
TableName: "mock-task-table",
Item: {
category: "tasks",
taskId: `task_${mockUUID}`,
title: "Test Task",
description: "This is a test task.",
status: "In Progress",
priority: "High",
tags: ["test", "jest"],
startDate: "2024-01-01",
dueDate: "2024-01-15",
points: 5,
projectId: "project_12345",
authorUserId: "user_abc",
assignedUserId: "user_xyz",
},
});
expect(response).toEqual({
statusCode: 201,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
category: "tasks",
taskId: `task_${mockUUID}`,
title: "Test Task",
description: "This is a test task.",
status: "In Progress",
priority: "High",
tags: ["test", "jest"],
startDate: "2024-01-01",
dueDate: "2024-01-15",
points: 5,
projectId: "project_12345",
authorUserId: "user_abc",
assignedUserId: "user_xyz",
}),
});
});
it("should return 500 response on error", async () => {
const event = {
body: JSON.stringify({
title: "Test Task",
description: "This is a test task.",
status: "In Progress",
priority: "High",
tags: ["test", "jest"],
startDate: "2024-01-01",
dueDate: "2024-01-15",
points: 5,
projectId: "project_12345",
authorUserId: "user_abc",
assignedUserId: "user_xyz",
}),
};
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 task: ${mockError.message}`,
}),
});
});
});

View File

@@ -0,0 +1,104 @@
const mockPut = jest.fn();
import { handler } from "../src/handlers/createUser";
import { v4 as uuidv4 } from "uuid";
import { fetchRandomTeamId } from "@/lib/util";
jest.mock("@aws-sdk/lib-dynamodb", () => ({
DynamoDBDocument: {
from: jest.fn(() => ({
put: mockPut,
})),
},
}));
jest.mock("uuid", () => ({
v4: jest.fn(),
}));
jest.mock("@/lib/util", () => ({
fetchRandomTeamId: jest.fn(),
}));
describe("createUser handler", () => {
beforeAll(() => {
jest.spyOn(console, "info").mockImplementation(jest.fn());
});
afterAll(() => {
jest.restoreAllMocks();
});
it("should create a new user and log a success message", async () => {
const mockUUID = "mock-uuid";
const mockTeamId = "team-123";
(uuidv4 as jest.Mock).mockReturnValue(mockUUID);
(fetchRandomTeamId as jest.Mock).mockResolvedValue(mockTeamId);
const event = {
request: {
userAttributes: {
preferred_username: "testUser",
sub: "cognito-123",
},
},
userName: "fallbackUser",
};
mockPut.mockResolvedValue({});
const response = await handler(event);
expect(fetchRandomTeamId).toHaveBeenCalled();
expect(mockPut).toHaveBeenCalledWith({
TableName: "mock-user-table",
Item: {
category: "users",
cognitoId: "cognito-123",
userId: `user_${mockUUID}`,
username: "testUser",
profilePictureUrl: "p0.jpeg",
teamId: mockTeamId,
},
});
expect(response).toEqual(event);
});
it("should throw an error if DynamoDB operation fails", async () => {
const mockUUID = "mock-uuid";
const mockTeamId = "team-123";
(uuidv4 as jest.Mock).mockReturnValue(mockUUID);
(fetchRandomTeamId as jest.Mock).mockResolvedValue(mockTeamId);
const event = {
request: {
userAttributes: {
preferred_username: "testUser",
sub: "cognito-123",
},
},
userName: "fallbackUser",
};
const mockError = new Error("DynamoDB error");
mockPut.mockRejectedValue(mockError);
await expect(handler(event)).rejects.toThrow(
"Error creating user: DynamoDB error"
);
expect(fetchRandomTeamId).toHaveBeenCalled();
expect(mockPut).toHaveBeenCalledWith({
TableName: "mock-user-table",
Item: {
category: "users",
cognitoId: "cognito-123",
userId: `user_${mockUUID}`,
username: "testUser",
profilePictureUrl: "p0.jpeg",
teamId: mockTeamId,
},
});
});
});

View File

@@ -0,0 +1,73 @@
const mockQuery = jest.fn();
import { handler } from "../src/handlers/getProjects";
jest.mock("@aws-sdk/lib-dynamodb", () => ({
DynamoDBDocument: {
from: jest.fn(() => ({
query: mockQuery,
})),
},
}));
describe("getProjects handler", () => {
afterAll(() => {
jest.restoreAllMocks();
});
it("should retrieve projects and return a 200 response", async () => {
const mockProjects = [
{ projectId: "project_1", name: "Project 1" },
{ projectId: "project_2", name: "Project 2" },
];
mockQuery.mockResolvedValue({
Items: mockProjects,
});
const response = await handler({});
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-project-table",
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "projects",
},
});
expect(response).toEqual({
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(mockProjects),
});
});
it("should return a 500 response if the query fails", async () => {
const mockError = new Error("DynamoDB query error");
mockQuery.mockRejectedValue(mockError);
const response = await handler({});
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-project-table",
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "projects",
},
});
expect(response).toEqual({
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving projects: ${mockError.message}`,
}),
});
});
});

View File

@@ -0,0 +1,131 @@
const mockQuery = jest.fn();
const mockFetchUserWithUserId = jest.fn();
const mockFetchComments = jest.fn();
const mockFetchAttachments = jest.fn();
import { handler } from "../src/handlers/getTasks";
jest.mock("@aws-sdk/lib-dynamodb", () => ({
DynamoDBDocument: {
from: jest.fn(() => ({
query: mockQuery,
})),
},
}));
jest.mock("@/lib/util", () => ({
fetchUserWithUserId: mockFetchUserWithUserId,
fetchComments: mockFetchComments,
fetchAttachments: mockFetchAttachments,
}));
describe("getTasks handler", () => {
afterAll(() => {
jest.restoreAllMocks();
});
it("should retrieve tasks with details and return a 200 response", async () => {
const mockTasks = [
{
taskId: "task_1",
title: "Task 1",
authorUserId: "user_1",
assignedUserId: "user_2",
},
{
taskId: "task_2",
title: "Task 2",
},
];
const mockAuthor = { userId: "user_1", username: "AuthorUser" };
const mockAssignee = { userId: "user_2", username: "AssigneeUser" };
const mockComments = [{ commentId: "comment_1", content: "Nice work!" }];
const mockAttachments = [
{ attachmentId: "attachment_1", name: "file.pdf" },
];
mockQuery.mockResolvedValue({ Items: mockTasks });
mockFetchUserWithUserId.mockResolvedValueOnce(mockAuthor);
mockFetchUserWithUserId.mockResolvedValueOnce(mockAssignee);
mockFetchComments.mockResolvedValue(mockComments);
mockFetchAttachments.mockResolvedValue(mockAttachments);
const event = {
queryStringParameters: { projectId: "project_123" },
};
const response = await handler(event);
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-task-table",
KeyConditionExpression: "category = :category AND projectId = :projectId",
IndexName: "GSI-project-id",
ExpressionAttributeValues: {
":category": "tasks",
":projectId": "project_123",
},
});
expect(response).toEqual({
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify([
{
taskId: "task_1",
title: "Task 1",
authorUserId: "user_1",
assignedUserId: "user_2",
author: mockAuthor,
assignee: mockAssignee,
comments: mockComments,
attachments: mockAttachments,
},
{
taskId: "task_2",
title: "Task 2",
author: null,
assignee: null,
comments: mockComments,
attachments: mockAttachments,
},
]),
});
});
it("should return a 500 response if there is an error", async () => {
const mockError = new Error("DynamoDB query error");
mockQuery.mockRejectedValue(mockError);
const event = {
queryStringParameters: { projectId: "project_123" },
};
const response = await handler(event);
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-task-table",
KeyConditionExpression: "category = :category AND projectId = :projectId",
IndexName: "GSI-project-id",
ExpressionAttributeValues: {
":category": "tasks",
":projectId": "project_123",
},
});
expect(response).toEqual({
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving tasks: ${mockError.message}`,
}),
});
});
});

View File

@@ -0,0 +1,113 @@
const mockQuery = jest.fn();
const mockFetchUserWithUserId = jest.fn();
import { handler } from "../src/handlers/getTeams";
jest.mock("@aws-sdk/lib-dynamodb", () => ({
DynamoDBDocument: {
from: jest.fn(() => ({
query: mockQuery,
})),
},
}));
jest.mock("@/lib/util", () => ({
fetchUserWithUserId: mockFetchUserWithUserId,
}));
describe("getTeams handler", () => {
afterAll(() => {
jest.restoreAllMocks();
});
it("should retrieve teams with usernames and return a 200 response", async () => {
const mockTeams = [
{
teamId: "team_1",
name: "Team A",
productOwnerUserId: "user_1",
projectManagerUserId: "user_2",
},
{
teamId: "team_2",
name: "Team B",
productOwnerUserId: "user_3",
},
];
const mockProductOwner1 = { userId: "user_1", username: "POUser1" };
const mockProjectManager1 = { userId: "user_2", username: "PMUser2" };
const mockProductOwner2 = { userId: "user_3", username: "POUser3" };
mockQuery.mockResolvedValue({ Items: mockTeams });
mockFetchUserWithUserId.mockImplementation((userId) => {
if (userId === "user_1") return Promise.resolve(mockProductOwner1);
if (userId === "user_2") return Promise.resolve(mockProjectManager1);
if (userId === "user_3") return Promise.resolve(mockProductOwner2);
return Promise.resolve(null);
});
const response = await handler({});
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-team-table",
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "teams",
},
});
expect(response).toEqual({
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify([
{
teamId: "team_1",
name: "Team A",
productOwnerUserId: "user_1",
projectManagerUserId: "user_2",
productOwnerUsername: "POUser1",
projectManagerUsername: "PMUser2",
},
{
teamId: "team_2",
name: "Team B",
productOwnerUserId: "user_3",
projectManagerUserId: undefined,
productOwnerUsername: "POUser3",
projectManagerUsername: null,
},
]),
});
});
it("should return a 500 response if there is an error", async () => {
const mockError = new Error("DynamoDB query error");
mockQuery.mockRejectedValue(mockError);
const response = await handler({});
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-team-table",
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "teams",
},
});
expect(response).toEqual({
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving teams: ${mockError.message}`,
}),
});
});
});

View File

@@ -0,0 +1,115 @@
const mockQuery = jest.fn();
import { handler } from "../src/handlers/getUser";
jest.mock("@aws-sdk/lib-dynamodb", () => ({
DynamoDBDocument: {
from: jest.fn(() => ({
query: mockQuery,
})),
},
}));
describe("getUser handler", () => {
afterAll(() => {
jest.restoreAllMocks();
});
it("should retrieve a user and return a 200 response", async () => {
const mockUser = {
cognitoId: "cognito_123",
userId: "user_1",
username: "TestUser",
category: "users",
};
mockQuery.mockResolvedValue({
Items: [mockUser],
});
const event = {
pathParameters: { cognitoId: "cognito_123" },
};
const response = await handler(event);
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-user-table",
KeyConditionExpression: "category = :category AND cognitoId = :cognitoId",
ExpressionAttributeValues: {
":category": "users",
":cognitoId": "cognito_123",
},
});
expect(response).toEqual({
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(mockUser),
});
});
it("should return an empty object if no user is found", async () => {
mockQuery.mockResolvedValue({
Items: [],
});
const event = {
pathParameters: { cognitoId: "cognito_456" },
};
const response = await handler(event);
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-user-table",
KeyConditionExpression: "category = :category AND cognitoId = :cognitoId",
ExpressionAttributeValues: {
":category": "users",
":cognitoId": "cognito_456",
},
});
expect(response).toEqual({
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({}),
});
});
it("should return a 500 response if there is an error", async () => {
const mockError = new Error("DynamoDB query error");
mockQuery.mockRejectedValue(mockError);
const event = {
pathParameters: { cognitoId: "cognito_123" },
};
const response = await handler(event);
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-user-table",
KeyConditionExpression: "category = :category AND cognitoId = :cognitoId",
ExpressionAttributeValues: {
":category": "users",
":cognitoId": "cognito_123",
},
});
expect(response).toEqual({
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving user: ${mockError.message}`,
}),
});
});
});

View File

@@ -0,0 +1,120 @@
const mockQueryTasks = jest.fn();
import { handler } from "../src/handlers/getUserTasks";
import { queryTasks } from "@/lib/util";
jest.mock("@/lib/util", () => ({
queryTasks: mockQueryTasks,
}));
describe("getUserTasks handler", () => {
afterAll(() => {
jest.restoreAllMocks();
});
it("should retrieve tasks authored and assigned to the user and return a 200 response", async () => {
const mockAuthorTasks = [
{ taskId: "task_1", title: "Authored Task 1" },
{ taskId: "task_2", title: "Authored Task 2" },
];
const mockAssigneeTasks = [
{ taskId: "task_2", title: "Authored Task 2" }, // Duplicate task
{ taskId: "task_3", title: "Assigned Task 3" },
];
const mockUniqueTasks = [
{ taskId: "task_1", title: "Authored Task 1" },
{ taskId: "task_2", title: "Authored Task 2" },
{ taskId: "task_3", title: "Assigned Task 3" },
];
mockQueryTasks
.mockResolvedValueOnce(mockAuthorTasks)
.mockResolvedValueOnce(mockAssigneeTasks);
const event = {
pathParameters: { userId: "user_123" },
};
const response = await handler(event);
expect(queryTasks).toHaveBeenCalledWith(
"user_123",
"GSI-author-user-id",
"authorUserId"
);
expect(queryTasks).toHaveBeenCalledWith(
"user_123",
"GSI-assigned-user-id",
"assignedUserId"
);
expect(response).toEqual({
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(mockUniqueTasks),
});
});
it("should return a 500 response if queryTasks fails", async () => {
const mockError = new Error("Query failed");
mockQueryTasks.mockRejectedValueOnce(mockError);
const event = {
pathParameters: { userId: "user_123" },
};
const response = await handler(event);
expect(queryTasks).toHaveBeenCalledWith(
"user_123",
"GSI-author-user-id",
"authorUserId"
);
expect(response).toEqual({
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving tasks for user: ${mockError.message}`,
}),
});
});
it("should handle empty author and assignee tasks gracefully", async () => {
mockQueryTasks.mockResolvedValueOnce([]).mockResolvedValueOnce([]);
const event = {
pathParameters: { userId: "user_123" },
};
const response = await handler(event);
expect(queryTasks).toHaveBeenCalledWith(
"user_123",
"GSI-author-user-id",
"authorUserId"
);
expect(queryTasks).toHaveBeenCalledWith(
"user_123",
"GSI-assigned-user-id",
"assignedUserId"
);
expect(response).toEqual({
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify([]),
});
});
});

View File

@@ -0,0 +1,98 @@
const mockQuery = jest.fn();
import { handler } from "../src/handlers/getUsers";
jest.mock("@aws-sdk/lib-dynamodb", () => ({
DynamoDBDocument: {
from: jest.fn(() => ({
query: mockQuery,
})),
},
}));
describe("getUsers handler", () => {
afterAll(() => {
jest.restoreAllMocks();
});
it("should retrieve all users and return a 200 response", async () => {
const mockUsers = [
{ userId: "user_1", username: "User1", category: "users" },
{ userId: "user_2", username: "User2", category: "users" },
];
mockQuery.mockResolvedValue({
Items: mockUsers,
});
const response = await handler({});
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-user-table",
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "users",
},
});
expect(response).toEqual({
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(mockUsers),
});
});
it("should return an empty array if no users are found", async () => {
mockQuery.mockResolvedValue({
Items: [],
});
const response = await handler({});
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-user-table",
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "users",
},
});
expect(response).toEqual({
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify([]),
});
});
it("should return a 500 response if there is an error", async () => {
const mockError = new Error("DynamoDB query error");
mockQuery.mockRejectedValue(mockError);
const response = await handler({});
expect(mockQuery).toHaveBeenCalledWith({
TableName: "mock-user-table",
KeyConditionExpression: "category = :category",
ExpressionAttributeValues: {
":category": "users",
},
});
expect(response).toEqual({
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error retrieving users: ${mockError.message}`,
}),
});
});
});

View File

@@ -0,0 +1,120 @@
const mockUpdate = jest.fn();
import { handler } from "../src/handlers/updateTaskStatus"; // Adjust the path as needed
jest.mock("@aws-sdk/lib-dynamodb", () => ({
DynamoDBDocument: {
from: jest.fn(() => ({
update: mockUpdate,
})),
},
}));
describe("updateTaskStatus handler", () => {
afterAll(() => {
jest.restoreAllMocks();
});
it("should update the task status and return the updated task", async () => {
const mockUpdatedTask = {
category: "tasks",
taskId: "task_123",
status: "Completed",
};
mockUpdate.mockResolvedValue({
Attributes: mockUpdatedTask,
});
const event = {
pathParameters: { taskId: "task_123" },
body: JSON.stringify({ status: "Completed" }),
};
const response = await handler(event);
expect(mockUpdate).toHaveBeenCalledWith({
TableName: "mock-task-table",
Key: {
category: "tasks",
taskId: "task_123",
},
UpdateExpression: "set #status = :status",
ExpressionAttributeNames: {
"#status": "status",
},
ExpressionAttributeValues: {
":status": "Completed",
},
ReturnValues: "ALL_NEW",
});
expect(response).toEqual({
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(mockUpdatedTask),
});
});
it("should return a 500 response if the update fails", async () => {
const mockError = new Error("DynamoDB update error");
mockUpdate.mockRejectedValue(mockError);
const event = {
pathParameters: { taskId: "task_123" },
body: JSON.stringify({ status: "Completed" }),
};
const response = await handler(event);
expect(mockUpdate).toHaveBeenCalledWith({
TableName: "mock-task-table",
Key: {
category: "tasks",
taskId: "task_123",
},
UpdateExpression: "set #status = :status",
ExpressionAttributeNames: {
"#status": "status",
},
ExpressionAttributeValues: {
":status": "Completed",
},
ReturnValues: "ALL_NEW",
});
expect(response).toEqual({
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error updating task: ${mockError.message}`,
}),
});
});
it("should handle invalid input gracefully", async () => {
const event = {
pathParameters: { taskId: "task_123" },
body: JSON.stringify({}),
};
const response = await handler(event);
expect(response).toEqual({
statusCode: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: `Error updating task: DynamoDB update error`,
}),
});
});
});

View File

@@ -22,6 +22,6 @@
"@/*": ["./src/*"] "@/*": ["./src/*"]
} }
}, },
"include": ["**/*.ts", "**/*.tsx"], "include": ["**/*.ts", "**/*.tsx", "jest.config.js"],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }