-
Notifications
You must be signed in to change notification settings - Fork 5
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 #267 from boostcampwm-2024/test/rss-history-api
✅ test: RSS 승인/거절 기록 API 테스트 코드 작성
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 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 |
---|---|---|
@@ -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]); | ||
}); | ||
}); |
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,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]); | ||
}); | ||
}); |