Skip to content

Commit 0193ee7

Browse files
committed
Bug - fixed handler middleware that was causing cannot set header error
1 parent 9f64298 commit 0193ee7

40 files changed

+2329
-2328
lines changed

server/jest.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-undef */
22
/** @type {import('ts-jest').JestConfigWithTsJest} */
33
module.exports = {
4-
preset: "ts-jest",
5-
testEnvironment: "node",
4+
preset: "ts-jest",
5+
testEnvironment: "node",
66
};

server/lib/prisma.db.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare global {
1111
}
1212

1313
if (!global.__db) {
14-
global.__db = new PrismaClient();
14+
global.__db = new PrismaClient();
1515
}
1616

1717
const db: PrismaClient = global.__db;

server/prisma/seed.ts

+63-63
Original file line numberDiff line numberDiff line change
@@ -21,82 +21,82 @@ type Review = {
2121
};
2222

2323
function getUsers(): Array<User> {
24-
return [
25-
{
26-
27-
firstName: "john",
28-
lastName: "adams",
29-
password: "test@Password",
30-
},
31-
{
32-
33-
firstName: "mike",
34-
lastName: "jason",
35-
password: "test@Password",
36-
},
37-
];
24+
return [
25+
{
26+
27+
firstName: "john",
28+
lastName: "adams",
29+
password: "test@Password",
30+
},
31+
{
32+
33+
firstName: "mike",
34+
lastName: "jason",
35+
password: "test@Password",
36+
},
37+
];
3838
}
3939

4040
function getMovies(): Array<Movie> {
41-
return [
42-
{
43-
title: "Oppenheimer",
44-
poster:
41+
return [
42+
{
43+
title: "Oppenheimer",
44+
poster:
4545
"https://upload.wikimedia.org/wikipedia/en/4/4a/Oppenheimer_%28film%29.jpg",
46-
trailer: "https://www.youtube.com/watch?v=uYPbbksJxIg",
47-
description:
46+
trailer: "https://www.youtube.com/watch?v=uYPbbksJxIg",
47+
description:
4848
"During World War II, Lt. Gen. Leslie Groves Jr. appoints physicist J. Robert Oppenheimer to work on the top-secret Manhattan Project. Oppenheimer and a team of scientists spend years developing and designing the atomic bomb. Their work comes to fruition on July 16, 1945, as they witness the world's first nuclear explosion, forever changing the course of history.",
49-
},
50-
{
51-
title: "Napoleon",
52-
poster:
49+
},
50+
{
51+
title: "Napoleon",
52+
poster:
5353
"https://upload.wikimedia.org/wikipedia/en/2/2e/Napoleon_Film_poster.jpg",
54-
trailer: "https://www.youtube.com/watch?v=OAZWXUkrjPc",
55-
description:
54+
trailer: "https://www.youtube.com/watch?v=OAZWXUkrjPc",
55+
description:
5656
"A look at the military commander's origins and his swift, ruthless climb to emperor, viewed through the prism of his addictive and often volatile relationship with his wife and one true love, Josephine",
57-
},
58-
{
59-
title: "The Last Kingdom Seven Kings Must Die",
60-
poster:
57+
},
58+
{
59+
title: "The Last Kingdom Seven Kings Must Die",
60+
poster:
6161
"https://upload.wikimedia.org/wikipedia/en/1/15/Last_kingdom_seven_kings_must_die.png",
62-
trailer: "https://www.youtube.com/watch?v=eqCYw_o5lng",
63-
description:
62+
trailer: "https://www.youtube.com/watch?v=eqCYw_o5lng",
63+
description:
6464
"Uhtred of Bebbanburg is given a task by King Edward to kill the seven kings who have formed an alliance against him. Uhtred is forced to face the greatest enemy he has ever encountered, and the fate of Wessex hangs in the balance.",
65-
},
66-
];
65+
},
66+
];
6767
}
6868

6969
async function seed() {
70-
console.log("Seeding database...");
70+
console.log("Seeding database...");
7171

72-
const users = getUsers();
73-
users.forEach(async (user) => {
74-
console.log("Seeding users...");
75-
await db.user.create({
76-
data: {
77-
...user,
78-
},
79-
});
80-
});
81-
const testUser = await db.user.findFirst({
82-
where: {
83-
84-
},
85-
});
86-
const movies = getMovies();
87-
console.log("Seeding movies...");
88-
if (!testUser) throw new Error("User not found");
89-
movies.forEach(async (movie) => {
90-
await db.movie.create({
91-
data: {
92-
title: movie.title,
93-
poster: movie.poster,
94-
trailer: movie.trailer,
95-
description: movie.description,
96-
userId: testUser.id,
97-
},
98-
});
99-
});
72+
const users = getUsers();
73+
users.forEach(async (user) => {
74+
console.log("Seeding users...");
75+
await db.user.create({
76+
data: {
77+
...user,
78+
},
79+
});
80+
});
81+
const testUser = await db.user.findFirst({
82+
where: {
83+
84+
},
85+
});
86+
const movies = getMovies();
87+
console.log("Seeding movies...");
88+
if (!testUser) throw new Error("User not found");
89+
movies.forEach(async (movie) => {
90+
await db.movie.create({
91+
data: {
92+
title: movie.title,
93+
poster: movie.poster,
94+
trailer: movie.trailer,
95+
description: movie.description,
96+
userId: testUser.id,
97+
},
98+
});
99+
});
100100
}
101101

102102
seed();

server/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { httpServer } from "./src/app";
22
import { config } from "./src/config/env.config";
33
const port = config.PORT;
44
httpServer.listen(port, () => {
5-
console.log(`[server]: Server is running at http://localhost:${port}`);
5+
console.log(`[server]: Server is running at http://localhost:${port}`);
66
});

server/src/__tests__/integration/index.test.ts

+27-27
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ import request from "supertest";
22

33
import app from "../../app";
44
describe("GET - Movie api - 200 OK", () => {
5-
let token: string;
6-
const testUser = {
7-
8-
firstName: "test",
9-
lastName: "test",
10-
password: "123",
11-
};
12-
beforeAll(async () => {
13-
const registerTestUser = await request(app)
14-
.post("/api/register")
15-
.send(testUser);
16-
const loginTestUser = await request(app).post("/api/login").send({
17-
email: testUser.email,
18-
password: testUser.password,
19-
});
20-
token = loginTestUser.body.token;
21-
});
22-
afterAll(async () => {
23-
await request(app).delete(`/api/user/${testUser.email}`);
24-
});
25-
it("should return 200 OK", async () => {
26-
const response = await request(app)
27-
.get("/api")
28-
.set("authorization", `Bearer ${token}`);
29-
expect(response.status).toBe(200);
30-
expect(response.text).toEqual("Movie API");
31-
});
5+
let token: string;
6+
const testUser = {
7+
8+
firstName: "test",
9+
lastName: "test",
10+
password: "123",
11+
};
12+
beforeAll(async () => {
13+
const registerTestUser = await request(app)
14+
.post("/api/register")
15+
.send(testUser);
16+
const loginTestUser = await request(app).post("/api/login").send({
17+
email: testUser.email,
18+
password: testUser.password,
19+
});
20+
token = loginTestUser.body.token;
21+
});
22+
afterAll(async () => {
23+
await request(app).delete(`/api/user/${testUser.email}`);
24+
});
25+
it("should return 200 OK", async () => {
26+
const response = await request(app)
27+
.get("/api")
28+
.set("authorization", `Bearer ${token}`);
29+
expect(response.status).toBe(200);
30+
expect(response.text).toEqual("Movie API");
31+
});
3232
});

0 commit comments

Comments
 (0)