generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for blocking archived users from discord actions (#1124)
* 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
1 parent
0d28a20
commit 24dd9b7
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); | ||
}); |