Skip to content

Commit 416e5ae

Browse files
authored
[Live-Site] Add logs for kickout API (#1623)
* [Live-Site] Add logs for kickout API Signed-off-by: Gurvinder Singh <[email protected]> * [Live-Site] Add logs for kickout API - Integration tests Signed-off-by: Gurvinder Singh <[email protected]> * [Live-Site] Add logs for kickout API - Integration tests for member user Signed-off-by: Gurvinder Singh <[email protected]> --------- Signed-off-by: Gurvinder Singh <[email protected]>
1 parent c72ec0b commit 416e5ae

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

constants/logs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const logType = {
22
PROFILE_DIFF_APPROVED: "PROFILE_DIFF_APPROVED",
33
PROFILE_DIFF_REJECTED: "PROFILE_DIFF_REJECTED",
44
CLOUDFLARE_CACHE_PURGED: "CLOUDFLARE_CACHE_PURGED",
5+
EVENTS_REMOVE_PEER: "EVENTS_REMOVE_PEER",
56
};
67

78
module.exports = { logType };

controllers/events.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const logger = require("../utils/logger");
77
const { removeUnwantedProperties } = require("../utils/events");
88

99
const crypto = require("crypto");
10+
const { addLog } = require("../models/logs");
11+
const { logType } = require("../constants/logs");
1012

1113
const tokenService = new EventTokenService();
1214
const apiService = new EventAPIService(tokenService);
@@ -296,6 +298,7 @@ const kickoutPeer = async (req, res) => {
296298
try {
297299
await apiService.post(`/active-rooms/${id}/remove-peers`, payload);
298300
await eventQuery.kickoutPeer({ eventId: id, peerId: payload.peer_id, reason: req.body.reason });
301+
addLog(logType.EVENTS_REMOVE_PEER, { removed_by: req.userData.id }, payload);
299302
return res.status(200).json({
300303
message: `Selected Participant is removed from event.`,
301304
});

test/integration/events.test.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const event1Data = eventData[0];
1616
const userData = require("../fixtures/user/user")();
1717

1818
const eventQuery = require("../../models/events");
19+
const logsModel = require("../../models/logs");
1920

2021
const defaultUser = userData[16];
2122

@@ -721,4 +722,98 @@ describe("events", function () {
721722
});
722723
});
723724
});
725+
726+
describe("PATCH /events/:id/peers/kickout", function () {
727+
let service;
728+
let superUserAuthToken;
729+
let memberAuthToken;
730+
beforeEach(async function () {
731+
const superUser = userData[4];
732+
const member = userData[6];
733+
const superUserId = await addUser(superUser);
734+
const memberUserId = await addUser(member);
735+
superUserAuthToken = authService.generateAuthToken({ userId: superUserId });
736+
memberAuthToken = authService.generateAuthToken({ userId: memberUserId });
737+
});
738+
739+
afterEach(function () {
740+
service.restore();
741+
sinon.restore();
742+
});
743+
744+
it("returns a success message when the request is successful for super user", function (done) {
745+
const payload = {
746+
peerId: "peer123",
747+
reason: "Kicked out for a reason",
748+
};
749+
750+
service = sinon.stub(EventAPIService.prototype, "post").returns({ message: "peer remove request submitted" });
751+
752+
sinon.stub(eventQuery, "kickoutPeer").returns({ message: "Selected Participant is removed from event." });
753+
sinon.stub(logsModel, "addLog");
754+
755+
chai
756+
.request(app)
757+
.patch(`/events/${event1Data.room_id}/peers/kickout`)
758+
.set("cookie", `${cookieName}=${superUserAuthToken}`)
759+
.send(payload)
760+
.end((error, response) => {
761+
if (error) {
762+
return done(error);
763+
}
764+
765+
expect(response).to.have.status(200);
766+
expect(response.body.message).to.be.a("string");
767+
expect(response.body.message).to.equal("Selected Participant is removed from event.");
768+
769+
return done();
770+
});
771+
});
772+
773+
it("returns a success message when the request is successful for member user", function (done) {
774+
const payload = {
775+
peerId: "peer123",
776+
reason: "Kicked out for a reason",
777+
};
778+
779+
service = sinon.stub(EventAPIService.prototype, "post").returns({ message: "peer remove request submitted" });
780+
781+
sinon.stub(eventQuery, "kickoutPeer").returns({ message: "Selected Participant is removed from event." });
782+
sinon.stub(logsModel, "addLog");
783+
784+
chai
785+
.request(app)
786+
.patch(`/events/${event1Data.room_id}/peers/kickout`)
787+
.set("cookie", `${cookieName}=${memberAuthToken}`)
788+
.send(payload)
789+
.end((error, response) => {
790+
if (error) {
791+
return done(error);
792+
}
793+
794+
expect(response).to.have.status(200);
795+
expect(response.body.message).to.be.a("string");
796+
expect(response.body.message).to.equal("Selected Participant is removed from event.");
797+
798+
return done();
799+
});
800+
});
801+
802+
it("should return unauthorized error if user is not authenticated", function (done) {
803+
chai
804+
.request(app)
805+
.patch(`/events/${event1Data.room_id}/peers/kickout`)
806+
.end((error, response) => {
807+
if (error) {
808+
return done(error);
809+
}
810+
811+
expect(response).to.have.status(401);
812+
expect(response.body.error).to.be.equal("Unauthorized");
813+
expect(response.body.message).to.be.equal("Unauthenticated User");
814+
815+
return done();
816+
});
817+
});
818+
});
724819
});

0 commit comments

Comments
 (0)