Skip to content

Commit

Permalink
Merge branch 'dev' into api_refactor_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaLoubser committed Sep 26, 2023
2 parents bbab4c3 + d8af7f9 commit 6ddc535
Show file tree
Hide file tree
Showing 232 changed files with 17,666 additions and 381 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ jobs:
deploy:
if: github.event_name == 'pull_request' && github.event.pull_request.merged
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Connect to server and trigger update
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
sudo /root/deploy.sh production
sudo /root/deploy.sh production
15 changes: 13 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@ jobs:
- run: 'yarn nx run-many --target=lint --all --parallel --skip-nx-cache'
- run: 'yarn nx run-many --target=build --all --parallel --skip-nx-cache'
- run: 'yarn nx run-many --target=test --all --parallel --skip-nx-cache --coverage --testTimeout=10000'
- run: 'yarn nx run app-e2e:e2e --all --parallel --skip-nx-cache --coverage --testTimeout=10000 --detectOpenHandles=true'
- run: 'yarn test:integration'
# - run: 'yarn nx run app-e2e:e2e --all --parallel --skip-nx-cache --coverage --testTimeout=10000 --detectOpenHandles=true'
- run: 'yarn test:integration --coverage'
- name: Use codecov token to upload coverage reports to codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage reports to Codecov
run: |
# Replace `linux` below with the appropriate OS
# Options are `alpine`, `linux`, `macos`, `windows`
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${{ secrets.CODECOV_TOKEN }} -f coverage-final.json
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# EventParticipationTrends

