-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
7,340 additions
and
2,980 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import request from "supertest"; | ||
import { spawn, ChildProcess } from "child_process"; | ||
import path from "path"; | ||
|
||
let server: ChildProcess; | ||
|
||
beforeAll(async () => { | ||
const serverScript = path.resolve(__dirname, "../../customServer.ts"); | ||
server = spawn("ts-node", [serverScript]); | ||
|
||
// Wait for the server to be ready | ||
await new Promise((resolve, reject) => { | ||
server.stdout?.on("data", (data) => { | ||
if (data.toString().includes("> Ready on http://localhost:3000")) { | ||
resolve(null); | ||
} | ||
}); | ||
server.stderr?.on("data", (data) => { | ||
reject(data.toString()); | ||
}); | ||
}); | ||
}, 30000); // Increase the timeout to 30 seconds | ||
|
||
afterAll(() => { | ||
if (server) { | ||
server.kill(); | ||
} | ||
}); | ||
|
||
describe("registerUser API Integration Test", () => { | ||
it("registers a new user successfully", async () => { | ||
const data = { | ||
email: "[email protected]", | ||
password: "Password@123", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
dateOfBirth: new Date(1990, 1, 1), | ||
}; | ||
|
||
const response = await request("http://localhost:3000") | ||
.post("/api/auth/register") | ||
.send(data) | ||
.set("Accept", "application/json"); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body).toEqual( | ||
expect.objectContaining({ | ||
message: "User registered successfully", | ||
// Other expected response properties | ||
}), | ||
); | ||
}); | ||
|
||
it("returns error for already used email", async () => { | ||
const data = { | ||
email: "[email protected]", | ||
password: "Password@123", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
dateOfBirth: new Date(1990, 1, 1), | ||
}; | ||
|
||
const response = await request("http://localhost:3000") | ||
.post("/api/auth/register") | ||
.send(data) | ||
.set("Accept", "application/json"); | ||
|
||
expect(response.status).toBe(400); | ||
expect(response.body).toEqual( | ||
expect.objectContaining({ | ||
message: "Email already in use", | ||
}), | ||
); | ||
}); | ||
|
||
// Add more tests for other use cases as needed | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { createServer } = require("http"); | ||
const next = require("next"); | ||
const { parse } = require("url"); | ||
|
||
const dev = process.env.NODE_ENV !== "production"; | ||
const app = next({ dev }); | ||
const handle = app.getRequestHandler(); | ||
|
||
app.prepare().then(() => { | ||
const server = createServer((req: { url: any }, res: any) => { | ||
const parsedUrl = parse(req.url, true); | ||
handle(req, res, parsedUrl); | ||
}); | ||
|
||
server.listen(3004, (err: any) => { | ||
if (err) throw err; | ||
console.log("> Ready on http://localhost:3004"); | ||
}); | ||
}); |
Oops, something went wrong.