@@ -6,21 +6,13 @@ const AuditLog = require('../../api/main_endpoints/models/AuditLog.js');
66const chai = require ( 'chai' ) ;
77
88const chaiHttp = require ( 'chai-http' ) ;
9- const sinon = require ( 'sinon' ) ;
109const {
11- OK ,
12- BAD_REQUEST ,
1310 UNAUTHORIZED ,
14- FORBIDDEN ,
15- NOT_FOUND ,
16- CONFLICT ,
17- SERVER_ERROR ,
1811} = require ( '../../api/util/constants.js' ) . STATUS_CODES ;
1912const SceApiTester = require ( '../util/tools/SceApiTester.js' ) ;
2013
2114let app = null ;
2215let test = null ;
23- let sandbox = sinon . createSandbox ( ) ;
2416const expect = chai . expect ;
2517const tools = require ( '../util/tools/tools.js' ) ;
2618const {
@@ -36,7 +28,6 @@ const {
3628 initializeDiscordAPIMock
3729} = require ( '../util/mocks/DiscordApiFunction.js' ) ;
3830const { MEMBERSHIP_STATE } = require ( '../../api/util/constants.js' ) ;
39- const { getMemberExpirationDate } = require ( '../../api/main_endpoints/util/userHelpers.js' ) ;
4031const AuditLogActions = require ( '../../api/main_endpoints/util/auditLogActions.js' ) ;
4132
4233chai . should ( ) ;
@@ -106,10 +97,8 @@ describe('AuditLog', () => {
10697 expect ( result ) . to . have . status ( UNAUTHORIZED ) ;
10798 } ) ;
10899
109- describe ( 'When token and access level is valid - status code 200' , ( ) => {
110- beforeEach ( ( ) => {
111- setTokenStatus ( true , { accessLevel : MEMBERSHIP_STATE . OFFICER } ) ;
112- } ) ;
100+ it ( 'Should return at most 50 records when query is an empty string and access level is valid' , async ( ) => {
101+ setTokenStatus ( true , { accessLevel : MEMBERSHIP_STATE . OFFICER } ) ;
113102
114103 before ( async ( ) => {
115104 const newUser = new User ( {
@@ -139,32 +128,31 @@ describe('AuditLog', () => {
139128 } ) ;
140129 }
141130 } ) ;
131+ const result = await test . sendGetRequestWithToken ( token , url ) ;
132+ expect ( result . body . items ) . that . is . an ( 'array' ) ;
133+ expect ( result . body . items . length ) . at . most ( 50 ) ;
134+ } ) ;
142135
143- it ( 'Should return at most 50 records when query is empty' , async ( ) => {
144- const result = await test . sendGetRequestWithToken ( token , url ) ;
145- expect ( result . body . items ) . that . is . an ( 'array' ) ;
146- expect ( result . body . items . length ) . at . most ( 50 ) ;
147- } ) ;
148-
149- it ( 'Should return the testUser when query is "[email protected] "' , async ( ) => { 150- const search = '[email protected] ' ; 151- const fullUrl = `/api/AuditLog/getAuditLogs?search=${ encodeURIComponent ( search ) } ` ;
152- const result = await test . sendGetRequestWithToken ( token , fullUrl ) ;
153- expect ( result . body . items ) . that . is . an ( 'array' ) . to . have . lengthOf ( 1 ) ;
154- expect ( result . body . items [ 0 ] . userId . email ) . to . eql ( '[email protected] ' ) ; 155- } ) ;
136+ it ( 'Should return the testUser when query is "[email protected] " and access level is OFFICER' , async ( ) => { 137+ setTokenStatus ( true , { accessLevel : MEMBERSHIP_STATE . OFFICER } ) ;
138+ const search = '[email protected] ' ; 139+ const fullUrl = `/api/AuditLog/getAuditLogs?search=${ encodeURIComponent ( search ) } ` ;
140+ const result = await test . sendGetRequestWithToken ( token , fullUrl ) ;
141+ expect ( result . body . items ) . that . is . an ( 'array' ) . to . have . lengthOf ( 1 ) ;
142+ expect ( result . body . items [ 0 ] . userId . email ) . to . eql ( '[email protected] ' ) ; 143+ } ) ;
156144
157- it ( 'Should return an empty array when the query matches no record: "[email protected] "' , async ( ) => { 158- const search = '[email protected] ' ; 159- const fullUrl = `/api/AuditLog/getAuditLogs?search=${ encodeURIComponent ( search ) } ` ;
160- const result = await test . sendGetRequestWithToken ( token , fullUrl ) ;
161- expect ( result . body . items ) . that . is . an ( 'array' ) . that . is . empty ;
162- } ) ;
145+ it ( 'Should return an empty array when the query matches no record: "[email protected] " and access level is ADMIN' , async ( ) => { 146+ setTokenStatus ( true , { accessLevel : MEMBERSHIP_STATE . ADMIN } ) ;
147+ const search = '[email protected] ' ; 148+ const fullUrl = `/api/AuditLog/getAuditLogs?search=${ encodeURIComponent ( search ) } ` ;
149+ const result = await test . sendGetRequestWithToken ( token , fullUrl ) ;
150+ expect ( result . body . items ) . that . is . an ( 'array' ) . that . is . empty ;
151+ } ) ;
163152
164- after ( async ( ) => {
165- await User . deleteMany ( { } ) ;
166- await AuditLog . deleteMany ( { } ) ;
167- } ) ;
153+ after ( async ( ) => {
154+ await User . deleteMany ( { } ) ;
155+ await AuditLog . deleteMany ( { } ) ;
168156 } ) ;
169157 } ) ;
170158} ) ;
0 commit comments