Skip to content

Commit 4adb3ba

Browse files
committed
disAccount
1 parent 8100fc8 commit 4adb3ba

13 files changed

+279
-201
lines changed

Diff for: package-lock.json

+43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"start": "tsc && node ./dist/app.js",
1818
"lint": "npx eslint ./src",
1919
"lint-fix": "npx eslint --fix ./src",
20-
"lint-fix": "npx eslint --fix ./src",
2120
"dev": "tsnd --respawn ./src/app.ts",
2221
"test": "jest --detect-openHandles --config ./src/jest.config.ts --forceExit",
2322
"test:w": "jest --config ./src/jest.config.ts --watch",
@@ -68,6 +67,7 @@
6867
},
6968
"devDependencies": {
7069
"@types/bcrypt": "^5.0.0",
70+
"@types/connect-redis": "^0.0.20",
7171
"@types/express": "^4.17.16",
7272
"@types/express-session": "^1.17.6",
7373
"@types/jest": "^29.4.0",
@@ -81,12 +81,9 @@
8181
"@types/swagger-ui-express": "^4.1.3",
8282
"@typescript-eslint/eslint-plugin": "^5.54.0",
8383
"@typescript-eslint/parser": "^5.54.0",
84-
"@typescript-eslint/eslint-plugin": "^5.54.0",
85-
"@typescript-eslint/parser": "^5.54.0",
8684
"coveralls": "^3.1.1",
8785
"eslint": "^8.33.0",
8886
"eslint-plugin-prettier": "^4.2.1",
89-
"eslint-plugin-prettier": "^4.2.1",
9087
"jest": "^29.4.1",
9188
"nodemon": "^2.0.20",
9289
"pg": "^8.9.0",

Diff for: src/controllers/__tests__/authController.test.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,9 @@ describe("Math functions", () => {
122122
jest.setTimeout(20000);
123123

124124
test("200 status for disabling account", async () => {
125-
const signUp = await request(app).post("/signup").send({
126-
firstName: "Festo",
127-
lastName: "kabab",
128-
129-
password: "admin1",
130-
});
131-
console.log(signUp.body.token);
132-
133125
const login = await request(app).post("/login").send({
134-
email: "admin1234@gmail.com",
135-
password: "admin1",
126+
email: "admin@gmail.com",
127+
password: "adminpass",
136128
});
137129
const users = await request(app).get("/users");
138130
console.log(users);
@@ -146,8 +138,8 @@ describe("Math functions", () => {
146138
});
147139
test("404 status for unexisting user", async () => {
148140
const login = await request(app).post("/login").send({
149-
email: "admin1234@gmail.com",
150-
password: "admin1",
141+
email: "admin@gmail.com",
142+
password: "adminpass",
151143
});
152144
console.log(login.body);
153145
const unExist = await request(app)

Diff for: src/controllers/__tests__/cart.test.ts

+33-29
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
1-
import supertest from 'supertest'
2-
import createServer from '../../utils/server'
1+
import supertest from "supertest";
2+
import createServer from "../../utils/server";
33
// import app from '../../app';
44

55
const app = createServer();
6-
let token
6+
let token;
77
beforeAll(async () => {
8-
const res = await supertest(app)
9-
.post('/login')
10-
.send({
11-
12-
password: 'string',
13-
});
14-
token = res.body.token;
15-
}, 40000);
8+
const res = await supertest(app).post("/login").send({
9+
10+
password: "string",
11+
});
12+
token = res.body.token;
13+
}, 40000);
1614

17-
describe("cart" , ()=>{
18-
describe("add to cart", ()=>{
19-
test("in case user loggedin", async ()=>{
20-
const response: any = await supertest(app).post("/cart/add/so6JEwJcHlDh").set('Authorization', `Bearer ${token}`)
21-
expect(response.status).toBe(200)
22-
}, 40000)
23-
test("update cart", async ()=>{
24-
const response: any = await supertest(app).patch("/cart/9").set('Authorization', `Bearer ${token}`).send({"itemQuantity": 9})
25-
expect(response.status).toBe(200)
26-
}, 40000)
27-
test("update cart", async ()=>{
28-
const response: any = await supertest(app).patch("/cart/9").set('Authorization', `Bearer ${token}`).send({"itemQuantity": 10})
29-
expect(response.status).toBe(200)
30-
}, 40000)
31-
32-
})
33-
34-
})
15+
describe("cart", () => {
16+
describe("add to cart", () => {
17+
test("in case user loggedin", async () => {
18+
const response: any = await supertest(app)
19+
.post("/cart/add/so6JEwJcHlDh")
20+
.set("Authorization", `Bearer ${token}`);
21+
expect(response.status).toBe(200);
22+
}, 40000);
23+
test("update cart", async () => {
24+
const response: any = await supertest(app)
25+
.patch("/cart/9")
26+
.set("Authorization", `Bearer ${token}`)
27+
.send({ itemQuantity: 9 });
28+
expect(response.status).toBe(200);
29+
}, 40000);
30+
test("update cart", async () => {
31+
const response: any = await supertest(app)
32+
.patch("/cart/9")
33+
.set("Authorization", `Bearer ${token}`)
34+
.send({ itemQuantity: 10 });
35+
expect(response.status).toBe(200);
36+
}, 40000);
37+
});
38+
});

Diff for: src/controllers/__tests__/profilepage.test.ts

+77-69
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,80 @@
1-
import supertest from 'supertest'
2-
import createServer from '../../utils/server'
1+
import supertest from "supertest";
2+
import createServer from "../../utils/server";
33
/* eslint-disable @typescript-eslint/no-explicit-any */
4-
const app = createServer()
5-
let token
4+
const app = createServer();
5+
let token;
66
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);
1513

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

Comments
 (0)