Skip to content

Commit

Permalink
Merge pull request #50 from DO-NOTTO-DO/Feat/#40
Browse files Browse the repository at this point in the history
Feat/#40 박정훈 테스트 코드
  • Loading branch information
shb03323 authored Jan 9, 2023
2 parents 8d49150 + 0b3e713 commit e58e461
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 7 deletions.
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@
"scripts": {
"dev": "nodemon",
"build": "tsc && node dist/src",
"test": "mocha -r ts-node/register src/test/*.spec.ts -exit",
"db:pull": "npx prisma db pull",
"db:push": "npx prisma db push",
"generate": "npx prisma generate"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.2",
"@types/chai": "^4.3.4",
"@types/express": "^4.17.14",
"@types/jsonwebtoken": "^8.5.9",
"@types/node": "^18.11.9",
"@types/supertest": "^2.0.12",
"chai": "^4.3.7",
"eslint": "^8.19.0",
"mocha": "^10.2.0",
"nodemon": "^2.0.20",
"typescript": "^4.7.4",
"ts-node": "^10.8.2",
"prettier": "^2.7.1",
"eslint": "^8.19.0"
"supertest": "^6.3.3",
"ts-node": "^10.8.2",
"typescript": "^4.7.4"
},
"dependencies": {
"@prisma/client": "^4.5.0",
"@types/express-validator": "^3.0.0",
"@types/mocha": "^10.0.1",
"agenda": "^4.3.0",
"axios": "^1.2.2",
"bcryptjs": "^2.4.3",
Expand Down
8 changes: 4 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ model not_todo {
}

model banner {
id Int @id(map: "banner_pk") @unique(map: "banner_id_uindex") @default(autoincrement())
title String @db.VarChar(500)
image String @db.VarChar(500)
banner_category String @db.VarChar(500)
id Int @id(map: "banner_pk") @unique(map: "banner_id_uindex") @default(autoincrement())
title String @db.VarChar(500)
image String @db.VarChar(500)
banner_category String @db.VarChar(500)
}
43 changes: 43 additions & 0 deletions src/test/banner.spec.ts
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);
});
});
});
268 changes: 268 additions & 0 deletions src/test/mission.spec.ts
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);
});
});
});

0 comments on commit e58e461

Please sign in to comment.