Skip to content

Commit

Permalink
Merge branch 'ft-login-via-google-187584916' of https://github.com/at…
Browse files Browse the repository at this point in the history
…lp-rwanda/e-commerce-ninjas-bn into ft-login-via-google-187584916
  • Loading branch information
Jadowacu1 committed May 30, 2024
2 parents 69aef3a + ffa3c3d commit 2202717
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 49 deletions.
53 changes: 5 additions & 48 deletions src/modules/auth/test/auth.spec.ts
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);
Expand Down Expand Up @@ -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");
});
});
});
})
1 change: 0 additions & 1 deletion src/routes/authRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Router } from "express";
import googleAuth from "../services/googleAuth";
import authControllers from "../modules/auth/controller/authControllers";
Expand Down

0 comments on commit 2202717

Please sign in to comment.