-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): implement Google auth strategy
- Integrate Google ID into the user model for OAuth. - Set up Google authentication strategy with Passport. - Establish '/auth/google' and '/auth/google/callback' routes. - Develop controller logic for handling Google OAuth. [Finishes #187419056]
- Loading branch information
1 parent
40e9cba
commit b20cb8d
Showing
16 changed files
with
440 additions
and
136 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,59 @@ | ||
import app from "../app"; | ||
import request from "supertest"; | ||
import { connectionToDatabase } from "../database/config/db.config"; | ||
import { deleteTableData } from "../utils/database.utils"; | ||
import { User } from "../database/models/User"; | ||
import { google_profile } from "../mock/static"; | ||
jest.setTimeout(30000); | ||
|
||
function logErrors( | ||
err: { stack: any }, | ||
_req: any, | ||
_res: any, | ||
next: (arg0: any) => void, | ||
) { | ||
console.log(err.stack); | ||
next(err); | ||
} | ||
|
||
const Jest_request = request(app.use(logErrors)); | ||
|
||
describe("GOOGLE API TEST", () => { | ||
beforeAll(async () => { | ||
await connectionToDatabase(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await deleteTableData(User, "users"); | ||
}); | ||
|
||
it("should simulate Google oAuth flow and return 302", async () => { | ||
const response = await Jest_request.get("/api/v1/users/auth/google").expect( | ||
302, | ||
); | ||
expect(response.header.location).toStrictEqual( | ||
"/api/v1/users/auth/google/callback", | ||
); | ||
expect(response.redirect).toBeTruthy(); | ||
expect(response.header["set-cookie"]).toBeDefined(); | ||
}); | ||
|
||
it("should handle google oauth callback and display user data to log in or to create user", async () => { | ||
const response = await Jest_request.get( | ||
"/api/v1/users/auth/google/callback", | ||
).query(google_profile); | ||
expect(response.status).toBe(302); | ||
|
||
const google_url = response.header.location; | ||
|
||
expect(google_url).toBeDefined(); | ||
}); | ||
|
||
it("Welcome to Hacker's e-commerce backend and return 200", async () => { | ||
const { body } = await Jest_request.get("/").expect(200); | ||
}); | ||
|
||
it("should display login home page and return 200", async () => { | ||
const { body } = await Jest_request.get("/api/v1/").expect(200); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.