-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
134 additions
and
86 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 |
---|---|---|
|
@@ -5,100 +5,119 @@ import app from "../../app"; | |
import USER from "../../models/User"; | ||
import { httpRequest, httpResponse } from "../mock/user.mock"; | ||
import GoogleController from "../googleAuthController"; | ||
import Tokens from "../../models/token" | ||
import Tokens from "../../models/token"; | ||
jest.setTimeout(70000); | ||
describe("Login via google", () => { | ||
afterAll(async () => { | ||
USER.destroy({ | ||
where: { email: "[email protected]" }, | ||
afterAll(async () => { | ||
USER.destroy({ | ||
where: { email: "[email protected]" }, | ||
}); | ||
}); | ||
test("redirect to google and authenticate", async () => { | ||
const data = await GoogleController.googleAuth( | ||
httpRequest("[email protected]"), | ||
httpResponse() | ||
); | ||
console.log(data); | ||
expect(data.body).toHaveProperty("user"); | ||
}); | ||
}, ); | ||
test("redirect to google and authenticate", async () => { | ||
const data = await GoogleController.googleAuth( | ||
httpRequest("[email protected]"), | ||
httpResponse() | ||
); | ||
console.log(data); | ||
expect(data.body).toHaveProperty("user"); | ||
}); | ||
|
||
test("testing register", async () => { | ||
const data: any = await GoogleController.googleAuth( | ||
httpRequest("[email protected]"), | ||
httpResponse() | ||
); | ||
console.log(data); | ||
expect(data.body).toHaveProperty("user"); | ||
}); | ||
test("testing 500", async () => { | ||
const data: any = await GoogleController.googleAuth( | ||
"helll", | ||
httpResponse() | ||
); | ||
expect(data.body.status).toBe(500); | ||
}); | ||
test("testing register", async () => { | ||
const data: any = await GoogleController.googleAuth( | ||
httpRequest("[email protected]"), | ||
httpResponse() | ||
); | ||
console.log(data); | ||
expect(data.body).toHaveProperty("user"); | ||
}); | ||
test("testing 500", async () => { | ||
const data: any = await GoogleController.googleAuth( | ||
"helll", | ||
httpResponse() | ||
); | ||
expect(data.body.status).toBe(500); | ||
}); | ||
}); | ||
|
||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
describe("Math functions", () => { | ||
it("should multiply 5 by 3", () => { | ||
const result = multiply(5, 3); | ||
expect(result).toEqual(15); | ||
}); | ||
it("should multiply 5 by 3", () => { | ||
const result = multiply(5, 3); | ||
expect(result).toEqual(15); | ||
}); | ||
|
||
it("should add 5 by 3", () => { | ||
const result = add(5, 3); | ||
expect(result).toEqual(8); | ||
}); | ||
it("should add 5 by 3", () => { | ||
const result = add(5, 3); | ||
expect(result).toEqual(8); | ||
}); | ||
}); | ||
// reset password coontroller tests | ||
describe('reset password', () => { | ||
describe('send link to email', () => { | ||
test('incase of unregistered email', async () => { | ||
const response = await supertest(app) | ||
.post('/resetpassword/link') | ||
.send({ email: '[email protected]' }) | ||
expect(response.status).toBe(400) | ||
}, 30000) // timeout 30 seconds | ||
}) | ||
test('incase of a registered email', async () => { | ||
const response = await supertest(app) | ||
.post('/resetpassword/link') | ||
.send({ email: '[email protected]' }) | ||
expect(response.status).toBe(200) | ||
}, 20000) | ||
test('incase invalid email input', async () => { | ||
const response = await supertest(app) | ||
.post('/resetpassword/link') | ||
.send({ email: 'rukundjoseph' }) | ||
expect(response.status).toBe(400) | ||
}, 20000) | ||
describe('add token and change password', () => { | ||
test('incase incorrect token', async () => { | ||
const response = await supertest(app) | ||
.patch('/changepassword/[email protected]/65328dba23') | ||
.send({ newpassword: 'newpassword', confirmpass: 'newpassword' }) | ||
expect(response.status).toBe(401) | ||
}, 20000) | ||
test('incase of a unmatching passwords', async () => { | ||
const user: any = await USER.findOne({ | ||
where: { email: '[email protected]' }, | ||
}) | ||
const token: any = await Tokens.findOne({ where: { userId: `${user.id}` } }) | ||
const response = await supertest(app) | ||
.patch(`/changepassword/[email protected]/${token.token}`) | ||
.send({ newpassword: 'newpas', confirmpass: 'newpaa' }) | ||
expect(response.status).toBe(400) | ||
}) | ||
test('incase of a valid token and email', async () => { | ||
const user: any = await USER.findOne({ | ||
where: { email: '[email protected]' }, | ||
}) | ||
const token: any = await Tokens.findOne({ where: { userId: `${user.id}` } }) | ||
const response = await supertest(app) | ||
.patch(`/changepassword/[email protected]/${token.token}`) | ||
.send({ newpassword: 'newpas', confirmpass: 'newpas' }) | ||
expect(response.status).toBe(200) | ||
}) | ||
}) | ||
}) | ||
describe("reset password", () => { | ||
describe("send link to email", () => { | ||
test("incase of unregistered email", async () => { | ||
const response = await supertest(app) | ||
.post("/resetpassword/link") | ||
.send({ email: "[email protected]" }); | ||
expect(response.status).toBe(400); | ||
}, 30000); // timeout 30 seconds | ||
}); | ||
test("incase of a registered email", async () => { | ||
const response = await supertest(app) | ||
.post("/resetpassword/link") | ||
.send({ email: "[email protected]" }); | ||
expect(response.status).toBe(200); | ||
}, 20000); | ||
test("incase invalid email input", async () => { | ||
const response = await supertest(app) | ||
.post("/resetpassword/link") | ||
.send({ email: "rukundjoseph" }); | ||
expect(response.status).toBe(400); | ||
}, 20000); | ||
describe("add token and change password", () => { | ||
test("incase incorrect token", async () => { | ||
const response = await supertest(app) | ||
.patch("/changepassword/[email protected]/65328dba23") | ||
.send({ | ||
newpassword: "newpassword", | ||
confirmpass: "newpassword", | ||
}); | ||
expect(response.status).toBe(401); | ||
}, 20000); | ||
test("incase of a unmatching passwords", async () => { | ||
const user: any = await USER.findOne({ | ||
where: { email: "[email protected]" }, | ||
}); | ||
const token: any = await Tokens.findOne({ | ||
where: { userId: `${user.id}` }, | ||
}); | ||
const response = await supertest(app) | ||
.patch( | ||
`/changepassword/[email protected]/${token.token}` | ||
) | ||
.send({ newpassword: "newpas", confirmpass: "newpaa" }); | ||
expect(response.status).toBe(400); | ||
}); | ||
test("incase of a valid token and email", async () => { | ||
const user: any = await USER.findOne({ | ||
where: { email: "[email protected]" }, | ||
}); | ||
const token: any = await Tokens.findOne({ | ||
where: { userId: `${user.id}` }, | ||
}); | ||
const response = await supertest(app) | ||
.patch( | ||
`/changepassword/[email protected]/${token.token}` | ||
) | ||
.send({ newpassword: "newpas", confirmpass: "newpas" }); | ||
expect(response.status).toBe(200); | ||
}); | ||
}); | ||
}); | ||
|
||
// logout tests | ||
describe("Logout user", () => { | ||
test("success logout", async () => { | ||
const response = await supertest(app).post("/logout"); | ||
expect(response.status).toBe(200); | ||
}, 30000); // timeout 30 seconds | ||
}); |
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,29 @@ | ||
import supertest from "supertest"; | ||
import createServer from "../../utils/server"; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const app = createServer(); | ||
let token; | ||
beforeAll(async () => { | ||
const res = await supertest(app).post("/login").send({ | ||
email: "[email protected]", | ||
password: "adminpass", | ||
}); | ||
token = res.body.token; | ||
}, 40000); | ||
|
||
describe("Seller Collection", () => { | ||
describe("Seller update product availability", () => { | ||
test("Seller update non-existing product", async () => { | ||
const response = await supertest(app).patch( | ||
"/products/delete/72753" | ||
); | ||
expect(response.status).toBe(404); | ||
}, 60000); | ||
test("unauthorised access", async () => { | ||
const response = await supertest(app).patch( | ||
"/products/delete/72753" | ||
); | ||
expect(response.status).toBe(404); | ||
}, 60000); | ||
}); | ||
}); |