1
1
import { beforeEach , describe , expect , it } from "@jest/globals" ;
2
2
import Models from "../../database/models.js" ;
3
- import { DecisionStatus , DecisionResponse } from "./admission-formats .js" ;
4
- import { getAsAttendee , getAsStaff , getAsUser , putAsAttendee , putAsStaff , putAsUser , TESTER } from "../../testTools.js" ;
3
+ import { DecisionStatus , DecisionResponse } from "../../database/decision-db .js" ;
4
+ import { getAsAttendee , getAsStaff , getAsUser , putAsStaff , putAsUser , TESTER } from "../../testTools.js" ;
5
5
import { DecisionInfo } from "../../database/decision-db.js" ;
6
6
import { StatusCode } from "status-code-enum" ;
7
+ import { ApplicantDecisionFormat } from "./admission-formats.js" ;
7
8
8
9
const TESTER_USER = {
9
10
userId : TESTER . id ,
@@ -21,6 +22,19 @@ const OTHER_USER = {
21
22
reviewer : "other-reviewer" ,
22
23
} satisfies DecisionInfo ;
23
24
25
+ const updateData = [
26
+ {
27
+ userId : TESTER . id ,
28
+ name : TESTER . name ,
29
+ status : DecisionStatus . WAITLISTED ,
30
+ } ,
31
+ {
32
+ userId : "other-user" ,
33
+ name : "other-name" ,
34
+ status : DecisionStatus . ACCEPTED ,
35
+ } ,
36
+ ] satisfies ApplicantDecisionFormat [ ] ;
37
+
24
38
beforeEach ( async ( ) => {
25
39
Models . initialize ( ) ;
26
40
await Models . DecisionInfo . create ( TESTER_USER ) ;
@@ -30,11 +44,11 @@ beforeEach(async () => {
30
44
describe ( "GET /admission" , ( ) => {
31
45
it ( "gives forbidden error for user without elevated perms" , async ( ) => {
32
46
const responseUser = await getAsUser ( "/admission/" ) . expect ( StatusCode . ClientErrorForbidden ) ;
33
- expect ( JSON . parse ( responseUser . text ) ) . toHaveProperty ( "error" , "InvalidToken " ) ;
47
+ expect ( JSON . parse ( responseUser . text ) ) . toHaveProperty ( "error" , "Forbidden " ) ;
34
48
} ) ;
35
49
it ( "gives forbidden error for user without elevated perms - attendee" , async ( ) => {
36
50
const responseAttendee = await getAsAttendee ( "/admission/" ) . expect ( StatusCode . ClientErrorForbidden ) ;
37
- expect ( JSON . parse ( responseAttendee . text ) ) . toHaveProperty ( "error" , "InvalidToken " ) ;
51
+ expect ( JSON . parse ( responseAttendee . text ) ) . toHaveProperty ( "error" , "Forbidden " ) ;
38
52
} ) ;
39
53
it ( "should return a list of applicants without email sent" , async ( ) => {
40
54
const response = await getAsStaff ( "/admission/" ) . expect ( StatusCode . SuccessOK ) ;
@@ -43,25 +57,9 @@ describe("GET /admission", () => {
43
57
} ) ;
44
58
45
59
describe ( "PUT /admission" , ( ) => {
46
- const updateData = [
47
- {
48
- userId : TESTER . id ,
49
- name : TESTER . name ,
50
- status : DecisionStatus . WAITLISTED ,
51
- } ,
52
- {
53
- userId : "other-user" ,
54
- name : "other-name" ,
55
- status : DecisionStatus . ACCEPTED ,
56
- } ,
57
- ] ;
58
- it ( "gives forbidden error for user without elevated perms (As User)" , async ( ) => {
59
- const responseAttendee = await putAsAttendee ( "/admission/" ) . send ( updateData ) . expect ( StatusCode . ClientErrorForbidden ) ;
60
- expect ( JSON . parse ( responseAttendee . text ) ) . toHaveProperty ( "error" , "InvalidToken" ) ;
61
- } ) ;
62
60
it ( "gives forbidden error for user without elevated perms (As Attendee)" , async ( ) => {
63
61
const responseUser = await putAsUser ( "/admission/" ) . send ( updateData ) . expect ( StatusCode . ClientErrorForbidden ) ;
64
- expect ( JSON . parse ( responseUser . text ) ) . toHaveProperty ( "error" , "InvalidToken " ) ;
62
+ expect ( JSON . parse ( responseUser . text ) ) . toHaveProperty ( "error" , "Forbidden " ) ;
65
63
} ) ;
66
64
it ( "should update application status of applicants" , async ( ) => {
67
65
const response = await putAsStaff ( "/admission/" ) . send ( updateData ) . expect ( StatusCode . SuccessOK ) ;
@@ -70,10 +68,10 @@ describe("PUT /admission", () => {
70
68
return Models . DecisionInfo . findOne ( { userId : entry . userId } ) ;
71
69
} ) ;
72
70
const retrievedEntries = await Promise . all ( ops ) ;
73
- updateData . forEach ( ( entry ) => {
74
- expect ( retrievedEntries ) . toMatchObject (
75
- expect . arrayContaining ( [ expect . objectContaining ( { status : entry . status , userId : entry . userId } ) ] ) ,
76
- ) ;
77
- } ) ;
71
+ expect ( retrievedEntries ) . toMatchObject (
72
+ expect . arrayContaining (
73
+ updateData . map ( ( item ) => expect . objectContaining ( { status : item . status , userId : item . userId } ) ) ,
74
+ ) ,
75
+ ) ;
78
76
} ) ;
79
77
} ) ;
0 commit comments