-
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.
Merge pull request #192 from boostcampwm2023/feat/183-stat-diaries-ye…
…ar-api [Feat] 특정 연도에 대한 날짜별 일기 작성 통계 API 구현
- Loading branch information
Showing
5 changed files
with
178 additions
and
4 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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import { sentimentStatus } from "src/utils/enum"; | ||
|
||
export class TagInfoDto { | ||
id: number; | ||
count: number; | ||
tag: string; | ||
} | ||
|
||
export class DiariesInfoDto { | ||
sentiment: sentimentStatus; | ||
date: Date; | ||
} | ||
|
||
export class StatTagDto { | ||
[key: string]: ({ rank: number } & TagInfoDto) | {}; | ||
} | ||
|
||
export class DiariesDateDto { | ||
[dateString: string]: { sentiment: sentimentStatus; count: Number }; | ||
} |
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,89 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { INestApplication } from "@nestjs/common"; | ||
import * as request from "supertest"; | ||
import { ValidationPipe } from "@nestjs/common"; | ||
import { typeORMTestConfig } from "src/configs/typeorm.test.config"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { RedisModule } from "@liaoliaots/nestjs-redis"; | ||
import { AuthModule } from "src/auth/auth.module"; | ||
import { StatModule } from "src/stat/stat.module"; | ||
import { DiariesModule } from "src/diaries/diaries.module"; | ||
|
||
describe("[연도별, 날짜별 일기 작성 조회] /stat/diaries/:year GET e2e 테스트", () => { | ||
let app: INestApplication; | ||
let accessToken: string; | ||
|
||
beforeAll(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [ | ||
TypeOrmModule.forRoot(typeORMTestConfig), | ||
RedisModule.forRoot({ | ||
readyLog: true, | ||
config: { | ||
host: "223.130.129.145", | ||
port: 6379, | ||
}, | ||
}), | ||
StatModule, | ||
AuthModule, | ||
DiariesModule, | ||
], | ||
}).compile(); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
app.enableCors(); | ||
app.useGlobalPipes(new ValidationPipe()); | ||
|
||
await app.init(); | ||
|
||
const signInPost = await request(app.getHttpServer()) | ||
.post("/auth/signin") | ||
.send({ | ||
userId: "commonUser", | ||
password: process.env.COMMON_USER_PASS, | ||
}); | ||
|
||
accessToken = signInPost.body.accessToken; | ||
|
||
for (let i = 1; i <= 3; i++) { | ||
await request(app.getHttpServer()) | ||
.post("/diaries") | ||
.set("Authorization", `Bearer ${accessToken}`) | ||
.send({ | ||
title: "stat test", | ||
content: "나는 행복해.", | ||
point: "1.5,5.5,10.55", | ||
date: `2023-08-0${i}`, | ||
tags: ["tagTest"], | ||
shapeUuid: "0c99bbc6-e404-464b-a310-5bf0fa0f0fa7", | ||
}); | ||
} | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
||
it("정상 요청 시 200 OK 응답", async () => { | ||
const postResponse = await request(app.getHttpServer()) | ||
.get("/stat/diaries/2023") | ||
.set("Authorization", `Bearer ${accessToken}`) | ||
.expect(200); | ||
|
||
expect(Object.keys(postResponse.body).includes("2023-08-01")).toEqual(true); | ||
expect(Object.keys(postResponse.body).includes("2023-08-02")).toEqual(true); | ||
expect(Object.keys(postResponse.body).includes("2023-08-03")).toEqual(true); | ||
}); | ||
|
||
it("액세스 토큰 없이 요청 시 401 Unauthorized 응답", async () => { | ||
const postResponse = await request(app.getHttpServer()) | ||
.get("/stat/diaries/2023") | ||
.expect(401); | ||
|
||
expect(postResponse.body).toEqual({ | ||
error: "Unauthorized", | ||
message: "비로그인 상태의 요청입니다.", | ||
statusCode: 401, | ||
}); | ||
}); | ||
}); |
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