Skip to content

Commit

Permalink
Merge pull request #267 from boostcampwm-2024/test/rss-history-api
Browse files Browse the repository at this point in the history
✅ test: RSS 승인/거절 기록 API 테스트 코드 작성
  • Loading branch information
Jo-Minseok authored Dec 3, 2024
2 parents 547bb90 + a029cbe commit f1a2dbe
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
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]);
});
});

0 comments on commit f1a2dbe

Please sign in to comment.