-
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
1 parent
55037cb
commit ea4cf1d
Showing
7 changed files
with
70 additions
and
12 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
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,12 @@ | ||
NODE_ENV=development | ||
PORT=5000 | ||
ALLOW_ORIGIN="*" | ||
ALLOW_METHODS="GET,PUT,POST,PATCH,DELETE,HEAD,OPTIONS" | ||
ALLOW_HEADERS="Content-Type,Cache-Control,Expires" | ||
JWT_SECRET=SUPERSECRET | ||
DB_NAME="test_express_app" | ||
DB_HOST=localhost | ||
DB_PORT=5432 | ||
DB_USERNAME=postgres | ||
DB_PASSWORD=password | ||
DB_LOGGING="" |
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
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
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
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,3 @@ | ||
import * as dotenv from "dotenv"; | ||
|
||
dotenv.config({ path: `.env.test`, override: true }); |
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,42 @@ | ||
import supertest, { SuperTest, Test } from "supertest"; | ||
import { DataSource } from "typeorm"; | ||
import app from "../src/app"; | ||
import { AppDataSource, getDbConfig } from "../src/config/db"; | ||
import { createDatabase } from "typeorm-extension"; | ||
|
||
const url = "/api/v1/user/signup"; | ||
let db: DataSource; | ||
|
||
describe(`${url}`, () => { | ||
let agent: SuperTest<Test>; | ||
|
||
beforeAll(async () => { | ||
await createDatabase({ options: getDbConfig(), ifNotExist: true }); | ||
db = await AppDataSource.initialize(); | ||
agent = supertest(app); | ||
}); | ||
|
||
afterAll((done) => { | ||
db.dropDatabase().then(() => { | ||
db.destroy(); | ||
done(); | ||
}); | ||
}); | ||
|
||
test("should sign up successfully when user data is valid", async () => { | ||
const test = await agent | ||
.post(url) | ||
.set("Content-Type", "application/json") | ||
.send({ | ||
username: `john1`, | ||
firstName: "John", | ||
lastName: "Johnson", | ||
password: "123123", | ||
}) | ||
.expect(201); | ||
|
||
expect(test.body.message).toBe("Sign up successful"); | ||
expect(test.body.data).toBeTruthy(); | ||
expect(test.body.code).toBe(201); | ||
}); | ||
}); |