Skip to content

Commit

Permalink
added e2e test for getAllActiveEvents endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaLoubser committed Sep 21, 2023
1 parent 4b47c30 commit 020b3c0
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions apps/api-e2e/src/api/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,45 @@ describe('EventController', ()=>{
})
})

describe('getActiveEvents', ()=>{
it('Should return an array of events', async ()=>{
//create event manager and event
await userRepository.createUser(TEST_USER_1);
const manager = await userRepository.getUser(process.env['TEST_USER_EMAIL_1']);
TEST_EVENT.Manager = manager[0]._id;
TEST_EVENT_2.Manager = manager[0]._id;

//set details to current time
TEST_EVENT.StartDate = new Date();
TEST_EVENT.EndDate = new Date();
TEST_EVENT.EndDate.setHours(TEST_EVENT.EndDate.getHours() + 2);

//create events
await eventRepository.createEvent(TEST_EVENT);
await eventRepository.createEvent(TEST_EVENT_2);
const event1 = await eventRepository.getEventByName(TEST_EVENT.Name);
const event2= await eventRepository.getEventByName(TEST_EVENT_2.Name);

let events = await eventRepository.getAllEvents();
while(events.length != 2){
SLEEP(500);
events = await eventRepository.getAllEvents();
}

const response = await request(httpServer).get('/event/getAllActiveEvents');

//should only contain event1
expect(response.status).toBe(200);
const res = objectSubset(TEST_EVENT,response.body.events);
expect(res).toBe(true);

//cleanup
await userRepository.deleteUserById(manager[0]._id);
await eventRepository.deleteEventbyId(event1[0]._id);
await eventRepository.deleteEventbyId(event2[0]._id);
})
})

})

describe('UserController', ()=>{
Expand Down

0 comments on commit 020b3c0

Please sign in to comment.