-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#40 박정훈 테스트 코드
- Loading branch information
Showing
4 changed files
with
325 additions
and
7 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
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
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,43 @@ | ||
import app from '../index'; | ||
import dotenv from 'dotenv'; | ||
import req from 'supertest'; | ||
dotenv.config(); | ||
|
||
/** | ||
* 배너 조회 | ||
* 200, 401 케이스 | ||
*/ | ||
describe('GET /banner', () => { | ||
// 배너 조회 200 케이스 | ||
it('배너 조회 - 성공', (done) => { | ||
req(app) | ||
.get('/api/banner') | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.expect(200) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 배너 조회 401 케이스 | ||
it('배너 조회 - 유효하지 않은 토큰', (done) => { | ||
req(app) | ||
.get('/api/banner') | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `Bearer process.env.TEST_TOKEN` }) | ||
.expect(401) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
}); |
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,268 @@ | ||
import app from '../index'; | ||
import dotenv from 'dotenv'; | ||
import req from 'supertest'; | ||
dotenv.config(); | ||
|
||
/** | ||
* 일일 낫투두 조회 | ||
* 200, 400, 401 케이스 | ||
*/ | ||
describe('GET /mission/daily/:date', () => { | ||
// 일일 낫투두 조회 200 케이스 | ||
it('일일 낫투두 조회 - 성공', (done) => { | ||
req(app) | ||
.get('/api/mission/daily/2023-01-06') | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.expect(200) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 일일 낫투두 조회 400 케이스 | ||
it('일일 낫투두 조회 - 잘못된 날짜 형식', (done) => { | ||
req(app) | ||
.get(`/api/mission/daily/2023-25`) | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.expect(400) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 일일 낫투두 조회 401 케이스 | ||
it('일일 낫투두 조회 - 유효하지 않은 토큰', (done) => { | ||
req(app) | ||
.get('/api/mission/daily/2023-01-05') | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `Bearer process.env.TEST_TOKEN` }) | ||
.expect(401) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
|
||
/** | ||
* 주간 낫투두 개수 조회 | ||
* 200, 400, 401 케이스 | ||
*/ | ||
describe('GET /mission/week/:startDate', () => { | ||
// 주간 낫투두 조회 200 케이스 | ||
it('주간 낫투두 개수 조회 - 성공', (done) => { | ||
req(app) | ||
.get('/api/mission/week/2023-01-02') | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.expect(200) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 주간 낫투두 조회 400 케이스 | ||
it('주간 낫투두 개수 조회 - 잘못된 날짜 형식', (done) => { | ||
req(app) | ||
.get(`/api/mission/week/2023-25`) | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.expect(400) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 주간 낫투두 조회 400 케이스 | ||
it('주간 낫투두 개수 조회 - 월요일이 아님', (done) => { | ||
req(app) | ||
.get(`/api/mission/week/2023-01-03`) | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.expect(400) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 주간 낫투두 조회 401 케이스 | ||
it('주간 낫투두 조회 - 유효하지 않은 토큰', (done) => { | ||
req(app) | ||
.get('/api/mission/week/2023-01-02') | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `Bearer process.env.TEST_TOKEN` }) | ||
.expect(401) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
|
||
/** | ||
* 낫투두 완료 상태 변경 | ||
* 201, 400, 401 케이스 | ||
*/ | ||
describe('PATCH /mission/:missionId/check', () => { | ||
// 낫투두 완료 상태 변경 201 케이스 | ||
it('낫투두 완료 상태 변경 - 성공', (done) => { | ||
req(app) | ||
.patch(`/api/mission/${process.env.TEST_MISSION_ID}/check`) | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.send({ | ||
completionStatus: 'FINISH', | ||
}) | ||
.expect(201) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 낫투두 완료 상태 변경 400 케이스 | ||
it('낫투두 완료 상태 변경 - 로그인한 유저의 낫투두가 아님', (done) => { | ||
req(app) | ||
.patch(`/api/mission/1/check`) | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.send({ | ||
completionStatus: 'FINISH', | ||
}) | ||
.expect(400) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 낫투두 완료 상태 변경 400 케이스 | ||
it('낫투두 완료 상태 변경 - 잘못된 완료 여부', (done) => { | ||
req(app) | ||
.patch(`/api/mission/${process.env.TEST_MISSION_ID}/check`) | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.send({ | ||
completionStatus: '남지윤 바보', | ||
}) | ||
.expect(400) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 낫투두 완료 상태 변경 401 케이스 | ||
it('낫투두 완료 상태 변경 - 유효하지 않은 토큰', (done) => { | ||
req(app) | ||
.patch(`/api/mission/${process.env.TEST_MISSION_ID}/check`) | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `Bearer process.env.TEST_TOKEN` }) | ||
.send({ | ||
completionStatus: 'FINISH', | ||
}) | ||
.expect(401) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
|
||
/** | ||
* 낫투두 삭제 | ||
* 201, 400, 401 케이스 | ||
*/ | ||
describe('DELETE /mission/:missionId', () => { | ||
// 낫투두 삭제 200 케이스 | ||
it('낫투두 삭제 - 성공', (done) => { | ||
req(app) | ||
.delete(`/api/mission/${process.env.TEST_MISSION_ID}`) | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.expect(200) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 낫투두 삭제 400 케이스 | ||
it('낫투두 삭제 - 로그인한 유저의 낫투두가 아님', (done) => { | ||
req(app) | ||
.delete(`/api/mission/1`) | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `${process.env.TEST_ACCESS_TOKEN}` }) | ||
.expect(400) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
// 낫투두 삭제 401 케이스 | ||
it('낫투두 삭제 - 유효하지 않은 토큰', (done) => { | ||
req(app) | ||
.delete(`/api/mission/${process.env.TEST_MISSION_ID}`) | ||
.set('Content-Type', 'application/json') | ||
.set({ Authorization: `Bearer process.env.TEST_TOKEN` }) | ||
.expect(401) | ||
.expect('Content-Type', /json/) | ||
.then((res) => { | ||
done(); | ||
}) | ||
.catch((err) => { | ||
console.error('######Error >>', err); | ||
done(err); | ||
}); | ||
}); | ||
}); |