|
1 |
| -import supertest from 'supertest' |
2 |
| -import createServer from '../../utils/server' |
| 1 | +import supertest from "supertest"; |
| 2 | +import createServer from "../../utils/server"; |
3 | 3 | /* eslint-disable @typescript-eslint/no-explicit-any */
|
4 |
| -const app = createServer() |
5 |
| -let token |
| 4 | +const app = createServer(); |
| 5 | +let token; |
6 | 6 | beforeAll(async () => {
|
7 |
| - const res = await supertest(app) |
8 |
| - .post('/login') |
9 |
| - .send({ |
10 |
| - |
11 |
| - password: 'string', |
12 |
| - }); |
13 |
| - token = res.body.token; |
14 |
| - }, 40000); |
| 7 | + const res = await supertest(app).post("/login").send({ |
| 8 | + |
| 9 | + password: "string", |
| 10 | + }); |
| 11 | + token = res.body.token; |
| 12 | +}, 40000); |
15 | 13 |
|
16 |
| - |
17 |
| -describe('profile page i', ()=>{ |
18 |
| - test("get all profiles", async ()=>{ |
19 |
| - const response = await supertest(app).get("/profiles") |
20 |
| - expect(response.status).toBe(200)},60000) |
21 |
| - test("single profile", async ()=>{ |
22 |
| - const response = await supertest(app).get("/profile/104") |
23 |
| - expect(response.status).toBe(200)}, 60000) |
24 |
| - test("incase of unregistered user",async ()=>{ |
25 |
| - const response = await supertest(app).get("/profile/1000") |
26 |
| - expect(response.status).toBe(400)}, 30000) |
27 |
| - describe("edit profile",()=>{ |
28 |
| - test("incase of no login", async ()=>{ |
29 |
| - const response = await supertest(app).patch("/profile/edit").send({birthdate : "2022-01-01"}) |
30 |
| - expect(response.status).toBe(401) |
31 |
| - }) |
32 |
| -}) |
33 |
| -describe("incase of a a logged in user", ()=>{ |
34 |
| - const profile={ |
35 |
| - profileDetails: { |
36 |
| - phoneNumber: "+250788000000", |
37 |
| - gender: "Female", |
38 |
| - birthdate: "2002-03-01", |
39 |
| - language: "kinyarwanda" |
40 |
| - }, |
41 |
| - billingAddress: { |
42 |
| - streetAddress: "kk509", |
43 |
| - city: "kigali", |
44 |
| - stateOrProvince: "kigali", |
45 |
| - zipOrPostalCode: "00000", |
46 |
| - country: "Rwanda" |
47 |
| - }, |
48 |
| - address: { |
49 |
| - streetAddress: "kk509", |
50 |
| - city: "kigali", |
51 |
| - stateOrProvince: "kigali", |
52 |
| - zipOrPostalCode: "00000", |
53 |
| - country: "Rwanda" |
54 |
| - } |
55 |
| - } |
56 |
| - test('with invalid date', async ()=>{ |
57 |
| - const response = await supertest(app).patch("/profile/edit").set('Authorization', `Bearer ${token}`).send({...profile,profileDetails:{ birthdate: "2022-01-30"}}) |
58 |
| - expect(response.status).toBe(406) |
59 |
| - }) |
60 |
| - test('with invalid date', async ()=>{ |
61 |
| - const response = await supertest(app).patch("/profile/edit").set('Authorization', `Bearer ${token}`).send({...profile,profileDetails:{ birthdate: "2022-001-30"}}) |
62 |
| - expect(response.status).toBe(406) |
63 |
| - }) |
64 |
| - test('with valid date', async ()=>{ |
65 |
| - const response = await supertest(app).patch("/profile/edit").set('Authorization', `Bearer ${token}`).send({...profile}) |
66 |
| - expect(response.status).toBe(200) |
67 |
| - }, 30000) |
68 |
| - |
69 |
| - |
70 |
| -}) |
71 |
| - |
72 |
| -}) |
| 14 | +describe("profile page i", () => { |
| 15 | + test("get all profiles", async () => { |
| 16 | + const response = await supertest(app).get("/profiles"); |
| 17 | + expect(response.status).toBe(200); |
| 18 | + }, 60000); |
| 19 | + test("single profile", async () => { |
| 20 | + const response = await supertest(app).get("/profile/104"); |
| 21 | + expect(response.status).toBe(200); |
| 22 | + }, 60000); |
| 23 | + test("incase of unregistered user", async () => { |
| 24 | + const response = await supertest(app).get("/profile/1000"); |
| 25 | + expect(response.status).toBe(400); |
| 26 | + }, 30000); |
| 27 | + describe("edit profile", () => { |
| 28 | + test("incase of no login", async () => { |
| 29 | + const response = await supertest(app) |
| 30 | + .patch("/profile/edit") |
| 31 | + .send({ birthdate: "2022-01-01" }); |
| 32 | + expect(response.status).toBe(401); |
| 33 | + }); |
| 34 | + }); |
| 35 | + describe("incase of a a logged in user", () => { |
| 36 | + const profile = { |
| 37 | + profileDetails: { |
| 38 | + phoneNumber: "+250788000000", |
| 39 | + gender: "Female", |
| 40 | + birthdate: "2002-03-01", |
| 41 | + language: "kinyarwanda", |
| 42 | + }, |
| 43 | + billingAddress: { |
| 44 | + streetAddress: "kk509", |
| 45 | + city: "kigali", |
| 46 | + stateOrProvince: "kigali", |
| 47 | + zipOrPostalCode: "00000", |
| 48 | + country: "Rwanda", |
| 49 | + }, |
| 50 | + address: { |
| 51 | + streetAddress: "kk509", |
| 52 | + city: "kigali", |
| 53 | + stateOrProvince: "kigali", |
| 54 | + zipOrPostalCode: "00000", |
| 55 | + country: "Rwanda", |
| 56 | + }, |
| 57 | + }; |
| 58 | + test("with invalid date", async () => { |
| 59 | + const response = await supertest(app) |
| 60 | + .patch("/profile/edit") |
| 61 | + .set("Authorization", `Bearer ${token}`) |
| 62 | + .send({ ...profile, profileDetails: { birthdate: "2022-01-30" } }); |
| 63 | + expect(response.status).toBe(406); |
| 64 | + }); |
| 65 | + test("with invalid date", async () => { |
| 66 | + const response = await supertest(app) |
| 67 | + .patch("/profile/edit") |
| 68 | + .set("Authorization", `Bearer ${token}`) |
| 69 | + .send({ ...profile, profileDetails: { birthdate: "2022-001-30" } }); |
| 70 | + expect(response.status).toBe(406); |
| 71 | + }); |
| 72 | + test("with valid date", async () => { |
| 73 | + const response = await supertest(app) |
| 74 | + .patch("/profile/edit") |
| 75 | + .set("Authorization", `Bearer ${token}`) |
| 76 | + .send({ ...profile }); |
| 77 | + expect(response.status).toBe(200); |
| 78 | + }, 30000); |
| 79 | + }); |
| 80 | +}); |
0 commit comments