Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ test: 최신 피드 업데이트 API 테스트 코드 작성 #282

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions server/test/feed/feed.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as request from 'supertest';
import { FeedFixture } from '../fixture/feed.fixture';
import { FeedRepository } from '../../src/feed/feed.repository';
import { RssAcceptRepository } from '../../src/rss/rss.repository';
import { RssFixture } from '../fixture/rss.fixture';
import { RssAcceptFixture } from '../fixture/rssAccept.fixture';

describe('GET api/feed E2E Test', () => {
let app: INestApplication;
Expand All @@ -14,7 +14,9 @@ describe('GET api/feed E2E Test', () => {
const feedRepository = app.get(FeedRepository);
const rssAcceptRepository = app.get(RssAcceptRepository);

const blog = await rssAcceptRepository.save(RssFixture.createRssFixture());
const blog = await rssAcceptRepository.save(
RssAcceptFixture.createRssAcceptFixture(),
);

const feeds = Array.from({ length: latestId }).map((_, i) => {
return FeedFixture.createFeedFixture(blog, _, i + 1);
Expand Down
6 changes: 4 additions & 2 deletions server/test/feed/feedId.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RedisService } from '../../src/common/redis/redis.service';
import { FeedRepository } from '../../src/feed/feed.repository';
import { RssAcceptRepository } from '../../src/rss/rss.repository';
import { FeedFixture } from '../fixture/feed.fixture';
import { RssFixture } from '../fixture/rss.fixture';
import { RssAcceptFixture } from '../fixture/rssAccept.fixture';

describe('POST /api/feed/:feedId E2E Test', () => {
let app: INestApplication;
Expand All @@ -20,7 +20,9 @@ describe('POST /api/feed/:feedId E2E Test', () => {
const feedRepository = app.get(FeedRepository);
const rssAcceptRepository = app.get(RssAcceptRepository);

const blog = await rssAcceptRepository.save(RssFixture.createRssFixture());
const blog = await rssAcceptRepository.save(
RssAcceptFixture.createRssAcceptFixture(),
);

const feeds = Array.from({ length: latestId }).map((_, i) => {
return FeedFixture.createFeedFixture(blog, _, i + 1);
Expand Down
22 changes: 0 additions & 22 deletions server/test/feed/fixture/feedFixture.ts

This file was deleted.

63 changes: 63 additions & 0 deletions server/test/feed/recent.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as request from 'supertest';
import { INestApplication } from '@nestjs/common';
import { Feed } from '../../src/feed/feed.entity';
import { RssAcceptRepository } from '../../src/rss/rss.repository';
import { RssAcceptFixture } from '../fixture/rssAccept.fixture';
import { FeedFixture } from '../fixture/feed.fixture';
import { FeedRepository } from '../../src/feed/feed.repository';
import { RedisService } from '../../src/common/redis/redis.service';
import { redisKeys } from '../../src/common/redis/redis.constant';

describe('GET /api/feed/recent E2E Test', () => {
let app: INestApplication;
let rssAcceptRepository: RssAcceptRepository;

beforeAll(async () => {
app = global.testApp;
rssAcceptRepository = app.get(RssAcceptRepository);
});

it('최신 피드 업데이트 요청이 들어오면 내림차순 정렬된 피드 배열을 반환한다.', async () => {
//given
const blog = await rssAcceptRepository.save(
RssAcceptFixture.createRssAcceptFixture(),
);
const feedRepository = app.get(FeedRepository);
const feedList: Feed[] = [];
const baseDate = new Date();
for (let i = 0; i < 2; i++) {
const date = new Date(baseDate);
date.setHours(date.getHours() + i);
feedList.push(
FeedFixture.createFeedFixture(blog, { createdAt: date }, i + 1),
);
}
const redisService = app.get(RedisService);
const feeds = await feedRepository.save(feedList);
const pipeLine = redisService.redisClient.pipeline();
pipeLine.set(redisKeys.FEED_RECENT_KEY, 'true');
pipeLine.hset(`feed:recent:${feeds[0]['id']}`, feeds[0]);
pipeLine.hset(`feed:recent:${feeds[1]['id']}`, feeds[1]);
await pipeLine.exec();

//when
const response = await request(app.getHttpServer()).get('/api/feed/recent');

//then
expect(response.status).toBe(200);
expect(response.body.data.map((feed) => feed.id)).toStrictEqual(['2', '1']);
});

it('피드가 없다면 빈 배열을 반환한다.', async () => {
//given
const redisService = app.get(RedisService);
await redisService.redisClient.set(redisKeys.FEED_RECENT_KEY, 'false');

//when
const response = await request(app.getHttpServer()).get('/api/feed/recent');

//then
expect(response.status).toBe(200);
expect(response.body.data.map((feed) => feed.id)).toStrictEqual([]);
});
});
Loading