-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from FernFinder/loginquizpathline
Login page to quiz redirection + Stat Change API
- Loading branch information
Showing
7 changed files
with
162 additions
and
11 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
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
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,43 @@ | ||
const request = require("supertest"); | ||
const sinon = require('sinon'); | ||
const middleware = require('../middleware/auth.js'); | ||
const mongoose = require('mongoose'); | ||
var app; | ||
|
||
beforeAll(async () => { | ||
//Replace the middleware function with a fake function that passes the request through. | ||
sinon.stub(middleware, "userVerification") | ||
.callsFake(async function userVerification(req, res, next) { | ||
return next(); | ||
}); | ||
|
||
//You need to declare this after the fake function is made | ||
app = require("../app"); | ||
}); | ||
|
||
afterAll(async () => { | ||
//Restore middleware function to the original state | ||
middleware.userVerification.restore(); | ||
mongoose.disconnect; | ||
}); | ||
|
||
// test user stat change | ||
describe("POST /users/changestats", () => { | ||
it("it should return 404 for no user found", async () => { | ||
// request stat update | ||
const response = await request(app).post("/users/changestats"); | ||
// check for error 404, user not found | ||
expect(response.statusCode).toBe(404); | ||
expect(response.body.message).toBe('User not found'); | ||
}); | ||
}); | ||
|
||
describe("GET /users/me", () => { | ||
it("it should get a user's stats", async () => { | ||
// request stats | ||
const response = await request(app).get("/users/me"); | ||
// check for error 404, user not found | ||
expect(response.statusCode).toBe(404); | ||
expect(response.body.message).toBe('User not found'); | ||
}); | ||
}); |
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