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: RSS 승인/거절 기록 API 테스트 코드 작성 #267

Merged
merged 3 commits into from
Dec 3, 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
48 changes: 48 additions & 0 deletions server/test/rss/history/accept.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { RssAcceptRepository } from '../../../src/rss/rss.repository';
import { RssAccept } from '../../../src/rss/rss.entity';
import { RssAcceptFixture } from '../../fixture/rssAccept.fixture';
import { RedisService } from '../../../src/common/redis/redis.service';

describe('GET /api/rss/history/accept E2E Test', () => {
let app: INestApplication;
beforeAll(async () => {
app = global.testApp;
const rssAcceptRepository = app.get(RssAcceptRepository);
const redisService = app.get(RedisService);
const rssAccepts: RssAccept[] = [];
for (let i = 1; i <= 2; i++) {
rssAccepts.push(RssAcceptFixture.createRssAcceptFixture({}, i));
}
await Promise.all([
rssAcceptRepository.save(rssAccepts),
redisService.redisClient.sadd('auth:sid', 'test1234'),
]);
});

it('관리자 로그인이 되어있지 않으면 조회할 수 없다.', async () => {
// when
const noCookieResponse = await request(app.getHttpServer()).get(
'/api/rss/history/accept',
);
const noSessionResponse = await request(app.getHttpServer())
.get('/api/rss/history/accept')
.set('Cookie', 'sessionId=invalid');

// then
expect(noCookieResponse.status).toBe(401);
expect(noSessionResponse.status).toBe(401);
});

it('관리자 로그인이 되어 있으면 최신순으로 기록 데이터를 응답한다.', async () => {
// when
const response = await request(app.getHttpServer())
.get('/api/rss/history/accept')
.set('Cookie', 'sessionId=sid');

// then
expect(response.status).toBe(200);
expect(response.body.data.map((item) => item.id)).toStrictEqual([2, 1]);
});
});
48 changes: 48 additions & 0 deletions server/test/rss/history/reject.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { RedisService } from '../../../src/common/redis/redis.service';
import { RssRejectRepository } from '../../../src/rss/rss.repository';
import { RssReject } from '../../../src/rss/rss.entity';
import { RssRejectFixture } from '../../fixture/rssReject.fixture';

describe('GET /api/rss/history/reject E2E Test', () => {
let app: INestApplication;
beforeAll(async () => {
app = global.testApp;
const rssRejectRepository = app.get(RssRejectRepository);
const redisService = app.get(RedisService);
const rssAccepts: RssReject[] = [];
for (let i = 1; i <= 2; i++) {
rssAccepts.push(RssRejectFixture.createRssRejectFixture({}, i));
}
await Promise.all([
rssRejectRepository.save(rssAccepts),
redisService.redisClient.sadd('auth:sid', 'test1234'),
]);
});

it('관리자 로그인이 되어있지 않으면 조회할 수 없다.', async () => {
// when
const noCookieResponse = await request(app.getHttpServer()).get(
'/api/rss/history/reject',
);
const noSessionResponse = await request(app.getHttpServer())
.get('/api/rss/history/reject')
.set('Cookie', 'sessionId=invalid');

// then
expect(noCookieResponse.status).toBe(401);
expect(noSessionResponse.status).toBe(401);
});

it('관리자 로그인이 되어 있으면 최신순으로 기록 데이터를 응답한다.', async () => {
// when
const response = await request(app.getHttpServer())
.get('/api/rss/history/reject')
.set('Cookie', 'sessionId=sid');

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