Skip to content

Commit

Permalink
feat(test): added userFile unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cephaschapa committed Jan 19, 2024
1 parent 35c7612 commit 042bc68
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 25 deletions.
93 changes: 76 additions & 17 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@storybook/react": "^7.4.5",
"@storybook/testing-library": "^0.2.2",
"@types/bcrypt": "^5.0.1",
"@types/form-data": "^2.5.0",
"@types/http-errors": "^2.0.4",
"@types/js-cookie": "^3.0.6",
"@types/jsonwebtoken": "^9.0.4",
Expand All @@ -54,7 +55,10 @@
"eslint": "8.52.0",
"eslint-config-next": "13.4.16",
"eslint-plugin-storybook": "^0.6.13",
"fetch-blob": "^4.0.0",
"fetch-mock": "^9.11.0",
"form-data": "^4.0.0",
"formdata-node": "^6.0.3",
"framer-motion": "^10.16.2",
"http-errors": "^2.0.0",
"i18next": "^23.4.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ export const GET = apiHandler(
_req: Request,
context: { session?: Session; params: Record<string, string> },
) => {
const userId = context.params.user;
if (!context.session) {
throw new createHttpError.Unauthorized("Unauthorized");
}

const user = await db.models.User.findOne({
attributes: ["userId"],
where: {
userId: context.session.user.id,
userId: userId,
},
});
if (!user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ export const GET = apiHandler(
_req: Request,
context: { session?: Session; params: Record<string, string> },
) => {
const userId = context.params.user;
if (!context.session) {
throw new createHttpError.Unauthorized("Unauthorized");
}

const user = await db.models.User.findOne({
attributes: ["userId"],
where: {
userId: context.session.user.id,
userId: userId,
},
});
if (!user) {
Expand All @@ -42,14 +43,15 @@ export const DELETE = apiHandler(
_req: Request,
context: { session?: Session; params: Record<string, string> },
) => {
const userId = context.params.user;
if (!context.session) {
throw new createHttpError.Unauthorized("Unauthorized");
}

const user = await db.models.User.findOne({
attributes: ["userId"],
where: {
userId: context.session.user.id,
userId: userId,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ export const GET = apiHandler(
_req: Request,
context: { session?: Session; params: Record<string, string> },
) => {
const userId = context.params.user;
if (!context.session) {
throw new createHttpError.Unauthorized("Unauthorized");
}

const user = await db.models.User.findOne({
attributes: ["userId"],
where: {
userId: context.session.user.id,
userId: userId,
},
});
if (!user) {
Expand All @@ -63,15 +64,16 @@ export const POST = apiHandler(
req: NextRequest,
context: { session?: Session; params: Record<string, string> },
) => {
const authorizedUser = context.session?.user;
const userId = context.params.user;

if (!context.session) {
throw new createHttpError.Unauthorized("Unauthorized");
}

const user = await db.models.User.findOne({
attributes: ["userId"],
where: {
userId: authorizedUser?.id,
userId: userId,
},
});

Expand Down Expand Up @@ -103,8 +105,6 @@ export const POST = apiHandler(
gpc_ref_no: formData.get("gpc_ref_no"),
};

console.log(fileType);

const body = createUserFileRequset.parse(fileData);

const userFile = await db.models.UserFile.create({
Expand Down
Loading

0 comments on commit 042bc68

Please sign in to comment.