Skip to content

Commit

Permalink
feat: add delete api
Browse files Browse the repository at this point in the history
  • Loading branch information
junha-ahn committed Oct 31, 2023
1 parent 236be8e commit 7e4a485
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/api/routes/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ module.exports = (app) => {
})
})
)

router.delete(
'/running/:eventId/:userId',
validator.mw([validator.param('eventId').isInt(), validator.param('userId').isInt()]),
container(async (req) => {
logger.debug('Calling DELETE /ticket with params: %o', req.params)
const { eventId, userId } = req.params

const ticketStoreService = new TicketStoreService(redis)
const offset = await ticketStoreService.getOffsetFromRunning(eventId, userId)
if (offset == null) return CustomResponse(404, `Ticket Not Found!`)
await ticketStoreService.removeTicketFromRunning(eventId, userId)
return CustomResponse(200, `Success Delete!`)
})
)
}
3 changes: 3 additions & 0 deletions src/services/ticketStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@ module.exports = class TicketStore {
const results = await this._getByTimestamp(this.getEventListKey(), minTimestamp, maxTimestamp)
return results.map((e) => Number(e))
}
async removeTicketFromRunning(eventId, userId) {
return this.redis.zRem(this.getRunningKeyByEventId(eventId), userId)
}
}
29 changes: 29 additions & 0 deletions test/integrationTest/api/ticket.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,33 @@ describe('Ticket', () => {
})
})
})

describe('DELETE /ticket/running/{eventId}/{userId} 은', () => {
describe('삭제 성공시', () => {
it('200을 리턴한다', async () => {
await ticketStoreService.pushIntoRunning(testEventId, testUserId)

const res = await chai.request(server).del(`/ticket/running/${testEventId}/${testUserId}`)
expect(res).to.have.status(200)
expect(res.body.status).to.deep.equal(true)
})
})
describe('실패시', () => {
it('Running 티켓이 없을 경우 404 Not Found를 리턴한다', async () => {
const res = await chai.request(server).del(`/ticket/${testEventId}/${testUserId}`)
expect(res).to.have.status(404)
expect(res.body.status).to.deep.equal(false)
})
it('Waiting 티켓이 존재해도, 입장 티켓이 없을 경우 404 Not Found를 리턴한다', async () => {
await chai.request(server).post('/ticket').send({
eventId: testEventId,
userId: testUserId,
})

const res = await chai.request(server).del(`/ticket/running/${testEventId}/${testUserId}`)
expect(res).to.have.status(404)
expect(res.body.status).to.deep.equal(false)
})
})
})
})

0 comments on commit 7e4a485

Please sign in to comment.