Skip to content

Commit

Permalink
fix: dist and feat: user info
Browse files Browse the repository at this point in the history
  • Loading branch information
n9mi committed Sep 12, 2024
1 parent 3d00703 commit d73c7c4
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 494 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules
# Keep environment variables out of version control
.env

dist
dist/
20 changes: 10 additions & 10 deletions __tests__/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ describe("POST /auth/login", () => {
password: AuthTestUtils.user.password,
});

logger.debug(res.body);
expect(res.status).toBe(200);
expect(res.body.data.token).toBeDefined();
logger.debug(res.body);
expect(res.status).toBe(200);
expect(res.body.data.token).toBeDefined();

await AuthTestUtils.delete();
await AuthTestUtils.delete();
});

it("should return 400 - bad request", async () => {
Expand All @@ -82,9 +82,9 @@ describe("POST /auth/login", () => {
password: "",
});

logger.debug(res.body);
expect(res.status).toBe(400);
expect(res.body.errors).toBeDefined();
logger.debug(res.body);
expect(res.status).toBe(400);
expect(res.body.errors).toBeDefined();
});

it("should return 401 - login failed with wrong credentials", async () => {
Expand All @@ -95,9 +95,9 @@ describe("POST /auth/login", () => {
password: "randompassword",
});

logger.debug(res.body);
expect(res.status).toBe(401);
expect(res.body.errors).toBeDefined();
logger.debug(res.body);
expect(res.status).toBe(401);
expect(res.body.errors).toBeDefined();
});
});

Expand Down
68 changes: 68 additions & 0 deletions __tests__/user.spec.ts
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;
}
}
39 changes: 0 additions & 39 deletions dist/application/database.js

This file was deleted.

18 changes: 0 additions & 18 deletions dist/application/logger.js

This file was deleted.

18 changes: 0 additions & 18 deletions dist/application/web.js

This file was deleted.

47 changes: 0 additions & 47 deletions dist/controller/auth.js

This file was deleted.

23 changes: 0 additions & 23 deletions dist/controller/user.js

This file was deleted.

11 changes: 0 additions & 11 deletions dist/error/response.js

This file was deleted.

11 changes: 0 additions & 11 deletions dist/main.js

This file was deleted.

34 changes: 0 additions & 34 deletions dist/middleware/accessValidation.js

This file was deleted.

45 changes: 0 additions & 45 deletions dist/middleware/error.js

This file was deleted.

2 changes: 0 additions & 2 deletions dist/model/auth.js

This file was deleted.

2 changes: 0 additions & 2 deletions dist/model/common.js

This file was deleted.

2 changes: 0 additions & 2 deletions dist/model/user.js

This file was deleted.

Loading

0 comments on commit d73c7c4

Please sign in to comment.