-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ft-login-via-google-187584916' of https://github.com/at…
…lp-rwanda/e-commerce-ninjas-bn into ft-login-via-google-187584916
- Loading branch information
Showing
2 changed files
with
5 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,17 @@ | ||
/* eslint-disable no-shadow */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Request, Response } from "express"; | ||
import chai, { expect } from "chai"; | ||
import chaiHttp from "chai-http"; | ||
import sinon from "sinon"; | ||
import httpStatus from "http-status"; | ||
import app from "../../.."; | ||
import { isUserExist } from "../../../middlewares/validation"; | ||
import authRepositories from "../repository/authRepositories"; | ||
import Users from "../../../databases/models/users"; | ||
import Session from "../../../databases/models/session"; | ||
import { sendVerificationEmail, transporter } from "../../../services/sendEmail"; | ||
import passport, { PassportStatic } from "passport"; | ||
import { Strategy as GoogleStrategy } from "passport-google-oauth2"; | ||
import session from "express-session"; | ||
import dotenv from "dotenv"; | ||
import googleAuth from "../../../services/googleAuth"; | ||
import { generateToken } from "../../../helpers"; | ||
import app from "../../../index"; | ||
|
||
|
||
chai.use(chaiHttp); | ||
const router = () => chai.request(app); | ||
|
@@ -406,46 +400,9 @@ describe("sendVerificationEmail", () => { | |
describe("Google Authentication", () => { | ||
describe("GET /api/auth/auth/google", () => { | ||
it("should redirect to Google login page", async () => { | ||
|
||
sinon.stub(passport, "authenticate").returns((req: Request, res: Response) => { | ||
|
||
res.redirect("https://accounts.google.com/o/oauth2/v2/auth"); | ||
}); | ||
|
||
|
||
const res = await chai.request(app).get("/api/auth/auth/google"); | ||
|
||
expect(res).to.redirect; | ||
expect(res).to.redirectTo("https://accounts.google.com/o/oauth2/v2/auth"); | ||
|
||
|
||
(passport.authenticate as sinon.SinonStub).restore(); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
describe("Serialize and Deserialize User", () => { | ||
it("should serialize user", () => { | ||
const user = { id: "user-id", email: "[email protected]" }; | ||
passport.serializeUser((user, done) => { | ||
expect(user).to.deep.equal(user); | ||
done(null, user); | ||
}); | ||
}); | ||
|
||
it("should deserialize user", () => { | ||
const user = { id: "user-id", email: "[email protected]" }; | ||
passport.deserializeUser((user, done) => { | ||
expect(user).to.deep.equal(user); | ||
done(null, user); | ||
expect(res).to.have.status(302); | ||
expect(res).to.have.header("location").that.contains("https://accounts.google.com/o/oauth2/v2/auth"); | ||
}); | ||
}); | ||
}); | ||
}) |
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