diff --git a/tests/timeEntry.test.js b/tests/timeEntry.test.js index 5b6cad4677348fd00a26a2079d88a1cf232a7228..54f8e0c372a93c361c688406c2d6296a3ec388ff 100644 --- a/tests/timeEntry.test.js +++ b/tests/timeEntry.test.js @@ -9,22 +9,22 @@ Polly.register(NodeHttpAdapter); Polly.register(FSPersister); describe('TimeEntry', () => { - describe('#list()', () => { - const timeEntryService = new TimeEntryResource({ - host: process.env.HOST, - api_key: process.env.API_KEY, - }); - setupMocha({ - adapters: ['node-http'], - persister: 'fs', - persisterOptions: { - fs: { - recordingsDir: path.resolve(__dirname, '../recordings'), - }, + const timeEntryService = new TimeEntryResource({ + host: process.env.HOST, + api_key: process.env.API_KEY, + }); + setupMocha({ + adapters: ['node-http'], + persister: 'fs', + persisterOptions: { + fs: { + recordingsDir: path.resolve(__dirname, '../recordings'), }, - recordFailedRequests: true, - }); - should(); + }, + recordFailedRequests: true, + }); + should(); + describe('#list()', () => { it('lists all timeEnries', async () => { const timeEntries = await timeEntryService.list( undefined, @@ -36,7 +36,7 @@ describe('TimeEntry', () => { ); assert.equal(timeEntries.data.length, 10); }); - it('lists min timeEntries', async () => { + it('lists default timeEntries count', async () => { const timeEntries = await timeEntryService.list( undefined, undefined, @@ -47,7 +47,7 @@ describe('TimeEntry', () => { ); assert.equal(timeEntries.data.length, 25); }); - it('lists max timeEntries', async () => { + it('lists max timeEntries count', async () => { const timeEntries = await timeEntryService.list( undefined, undefined, @@ -100,6 +100,8 @@ describe('TimeEntry', () => { assert.equal(entry.project.id, projectId) ); }); + }); + describe('#get()', () => { it('gets one', async () => { const timeEntries = await timeEntryService.list( undefined, @@ -118,4 +120,49 @@ describe('TimeEntry', () => { timeEntry.should.have.property('code').to.equal(404); }); }); + describe('#create() #delete()', () => { + it('creates and deletes new time entry', async () => { + const userId = process.env.USER_ID; + const issueId = process.env.ISSUE_ID; + const projectId = process.env.PROJECT_ID; + const newTimeEntry = await timeEntryService.create({ + user_id: userId, + issue_id: issueId, + hours: 1.5, + comments: 'new time entry', + project_id: projectId, + activity_id: 9, + }); + assert.equal(newTimeEntry.data.user.id, userId); + assert.equal(newTimeEntry.data.issue.id, issueId); + assert.equal(newTimeEntry.data.project.id, projectId); + + const timeEntryId = newTimeEntry.data.id; + + const deletedTimeEntry = await timeEntryService.delete(timeEntryId); + + assert.equal(newTimeEntry.data.id, deletedTimeEntry.data.id); + }); + }); + describe('#update()', () => { + it('updates one', async () => { + const userId = process.env.USER_ID; + const issueId = process.env.ISSUE_ID; + const projectId = process.env.PROJECT_ID; + const activityId = process.env.ACTIVITY_ID; + const newTimeEntry = await timeEntryService.create({ + user_id: userId, + issue_id: issueId, + hours: 1.5, + comments: 'new time entry', + project_id: projectId, + activity_id: activityId, + }); + const timeEntryId = newTimeEntry.data.id; + const updatedEntry = await timeEntryService.update(timeEntryId, { + hours: 2, + }); + assert.equal(updatedEntry.data.hours, 2); + }); + }); });