[![codecov](https://codecov.io/gh/JsteReubsSoftware/Event-Participation-Trends-forked/graph/badge.svg?token=AA00EF5IVF)](https://codecov.io/gh/JsteReubsSoftware/Event-Participation-Trends-forked)

## Indlovu - Gendac - Event Participation Trends

Event Participation Trends is a system that leverages the always-online nature of devices to track the number of people attending an event, generate heatmaps and flowmaps of the event, and provide a live feed of the event to the public.
Expand Down
3 changes: 2 additions & 1 deletion apps/api-e2e/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export default {
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/api-e2e',
coverageDirectory: '../../coverage/apps/api-e2e',
coverageReporters: ['clover', 'json', 'lcov', 'text'], // Include 'json' for JSON coverage report
};
230 changes: 226 additions & 4 deletions apps/api-e2e/src/api/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { CsrfGuard, JwtGuard, RbacGuard } from '@event-participation-trends/api/
import { EventRepository } from '@event-participation-trends/api/event/data-access';
import { UserRepository } from '@event-participation-trends/api/user/data-access';
import { GlobalRepository } from '@event-participation-trends/api/global/data-access';
import { ICreateEventRequest, IEvent, IFloorLayout, IImageUploadRequest, IPosition, IUpdateEventFloorLayoutImgRequest, IViewEvent, Position } from '@event-participation-trends/api/event/util';
import { IEvent, IFloorLayout, IImageUploadRequest, IPosition, IUpdateEventFloorLayoutImgRequest } from '@event-participation-trends/api/event/util';
import { IUser, Role } from '@event-participation-trends/api/user/util';
import { ICreateGlobalRequest, IGlobal } from '@event-participation-trends/api/global/util';
import { promisify } from 'util';
import { UpdateEventDetails } from '@event-participation-trends/api/event/feature';
import { Image } from "@event-participation-trends/api/event/feature";


Expand Down Expand Up @@ -515,11 +514,9 @@ describe('EventController', ()=>{
expect(response.status).toBe(201);
let events = await eventRepository.getAllEvents();

CATCH_ITERATION_EXCEEDED(true);
while(events.length != 1){
SLEEP(500);
events = await eventRepository.getAllEvents();
CATCH_ITERATION_EXCEEDED(false);
}

if(events && events.length ==1){
Expand Down Expand Up @@ -1161,6 +1158,231 @@ 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');

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('uploadFloorlayoutImage', ()=>{
it('Should upload the given image', 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;

//create event
await eventRepository.createEvent(TEST_EVENT);
let event = await eventRepository.getEventByName(TEST_EVENT.Name);

while(event.length != 1){
SLEEP(500);
event = await eventRepository.getEventByName(TEST_EVENT.Name);
}

EVENT_IMAGE.eventId = <string> <unknown> event[0]._id;

const response = await request(httpServer).post('/event/uploadFloorlayoutImage').send(
EVENT_IMAGE
);
expect(response.body.status).toBe("success");

//should create an image
let eventImg = await eventRepository.findImageByEventId(event[0]._id);

while(event.length != 1){
SLEEP(500);
eventImg = await eventRepository.findImageByEventId(event[0]._id);
}

const temp: IImageUploadRequest = {
eventId: <string> <unknown> event[0]._id,
imgBase64: eventImg[0].imageBase64,
imageObj: eventImg[0].imageObj,
imageScale: eventImg[0].imageScale,
imageType: eventImg[0].imageType,
}

const res = objectSubset(EVENT_IMAGE,[temp]);
expect(res).toBe(true);

//should add imageid to the event's FloorLayoutImgs array
while(event[0].FloorLayoutImgs.length != 1){
SLEEP(500);
event = await eventRepository.getEventByName(TEST_EVENT.Name);
}

if(event[0].FloorLayoutImgs[0].equals(eventImg[0]._id)){
expect(true).toBe(true);
}else{
expect(false).toBe(true);
}

//cleanup
await userRepository.deleteUserById(manager[0]._id);
await eventRepository.deleteEventbyId(event[0]._id);
await eventRepository.removeImage(eventImg[0]._id);
})
})

describe('getFloorLayoutImage', ()=>{
it('Should return the given image', 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;

//create event
await eventRepository.createEvent(TEST_EVENT);
let event = await eventRepository.getEventByName(TEST_EVENT.Name);

while(event.length != 1){
SLEEP(500);
event = await eventRepository.getEventByName(TEST_EVENT.Name);
}

EVENT_IMAGE.eventId = <string> <unknown> event[0]._id;

await eventRepository.uploadImage(new Image(
<Types.ObjectId> <unknown> EVENT_IMAGE.eventId,
EVENT_IMAGE.imgBase64,
EVENT_IMAGE.imageScale,
EVENT_IMAGE.imageType,
EVENT_IMAGE.imageObj
));

let eventImg = await eventRepository.findImagesIdByEventId(event[0]._id);
while(eventImg.length != 1){
SLEEP(500);
eventImg = await eventRepository.findImagesIdByEventId(event[0]._id);
}

const response = await request(httpServer).get(`/event/getFloorLayoutImage?eventId=${event[0]._id}`);

const temp: IImageUploadRequest = {
eventId: <string> <unknown> response.body.images[0]._id,
imgBase64: response.body.images[0].imageBase64,
imageObj: response.body.images[0].imageObj,
imageScale: response.body.images[0].imageScale,
imageType: response.body.images[0].imageType,
}

expect(response.status).toBe(200);
const res = objectSubset(EVENT_IMAGE,[temp]);
expect(res).toBe(true);

//cleanup
await userRepository.deleteUserById(manager[0]._id);
await eventRepository.deleteEventbyId(event[0]._id);
await eventRepository.removeImage(eventImg[0]._id);
})
})

describe('updateEventFloorlayoutImage', ()=>{
it('Should update the given image', 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;

//create event
await eventRepository.createEvent(TEST_EVENT);

let event = await eventRepository.getEventByName(TEST_EVENT.Name);
while(event.length != 1){
SLEEP(500);
event = await eventRepository.getEventByName(TEST_EVENT.Name);
}

EVENT_IMAGE.eventId = <string> <unknown> event[0]._id;

await eventRepository.uploadImage(new Image(
<Types.ObjectId> <unknown> EVENT_IMAGE.eventId,
EVENT_IMAGE.imgBase64,
EVENT_IMAGE.imageScale,
EVENT_IMAGE.imageType,
EVENT_IMAGE.imageObj
));

let eventImg = await eventRepository.findImageByEventId(event[0]._id);
while(eventImg.length != 1){
SLEEP(500);
eventImg = await eventRepository.findImageByEventId(event[0]._id);
}

UPDATED_EVENT_IMAGE.eventId = <string> <unknown> event[0]._id;
UPDATED_EVENT_IMAGE.imageId = <string> <unknown> eventImg[0]._id;
UPDATED_EVENT_IMAGE.managerEmail = process.env['TEST_USER_EMAIL_1'];

await eventRepository.addImageToEvent(event[0]._id,eventImg[0]._id);

const response = await request(httpServer).post('/event/updateEventFloorlayoutImage').send(
UPDATED_EVENT_IMAGE
);

eventImg = await eventRepository.findImageByEventId(event[0]._id);
//imageType is last to update ref: event handler
console.log(eventImg[0].imageType);
console.log(UPDATED_EVENT_IMAGE.imageType);
while(eventImg[0].imageType != UPDATED_EVENT_IMAGE.imageType ){
SLEEP(500);
eventImg = await eventRepository.findImageByEventId(event[0]._id);
}

expect(response.body.status).toBe("success");

const temp: IUpdateEventFloorLayoutImgRequest = {
eventId: <string> <unknown> event[0]._id,
imageId: <string> <unknown> eventImg[0]._id,
managerEmail: process.env['TEST_USER_EMAIL_1'],
imgBase64: eventImg[0].imageBase64,
imageObj: eventImg[0].imageObj,
imageScale: eventImg[0].imageScale,
imageType: eventImg[0].imageType,
}

const res = objectSubset(UPDATED_EVENT_IMAGE,[temp]);
expect(res).toBe(true);

//cleanup
await userRepository.deleteUserById(manager[0]._id);
await eventRepository.deleteEventbyId(event[0]._id);
await eventRepository.removeImage(eventImg[0]._id);
})
})

})

describe('UserController', ()=>{
Expand Down
1 change: 1 addition & 0 deletions apps/api/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export default {
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/api',
coverageReporters: ['clover', 'json', 'lcov', 'text'], // Include 'json' for JSON coverage report
};
5 changes: 5 additions & 0 deletions apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import { ScheduleModule } from '@nestjs/schedule';

import {DatabaseModule} from '@event-participation-trends/api/database/feature';
import { DatabaseConfigService } from '@event-participation-trends/api/database/feature';
import { NgIconsModule } from '@ng-icons/core';
import { SocketGateway } from './socket/socket.gateway';
import { SocketServiceService } from './socket/socket-service.service';

@Module({
imports: [
Expand Down Expand Up @@ -62,6 +65,8 @@ import { DatabaseConfigService } from '@event-participation-trends/api/database/
UserService,
EventService,
SensorlinkingService,
SocketGateway,
SocketServiceService
],
})
export class AppModule {}
Loading

0 comments on commit 6ddc535

Please sign in to comment.