Skip to content

Commit

Permalink
✅ test: 블로그 플랫폼별 통계 API 테스트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
Jo-Minseok committed Dec 2, 2024
1 parent 0302197 commit 6d3516a
Showing 1 changed file with 19 additions and 43 deletions.
62 changes: 19 additions & 43 deletions server/test/statistic/platform.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,37 @@
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { RedisService } from '../../src/common/redis/redis.service';
import { RssAcceptRepository } from '../../src/rss/rss.repository';
import { RssAcceptFixture } from '../fixture/rssAccept.fixture';

describe('Blog platform count statistic E2E Test : GET /api/statistic/platform', () => {
describe('GET /api/statistic/platform E2E Test', () => {
let app: INestApplication;
let rssAcceptRepository: RssAcceptRepository;
beforeAll(async () => {
app = global.testApp;
const redisService = app.get(RedisService);
rssAcceptRepository = app.get(RssAcceptRepository);
await redisService.redisClient.set('auth:test1234', 'test');
await Promise.all([
rssAcceptRepository.save(RssAcceptFixture.createRssAcceptFixture({})),
rssAcceptRepository.save(RssAcceptFixture.createRssAcceptFixture({}, 2)),
rssAcceptRepository.save(
RssAcceptFixture.createRssAcceptFixture({ blogPlatform: 'velog' }, 3),
),
]);
});

beforeEach(async () => {
await rssAcceptRepository
.createQueryBuilder()
.delete()
.from('rss_accept')
.execute();
});

it('데이터가 올바르게 출력된다.', async () => {
await rssAcceptRepository.save(RssAcceptFixture.createRssAcceptFixture({}));
await rssAcceptRepository.save(
RssAcceptFixture.createRssAcceptFixture({}, 2),
);
await rssAcceptRepository.save(
RssAcceptFixture.createRssAcceptFixture({ blogPlatform: 'velog' }, 3),
);
const response = await request(app.getHttpServer()).get(
'/api/statistic/platform',
);
expect(response.status).toBe(200);
expect(response.body).toStrictEqual({
message: '블로그 플랫폼 통계 조회 완료',
data: [
{
platform: 'etc',
count: 2,
},
{
platform: 'velog',
count: 1,
},
],
});
});
it('데이터가 없다.', async () => {
it('요청을 받으면 블로그 플랫폼별 통계 결과를 응답한다.', async () => {
const response = await request(app.getHttpServer()).get(
'/api/statistic/platform',
);
expect(response.status).toBe(200);
expect(response.body).toStrictEqual({
message: '블로그 플랫폼 통계 조회 완료',
data: [],
});
expect(response.body.data).toStrictEqual([
{
platform: 'etc',
count: 2,
},
{
platform: 'velog',
count: 1,
},
]);
});
});

0 comments on commit 6d3516a

Please sign in to comment.