Skip to content

Commit

Permalink
add tests for blocking archived users from discord actions (#1124)
Browse files Browse the repository at this point in the history
* add tests for blocking archived users from discord actions

* add test to cover foe unarchived and active users

* Delete yarn.lock

* add yarn-lock

* remove yarn lock changes
  • Loading branch information
RitikJaiswal75 authored Jun 7, 2023
1 parent 0d28a20 commit 24dd9b7
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/fixtures/discordactions/discordactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const roleData = {
userid: "test-user-id",
};

const requestRoleData = {
rolename: "test-role",
};

const existingRole = {
roleData: { roleid: "test-role-id", userid: "test-user-id" },
wasSuccess: false,
Expand All @@ -18,4 +22,5 @@ module.exports = {
groupData,
roleData,
existingRole,
requestRoleData,
};
78 changes: 78 additions & 0 deletions test/integration/discord.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const chai = require("chai");
const { expect } = chai;

const app = require("../../server");
const addUser = require("../utils/addUser");
const cleanDb = require("../utils/cleanDb");
const authService = require("../../services/authService");
const userData = require("../fixtures/user/user")();
const { requestRoleData } = require("../fixtures/discordactions/discordactions");

const cookieName = config.get("userToken.cookieName");

let userId;
let jwt;

describe("test discord actions", function () {
describe("test discord actions for archived users", function (done) {
beforeEach(async function () {
userId = await addUser(userData[5]);
jwt = authService.generateAuthToken({ userId });
});

afterEach(async function () {
await cleanDb();
});

it("returns 403 for archived users post method", function (done) {
chai
.request(app)
.post("/discord-actions/groups")
.set("Cookie", `${cookieName}=${jwt}`)
.send(requestRoleData)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res).to.have.status(403);
return done();
});
});

it("returns 403 for archived users get method", function (done) {
chai
.request(app)
.get("/discord-actions/groups")
.set("Cookie", `${cookieName}=${jwt}`)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res).to.have.status(403);
return done();
});
});
});

describe("test discord actions for active users", function () {
beforeEach(async function () {
const user = { ...userData[4], discordId: "123456789" };
userId = await addUser(user);
jwt = authService.generateAuthToken({ userId });
});

it("returns 200 for active users get method", function (done) {
chai
.request(app)
.get("/discord-actions/groups")
.set("Cookie", `${cookieName}=${jwt}`)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res).to.have.status(200);
return done();
});
});
});
});

0 comments on commit 24dd9b7

Please sign in to comment.