Skip to content

Commit

Permalink
테스트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tirr-c committed Sep 28, 2023
1 parent 7022ad7 commit 007f374
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/api/handlers/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function listMembers(model: Model): IMiddleware {
}

if (!owner) {
ctx.status = 401;
ctx.status = 403;
return;
}

Expand Down Expand Up @@ -108,7 +108,7 @@ export function listPending(model: Model): IMiddleware {
}

if (!owner) {
ctx.status = 401;
ctx.status = 403;
return;
}

Expand Down Expand Up @@ -180,7 +180,7 @@ export function acceptGroup(model: Model): IMiddleware {

const owner = await model.groups.checkOwner(tr, group.idx, ctx.state.userIdx);
if (!owner) {
ctx.status = 401;
ctx.status = 403;
return;
}

Expand Down Expand Up @@ -224,7 +224,7 @@ export function rejectGroup(model: Model): IMiddleware {

const owner = await model.groups.checkOwner(tr, group.idx, ctx.state.userIdx);
if (!owner) {
ctx.status = 401;
ctx.status = 403;
return;
}

Expand Down
38 changes: 19 additions & 19 deletions test/api/groups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ test('pending listing', async t => {
t.is(response.status, 200);

response = await agent.get(`/api/group/${groupIdx}/pending`);
t.is(response.status, 401);
t.is(response.status, 403);

await model.pgDo(async tr => {
await model.users.addUserMembership(tr, userIdx, groupIdx);
Expand Down Expand Up @@ -236,6 +236,13 @@ test('accept group requests', async t => {
let response;

response = await agent.post(`/api/group/${groupIdx}/accept`).send([]);
t.is(response.status, 400);

await model.pgDo(async tr => {
await model.users.addPendingUserMembership(tr, memberIdx, groupIdx);
});

response = await agent.post(`/api/group/${groupIdx}/accept`).send([memberIdx]);
t.is(response.status, 401);

response = await agent.post('/api/login').send({
Expand All @@ -244,20 +251,13 @@ test('accept group requests', async t => {
});
t.is(response.status, 200);

response = await agent.post(`/api/group/${groupIdx}/accept`).send([]);
t.is(response.status, 401);
response = await agent.post(`/api/group/${groupIdx}/accept`).send([memberIdx]);
t.is(response.status, 403);

await model.pgDo(async tr => {
await model.groups.setOwnerGroup(tr, groupIdx, ownerGroupIdx);
});

response = await agent.post(`/api/group/${groupIdx}/accept`).send([]);
t.is(response.status, 200);

await model.pgDo(async tr => {
await model.users.addPendingUserMembership(tr, memberIdx, groupIdx);
});

response = await agent.post(`/api/group/${groupIdx}/accept`).send([memberIdx]);
t.is(response.status, 200);

Expand Down Expand Up @@ -288,6 +288,13 @@ test('reject group requests', async t => {
let response;

response = await agent.post(`/api/group/${groupIdx}/reject`).send([]);
t.is(response.status, 400);

await model.pgDo(async tr => {
await model.users.addPendingUserMembership(tr, memberIdx, groupIdx);
});

response = await agent.post(`/api/group/${groupIdx}/reject`).send([memberIdx]);
t.is(response.status, 401);

response = await agent.post('/api/login').send({
Expand All @@ -296,20 +303,13 @@ test('reject group requests', async t => {
});
t.is(response.status, 200);

response = await agent.post(`/api/group/${groupIdx}/reject`).send([]);
t.is(response.status, 401);
response = await agent.post(`/api/group/${groupIdx}/reject`).send([memberIdx]);
t.is(response.status, 403);

await model.pgDo(async tr => {
await model.groups.setOwnerGroup(tr, groupIdx, ownerGroupIdx);
});

response = await agent.post(`/api/group/${groupIdx}/reject`).send([]);
t.is(response.status, 200);

await model.pgDo(async tr => {
await model.users.addPendingUserMembership(tr, memberIdx, groupIdx);
});

response = await agent.post(`/api/group/${groupIdx}/reject`).send([memberIdx]);
t.is(response.status, 200);

Expand Down
2 changes: 1 addition & 1 deletion test/api/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test('create user step by step', async t => {
studentNumbers,
});
// request without session token will be fail
t.is(response.status, 401);
t.is(response.status, 400);

response = await agent.post('/api/email/check-token').send({
token,
Expand Down

0 comments on commit 007f374

Please sign in to comment.