Skip to content

Commit 87dde4a

Browse files
added a test for redirection to new signup flow, and fix for the existing test failing
1 parent 8983d06 commit 87dde4a

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

test/fixtures/user/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = () => {
3333
publicId: "profile/mtS4DhUvNYsKqI7oCWVB/aenklfhtjldc5ytei3ar",
3434
url: "https://res.cloudinary.com/realdevsquad/image/upload/v1667685133/profile/mtS4DhUvNYsKqI7oCWVB/aenklfhtjldc5ytei3ar.jpg",
3535
},
36+
incompleteUserDetails: false,
3637
},
3738
{
3839
username: "nikhil",

test/integration/auth.test.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const passport = require("passport");
66

77
const app = require("../../server");
88
const cleanDb = require("../utils/cleanDb");
9+
const { addUserToDBForTest } = require("../../utils/users");
10+
const userData = require("../fixtures/user/user")();
911

1012
chai.use(chaiHttp);
1113

@@ -19,28 +21,38 @@ describe("auth", function () {
1921
sinon.restore();
2022
});
2123

22-
it("should redirect the request to the goto page on successful login", function (done) {
24+
it("should redirect the user to new sign up flow if they are have incomplte user details true", async function () {
25+
const redirectURL = "https://my.realdevsquad.com/new-signup";
26+
sinon.stub(passport, "authenticate").callsFake((strategy, options, callback) => {
27+
callback(null, "accessToken", githubUserInfo[0]);
28+
return (req, res, next) => {};
29+
});
30+
31+
const res = await chai
32+
.request(app)
33+
.get("/auth/github/callback")
34+
.query({ code: "codeReturnedByGithub" })
35+
.redirects(0);
36+
expect(res).to.have.status(302);
37+
expect(res.headers.location).to.equal(redirectURL);
38+
});
39+
// same data should be return from github and same data should be added there
40+
it("should redirect the request to the goto page on successful login, if user has incomplete user details false", async function () {
41+
await addUserToDBForTest(userData[0]);
2342
const rdsUiUrl = config.get("services.rdsUi.baseUrl");
2443

2544
sinon.stub(passport, "authenticate").callsFake((strategy, options, callback) => {
2645
callback(null, "accessToken", githubUserInfo[0]);
2746
return (req, res, next) => {};
2847
});
2948

30-
chai
49+
const res = await chai
3150
.request(app)
3251
.get("/auth/github/callback")
33-
.query({ code: "codeReturnedByGithub", state: rdsUiUrl })
34-
.redirects(0)
35-
.end((err, res) => {
36-
if (err) {
37-
return done(err);
38-
}
39-
expect(res).to.have.status(302);
40-
expect(res.headers.location).to.equal(rdsUiUrl);
41-
42-
return done();
43-
});
52+
.query({ code: "codeReturnedByGithub", state: rdsUiUrl, shouldConsole: true })
53+
.redirects(0);
54+
expect(res).to.have.status(302);
55+
expect(res.headers.location).to.equal(rdsUiUrl);
4456
});
4557

4658
it("should send a cookie with JWT in the response", function (done) {

utils/users.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
const { fetchUser } = require("../models/users");
2+
const firestore = require("../utils/firestore");
3+
const userModel = firestore.collection("users");
4+
5+
const addUserToDBForTest = async (userData) => {
6+
try {
7+
await userModel.add(userData);
8+
} catch (err) {
9+
// console.log(err);
10+
}
11+
};
212

313
/**
414
* Used for receiving userId when providing username
515
*
616
* @param username {String} - username of the User.
717
* @returns id {String} - userId of the same user
818
*/
19+
920
const getUserId = async (username) => {
1021
try {
1122
const {
@@ -137,6 +148,7 @@ function getUsernamesFromPRs(allPRs) {
137148
}
138149

139150
module.exports = {
151+
addUserToDBForTest,
140152
getUserId,
141153
getUsername,
142154
getParticipantUserIds,

0 commit comments

Comments
 (0)