-
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
26 changed files
with
112 additions
and
494 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 |
---|---|---|
|
@@ -14,4 +14,4 @@ PORT=3000 | |
BASE_URL_PATH=/api/v1 | ||
|
||
JWT_SECRET=secret-key | ||
JWT_EXPIRED_IN_MINUTES=100c | ||
JWT_EXPIRED_IN_MINUTES=100 |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ node_modules | |
# Keep environment variables out of version control | ||
.env | ||
|
||
dist | ||
dist/ |
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,68 @@ | ||
import prisma from "../src/application/database"; | ||
import bcrypt from "bcrypt"; | ||
import supertest from "supertest"; | ||
import { basePath, web } from "../src/application/web"; | ||
import logger from "../src/application/logger"; | ||
|
||
describe("GET /user/info", () => { | ||
let token: string = ""; | ||
|
||
beforeAll(async () => { | ||
token = await UserTestUtil.getToken(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await UserTestUtil.delete(); | ||
}); | ||
|
||
it("should return 200 - get user info", async () => { | ||
const res = await supertest(web) | ||
.get(`${basePath}/user/info`) | ||
.set('Authorization', `Bearer ${token}`); | ||
|
||
logger.debug(res.body); | ||
expect(res.status).toBe(200); | ||
expect(res.body.data.username).toBe(UserTestUtil.user.username); | ||
expect(res.body.data.name).toBe(UserTestUtil.user.name); | ||
}); | ||
}); | ||
|
||
class UserTestUtil { | ||
static user = { | ||
name: "user", | ||
username: "user", | ||
password: "password" | ||
}; | ||
|
||
static async create() { | ||
await prisma.user.create({ | ||
data: { | ||
name: UserTestUtil.user.name, | ||
username: UserTestUtil.user.username, | ||
password: await bcrypt.hash(UserTestUtil.user.password, 10), | ||
token: "" | ||
} | ||
}); | ||
} | ||
|
||
static async delete() { | ||
await prisma.user.deleteMany({ | ||
where: { | ||
username: UserTestUtil.user.username | ||
} | ||
}); | ||
} | ||
|
||
static async getToken() { | ||
await UserTestUtil.create(); | ||
|
||
const loginRes = await supertest(web) | ||
.post(`${basePath}/auth/login`) | ||
.send({ | ||
username: UserTestUtil.user.username, | ||
password: UserTestUtil.user.password, | ||
}); | ||
|
||
return loginRes.body.data.token; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.