diff --git a/migrations/2021-04-22-2-populate-work-periods-for-resource-bookings.js b/migrations/2021-04-22-2-populate-work-periods-for-resource-bookings.js index a15d64cd..0b20c9e6 100644 --- a/migrations/2021-04-22-2-populate-work-periods-for-resource-bookings.js +++ b/migrations/2021-04-22-2-populate-work-periods-for-resource-bookings.js @@ -41,7 +41,7 @@ module.exports = { user_handle: user.handle, start_date: period.startDate, end_date: period.endDate, - days_worked: period.daysWorked, + days_worked: null, payment_status: 'pending', created_by: config.m2m.M2M_AUDIT_USER_ID, created_at: new Date() diff --git a/src/common/helper.js b/src/common/helper.js index 0f166fe7..c081467c 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -1260,10 +1260,10 @@ async function createChallengeResource (data, token) { * Populates workPeriods from start and end date of resource booking * @param {Date} start start date of the resource booking * @param {Date} end end date of the resource booking - * @returns {Array} information about workPeriods + * @returns {Array<{startDate:Date, endDate:Date, daysWorked:number}>} information about workPeriods */ function extractWorkPeriods (start, end) { - // canculate daysWorked for a week + // calculate maximum possible daysWorked for a week function getDaysWorked (week) { if (weeks === 1) { return Math.min(endDay, 5) - Math.max(startDay, 1) + 1 diff --git a/src/eventHandlers/ResourceBookingEventHandler.js b/src/eventHandlers/ResourceBookingEventHandler.js index 95947436..8145ba49 100644 --- a/src/eventHandlers/ResourceBookingEventHandler.js +++ b/src/eventHandlers/ResourceBookingEventHandler.js @@ -176,7 +176,8 @@ async function updateWorkPeriods (payload) { const workPeriodsToAdd = _.differenceBy(newWorkPeriods, workPeriods, 'startDate') // find which workperiods' daysWorked propery should be updated let workPeriodsToUpdate = _.intersectionBy(newWorkPeriods, workPeriods, 'startDate') - workPeriodsToUpdate = _.differenceWith(workPeriodsToUpdate, workPeriods, (a, b) => b.startDate === a.startDate && b.daysWorked === a.daysWorked) + // find which workperiods' daysWorked property is preset and exceeds the possible maximum + workPeriodsToUpdate = _.differenceWith(workPeriodsToUpdate, workPeriods, (a, b) => b.startDate === a.startDate && _.defaultTo(b.daysWorked, a.daysWorked) <= a.daysWorked) // include id workPeriodsToUpdate = _.map(workPeriodsToUpdate, wpu => { wpu.id = _.filter(workPeriods, ['startDate', wpu.startDate])[0].id @@ -186,7 +187,7 @@ async function updateWorkPeriods (payload) { logger.debug({ component: 'ResourceBookingEventHandler', context: 'updateWorkPeriods', - message: `id: ${payload.value.id} resource booking has no change in dates - ignored` + message: `id: ${payload.value.id} resource booking has no change in dates that affect work periods - ignored` }) return } @@ -248,8 +249,7 @@ async function deleteWorkPeriods (payload) { /** * Calls WorkPeriodService to create workPeriods - * @param {Array<{startDate:Date, - * endDate:Date, daysWorked:number}>} periods work period data + * @param {Array<{startDate:Date, endDate:Date}>} periods work period data * @param {string} resourceBookingId resourceBookingId of work period * @returns {undefined} */ @@ -259,7 +259,7 @@ async function _createWorkPeriods (periods, resourceBookingId) { resourceBookingId: resourceBookingId, startDate: period.startDate, endDate: period.endDate, - daysWorked: period.daysWorked, + daysWorked: null, paymentStatus: 'pending' }))) } diff --git a/src/services/PaymentService.js b/src/services/PaymentService.js index 15c6ee7c..7d714f75 100644 --- a/src/services/PaymentService.js +++ b/src/services/PaymentService.js @@ -79,13 +79,13 @@ async function createChallenge (challenge, token) { pureV5Task: true }, tags: ['Other'], - startDate: new Date(), + startDate: new Date() } if (challenge.billingAccountId) { body.billing = { billingAccountId: challenge.billingAccountId, - markup: 0, // for TaaS payments we always use 0 markup + markup: 0 // for TaaS payments we always use 0 markup } } try { diff --git a/test/unit/ResourceBookingService.test.js b/test/unit/ResourceBookingService.test.js index 1af075e3..f557466e 100644 --- a/test/unit/ResourceBookingService.test.js +++ b/test/unit/ResourceBookingService.test.js @@ -1,62 +1,66 @@ /* eslint-disable no-unused-expressions */ -// const _ = require('lodash') const expect = require('chai').expect const sinon = require('sinon') const models = require('../../src/models') const service = require('../../src/services/ResourceBookingService') const workPeriodService = require('../../src/services/WorkPeriodService') -const testData = require('./common/testData') +const commonData = require('./common/CommonData') +const testData = require('./common/ResourceBookingData') const helper = require('../../src/common/helper') -// const esClient = helper.getESClient() const busApiClient = helper.getBusApiClient() const ResourceBooking = models.ResourceBooking const WorkPeriod = models.WorkPeriod describe('resourceBooking service test', () => { - let stubEnsureJobById - let stubEnsureUserById let stubPostEvent let stubCreateWorkPeriodService let stubUpdateWorkPeriodService let stubDeleteWorkPeriodService beforeEach(() => { - stubEnsureJobById = sinon.stub(helper, 'ensureJobById').callsFake(async () => {}) - stubEnsureUserById = sinon.stub(helper, 'ensureUserById').callsFake(async () => testData.UserTCConnCopilot) - stubPostEvent = sinon.stub(busApiClient, 'postEvent').callsFake(async () => {}) - stubCreateWorkPeriodService = sinon.stub(workPeriodService, 'createWorkPeriod').callsFake(async () => {}) - stubUpdateWorkPeriodService = sinon.stub(workPeriodService, 'partiallyUpdateWorkPeriod').callsFake(async () => {}) - stubDeleteWorkPeriodService = sinon.stub(workPeriodService, 'deleteWorkPeriod').callsFake(async () => {}) + stubPostEvent = sinon.stub(busApiClient, 'postEvent').callsFake(async () => undefined) + stubCreateWorkPeriodService = sinon.stub(workPeriodService, 'createWorkPeriod').callsFake(async () => undefined) + stubUpdateWorkPeriodService = sinon.stub(workPeriodService, 'partiallyUpdateWorkPeriod').callsFake(async () => undefined) + stubDeleteWorkPeriodService = sinon.stub(workPeriodService, 'deleteWorkPeriod').callsFake(async () => undefined) }) afterEach(() => { sinon.restore() }) - describe('create resource booking test', () => { - it('create resource booking and auto populate work periods for 5 weeks', async () => { + describe('Create resource booking successfully', () => { + let stubEnsureJobById + let stubEnsureUserById + beforeEach(() => { + stubEnsureJobById = sinon.stub(helper, 'ensureJobById').callsFake(async () => undefined) + stubEnsureUserById = sinon.stub(helper, 'ensureUserById').callsFake(async () => commonData.UserTCConnCopilot) + }) + it('T01:Create resource booking start Saturday end Sunday', async () => { + const data = testData.T01 const stubDBCreate = sinon.stub(ResourceBooking, 'create').callsFake(() => { - return testData.resourceBooking5Week.response + return data.resourceBooking.response }) - const entity = await service.createResourceBooking(testData.currentUser, testData.resourceBooking5Week.request) - expect(entity).to.deep.eql(testData.resourceBooking5Week.response.toJSON()) + const entity = await service.createResourceBooking(commonData.currentUser, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) expect(stubEnsureJobById.calledOnce).to.be.true expect(stubEnsureUserById.calledOnce).to.be.true expect(stubDBCreate.calledOnce).to.be.true expect(stubPostEvent.calledOnce).to.be.true - expect(stubCreateWorkPeriodService.callCount).to.eq(5) - expect(stubCreateWorkPeriodService.getCall(0).args[1]).to.deep.eq(testData.resourceBooking5Week.workPeriodRequests[0]) - expect(stubCreateWorkPeriodService.getCall(1).args[1]).to.deep.eq(testData.resourceBooking5Week.workPeriodRequests[1]) - expect(stubCreateWorkPeriodService.getCall(2).args[1]).to.deep.eq(testData.resourceBooking5Week.workPeriodRequests[2]) - expect(stubCreateWorkPeriodService.getCall(3).args[1]).to.deep.eq(testData.resourceBooking5Week.workPeriodRequests[3]) - expect(stubCreateWorkPeriodService.getCall(4).args[1]).to.deep.eq(testData.resourceBooking5Week.workPeriodRequests[4]) - }) - it('create resource booking and auto populate work periods for 1 week', async () => { + expect(stubCreateWorkPeriodService.callCount).to.eq(6) + expect(stubUpdateWorkPeriodService.callCount).to.eq(0) + expect(stubDeleteWorkPeriodService.callCount).to.eq(0) + expect(stubCreateWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[0]) + expect(stubCreateWorkPeriodService.getCall(1).args[1]).to.deep.eq(data.workPeriod.request[1]) + expect(stubCreateWorkPeriodService.getCall(2).args[1]).to.deep.eq(data.workPeriod.request[2]) + expect(stubCreateWorkPeriodService.getCall(3).args[1]).to.deep.eq(data.workPeriod.request[3]) + expect(stubCreateWorkPeriodService.getCall(4).args[1]).to.deep.eq(data.workPeriod.request[4]) + }) + it('T02:Create resource booking start Sunday end Saturday', async () => { + const data = testData.T02 const stubDBCreate = sinon.stub(ResourceBooking, 'create').callsFake(async () => { - return testData.resourceBooking1Week.response + return data.resourceBooking.response }) - - const entity = await service.createResourceBooking(testData.currentUser, testData.resourceBooking1Week.request) - expect(entity).to.deep.eql(testData.resourceBooking1Week.response.toJSON()) + const entity = await service.createResourceBooking(commonData.currentUser, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) expect(stubEnsureJobById.calledOnce).to.be.true expect(stubEnsureUserById.calledOnce).to.be.true expect(stubDBCreate.calledOnce).to.be.true @@ -64,175 +68,285 @@ describe('resourceBooking service test', () => { expect(stubCreateWorkPeriodService.callCount).to.eq(1) expect(stubUpdateWorkPeriodService.callCount).to.eq(0) expect(stubDeleteWorkPeriodService.callCount).to.eq(0) - expect(stubCreateWorkPeriodService.getCall(0).args[1]).to.deep.eq(testData.resourceBooking1Week.workPeriodRequests[0]) + expect(stubCreateWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[0]) + }) + it('T03:Create resource booking without startDate', async () => { + const data = testData.T03 + const stubDBCreate = sinon.stub(ResourceBooking, 'create').callsFake(async () => { + return data.resourceBooking.response + }) + const entity = await service.createResourceBooking(commonData.currentUser, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) + expect(stubEnsureJobById.calledOnce).to.be.true + expect(stubEnsureUserById.calledOnce).to.be.true + expect(stubDBCreate.calledOnce).to.be.true + expect(stubPostEvent.calledOnce).to.be.true + expect(stubCreateWorkPeriodService.callCount).to.eq(0) + expect(stubUpdateWorkPeriodService.callCount).to.eq(0) + expect(stubDeleteWorkPeriodService.callCount).to.eq(0) + }) + it('T04:Create resource booking without endDate', async () => { + const data = testData.T04 + const stubDBCreate = sinon.stub(ResourceBooking, 'create').callsFake(async () => { + return data.resourceBooking.response + }) + const entity = await service.createResourceBooking(commonData.currentUser, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) + expect(stubEnsureJobById.calledOnce).to.be.true + expect(stubEnsureUserById.calledOnce).to.be.true + expect(stubDBCreate.calledOnce).to.be.true + expect(stubPostEvent.calledOnce).to.be.true + expect(stubCreateWorkPeriodService.callCount).to.eq(0) + expect(stubUpdateWorkPeriodService.callCount).to.eq(0) + expect(stubDeleteWorkPeriodService.callCount).to.eq(0) + }) + }) + describe('Create resource booking unsuccessfully', () => { + let stubEnsureJobById + let stubEnsureUserById + beforeEach(() => { + stubEnsureJobById = sinon.stub(helper, 'ensureJobById').callsFake(async () => undefined) + stubEnsureUserById = sinon.stub(helper, 'ensureUserById').callsFake(async () => commonData.UserTCConnCopilot) }) - it('update resource booking and cause daysWorked to change', async () => { + it('T05:Fail to create resource booking with startDate greater then endDate', async () => { + const data = testData.T05 + const stubDBCreate = sinon.stub(ResourceBooking, 'create').callsFake(() => { + return data.resourceBooking.response + }) + let error + try { + await service.createResourceBooking(commonData.currentUser, data.resourceBooking.request) + } catch (err) { + error = err + } + expect(error.message).to.eq(data.error.message) + expect(stubEnsureJobById.notCalled).to.be.true + expect(stubEnsureUserById.notCalled).to.be.true + expect(stubDBCreate.notCalled).to.be.true + expect(stubPostEvent.notCalled).to.be.true + expect(stubCreateWorkPeriodService.callCount).to.eq(0) + expect(stubUpdateWorkPeriodService.callCount).to.eq(0) + expect(stubDeleteWorkPeriodService.callCount).to.eq(0) + }) + }) + describe('Update resource booking successfully', () => { + it('T06:Update resource booking dates and do not cause work period change', async () => { + const data = testData.T06 const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { - return testData.resourceBooking1Week.response + return data.resourceBooking.value }) const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { - return testData.resourceBooking1Week.workPeriodResponse + return data.workPeriod.response }) - const entity = await service.partiallyUpdateResourceBooking(testData.currentUser, testData.resourceBooking1Week.response.dataValues.id, testData.resourceBooking1Week.updateRequest) - expect(entity).to.deep.eql(testData.resourceBooking1Week.updateResponse.toJSON()) + const entity = await service.partiallyUpdateResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) expect(stubResourceBookingFindById.calledOnce).to.be.true expect(stubPostEvent.calledOnce).to.be.true expect(stubWorkPeriodFindAll.called).to.be.true expect(stubCreateWorkPeriodService.callCount).to.eq(0) - expect(stubUpdateWorkPeriodService.callCount).to.eq(1) + expect(stubUpdateWorkPeriodService.callCount).to.eq(0) expect(stubDeleteWorkPeriodService.callCount).to.eq(0) - expect(stubUpdateWorkPeriodService.getCall(0).args[2]).to.deep.eq(testData.resourceBooking1Week.workPeriodUpdateRequests[0]) }) - it('update resource booking and cause daysWorked to change', async () => { + it('T07:Update resource booking dates and cause work period creation - 1', async () => { + const data = testData.T07 const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { - return testData.resourceBookingUpdate.response + return data.resourceBooking.value }) const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { - return testData.resourceBookingUpdate.workPeriodResponse + return data.workPeriod.response }) - const entity = await service.partiallyUpdateResourceBooking(testData.currentUser, testData.resourceBookingUpdate.response.dataValues.id, testData.resourceBookingUpdate.updateRequest) - expect(entity).to.deep.eql(testData.resourceBookingUpdate.updateResponse.toJSON()) + const entity = await service.partiallyUpdateResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) expect(stubResourceBookingFindById.calledOnce).to.be.true expect(stubPostEvent.calledOnce).to.be.true expect(stubWorkPeriodFindAll.called).to.be.true - expect(stubCreateWorkPeriodService.callCount).to.eq(0) - expect(stubUpdateWorkPeriodService.callCount).to.eq(1) + expect(stubCreateWorkPeriodService.callCount).to.eq(1) + expect(stubUpdateWorkPeriodService.callCount).to.eq(0) expect(stubDeleteWorkPeriodService.callCount).to.eq(0) - expect(stubUpdateWorkPeriodService.getCall(0).args[2]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests[0]) + expect(stubCreateWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[0]) }) - it('update resource booking and cause workPeriod to create', async () => { + it('T08:Update resource booking dates and cause work period creation - 2', async () => { + const data = testData.T08 const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { - return testData.resourceBookingUpdate.response2 + return data.resourceBooking.value }) const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { - return testData.resourceBookingUpdate.workPeriodResponse + return data.workPeriod.response }) - const entity = await service.partiallyUpdateResourceBooking(testData.currentUser, testData.resourceBookingUpdate.response2.dataValues.id, testData.resourceBookingUpdate.updateRequest2) - expect(entity).to.deep.eql(testData.resourceBookingUpdate.updateResponse2.toJSON()) + const entity = await service.partiallyUpdateResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) expect(stubResourceBookingFindById.calledOnce).to.be.true expect(stubPostEvent.calledOnce).to.be.true expect(stubWorkPeriodFindAll.called).to.be.true expect(stubCreateWorkPeriodService.callCount).to.eq(1) - expect(stubUpdateWorkPeriodService.callCount).to.eq(1) + expect(stubUpdateWorkPeriodService.callCount).to.eq(0) expect(stubDeleteWorkPeriodService.callCount).to.eq(0) - expect(stubUpdateWorkPeriodService.getCall(0).args[2]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests2[0]) - expect(stubCreateWorkPeriodService.getCall(0).args[1]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests2[1]) + expect(stubCreateWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[0]) }) - it('update resource booking and cause workPeriod to delete', async () => { + it('T09:Update resource booking startDate and cause work period to be deleted', async () => { + const data = testData.T09 const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { - return testData.resourceBookingUpdate.response3 + return data.resourceBooking.value }) const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { - return testData.resourceBookingUpdate.workPeriodResponse + return data.workPeriod.response }) - const entity = await service.partiallyUpdateResourceBooking(testData.currentUser, testData.resourceBookingUpdate.response3.dataValues.id, testData.resourceBookingUpdate.updateRequest3) - expect(entity).to.deep.eql(testData.resourceBookingUpdate.updateResponse3.toJSON()) + const entity = await service.partiallyUpdateResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) expect(stubResourceBookingFindById.calledOnce).to.be.true expect(stubPostEvent.calledOnce).to.be.true expect(stubWorkPeriodFindAll.called).to.be.true expect(stubCreateWorkPeriodService.callCount).to.eq(0) - expect(stubUpdateWorkPeriodService.callCount).to.eq(1) + expect(stubUpdateWorkPeriodService.callCount).to.eq(0) expect(stubDeleteWorkPeriodService.callCount).to.eq(1) - expect(stubUpdateWorkPeriodService.getCall(0).args[1]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests3[0]) - expect(stubUpdateWorkPeriodService.getCall(0).args[2]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests3[1]) - expect(stubDeleteWorkPeriodService.getCall(0).args[1]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests3[2]) + expect(stubDeleteWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[0]) }) - it('delete resource booking and cause workPeriod to delete', async () => { + it('T10:Update resource booking endDate and cause work period to be deleted', async () => { + const data = testData.T10 const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { - return testData.resourceBookingUpdate.response3 + return data.resourceBooking.value }) const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { - return testData.resourceBookingUpdate.workPeriodResponse + return data.workPeriod.response }) - await service.deleteResourceBooking(testData.currentUser, testData.resourceBookingUpdate.response3.dataValues.id) + const entity = await service.partiallyUpdateResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) expect(stubResourceBookingFindById.calledOnce).to.be.true expect(stubPostEvent.calledOnce).to.be.true expect(stubWorkPeriodFindAll.called).to.be.true expect(stubCreateWorkPeriodService.callCount).to.eq(0) expect(stubUpdateWorkPeriodService.callCount).to.eq(0) - expect(stubDeleteWorkPeriodService.callCount).to.eq(4) - expect(stubDeleteWorkPeriodService.getCall(0).args[1]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests3[3]) - expect(stubDeleteWorkPeriodService.getCall(1).args[1]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests3[4]) - expect(stubDeleteWorkPeriodService.getCall(2).args[1]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests3[5]) - expect(stubDeleteWorkPeriodService.getCall(3).args[1]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests3[6]) + expect(stubDeleteWorkPeriodService.callCount).to.eq(1) + expect(stubDeleteWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[0]) }) - it('update resource booking with paid weeks and cause workPeriod to delete', async () => { + it('T11:Update resource booking dates and cause work period daysWorked to change', async () => { + const data = testData.T11 const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { - return testData.resourceBookingUpdate.response4 + return data.resourceBooking.value }) const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { - return testData.resourceBookingUpdate.workPeriodResponse4 + return data.workPeriod.response }) - const entity = await service.partiallyUpdateResourceBooking(testData.currentUser, testData.resourceBookingUpdate.response4.dataValues.id, testData.resourceBookingUpdate.updateRequest4) - expect(entity).to.deep.eql(testData.resourceBookingUpdate.updateResponse4.toJSON()) + const entity = await service.partiallyUpdateResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) expect(stubResourceBookingFindById.calledOnce).to.be.true expect(stubPostEvent.calledOnce).to.be.true expect(stubWorkPeriodFindAll.called).to.be.true expect(stubCreateWorkPeriodService.callCount).to.eq(0) expect(stubUpdateWorkPeriodService.callCount).to.eq(1) - expect(stubDeleteWorkPeriodService.callCount).to.eq(2) - expect(stubUpdateWorkPeriodService.getCall(0).args[2]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests4[0]) - expect(stubDeleteWorkPeriodService.getCall(0).args[1]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests4[1]) - expect(stubDeleteWorkPeriodService.getCall(1).args[1]).to.deep.eq(testData.resourceBookingUpdate.workPeriodUpdateRequests4[2]) + expect(stubDeleteWorkPeriodService.callCount).to.eq(0) + expect(stubUpdateWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[0]) + expect(stubUpdateWorkPeriodService.getCall(0).args[2]).to.deep.eq(data.workPeriod.request[1]) }) - it('fail to update resource booking with paid weeks when try to delete paid weeks', async () => { + it('T12:Update resource booking dates and cause delete, update, create work period operations', async () => { + const data = testData.T12 const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { - return testData.resourceBookingUpdate.response4 + return data.resourceBooking.value }) const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { - return testData.resourceBookingUpdate.workPeriodResponse4 + return data.workPeriod.response }) - let httpStatus + const entity = await service.partiallyUpdateResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id, data.resourceBooking.request) + expect(entity).to.deep.eql(data.resourceBooking.response.toJSON()) + expect(stubResourceBookingFindById.calledOnce).to.be.true + expect(stubPostEvent.calledOnce).to.be.true + expect(stubWorkPeriodFindAll.called).to.be.true + expect(stubCreateWorkPeriodService.callCount).to.eq(1) + expect(stubUpdateWorkPeriodService.callCount).to.eq(1) + expect(stubDeleteWorkPeriodService.callCount).to.eq(1) + expect(stubDeleteWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[0]) + expect(stubUpdateWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[1]) + expect(stubUpdateWorkPeriodService.getCall(0).args[2]).to.deep.eq(data.workPeriod.request[2]) + expect(stubCreateWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[3]) + }) + }) + describe('Update resource booking unsuccessfully', () => { + it('T13:Fail to update resource booking status to cancelled', async () => { + const data = testData.T13 + const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { + return data.resourceBooking.value + }) + const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { + return data.workPeriod.response + }) + let error try { - await service.partiallyUpdateResourceBooking(testData.currentUser, testData.resourceBookingUpdate.response4.dataValues.id, testData.resourceBookingUpdate.updateRequest5) + await service.partiallyUpdateResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id, data.resourceBooking.request) } catch (err) { - httpStatus = err.httpStatus + error = err } - expect(httpStatus).to.eq(400) + expect(error.httpStatus).to.eq(data.error.httpStatus) + expect(error.message).to.eq(data.error.message) expect(stubResourceBookingFindById.calledOnce).to.be.true - expect(stubPostEvent.calledOnce).to.be.false + expect(stubPostEvent.notCalled).to.be.true expect(stubWorkPeriodFindAll.called).to.be.true expect(stubCreateWorkPeriodService.callCount).to.eq(0) expect(stubUpdateWorkPeriodService.callCount).to.eq(0) expect(stubDeleteWorkPeriodService.callCount).to.eq(0) }) - it('fail to update resource booking with paid weeks when try to set status cancelled', async () => { + it('T14:Fail to update resource booking dates', async () => { + const data = testData.T14 const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { - return testData.resourceBookingUpdate.response4 + return data.resourceBooking.value }) const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { - return testData.resourceBookingUpdate.workPeriodResponse4 + return data.workPeriod.response }) - let httpStatus + let error try { - await service.partiallyUpdateResourceBooking(testData.currentUser, testData.resourceBookingUpdate.response4.dataValues.id, testData.resourceBookingUpdate.updateRequest6) + await service.partiallyUpdateResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id, data.resourceBooking.request) } catch (err) { - httpStatus = err.httpStatus + error = err } - expect(httpStatus).to.eq(400) + expect(error.httpStatus).to.eq(data.error.httpStatus) + expect(error.message).to.eq(data.error.message) expect(stubResourceBookingFindById.calledOnce).to.be.true - expect(stubPostEvent.calledOnce).to.be.false + expect(stubPostEvent.notCalled).to.be.true expect(stubWorkPeriodFindAll.called).to.be.true expect(stubCreateWorkPeriodService.callCount).to.eq(0) expect(stubUpdateWorkPeriodService.callCount).to.eq(0) expect(stubDeleteWorkPeriodService.callCount).to.eq(0) }) - it('fail to delete resource booking with paid weeks', async () => { + }) + describe('Delete resource booking successfully', () => { + it('T15:Delete resource booking and cause work periods to be deleted ', async () => { + const data = testData.T15 + const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { + return data.resourceBooking.value + }) + const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { + return data.workPeriod.response + }) + await service.deleteResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id) + expect(stubResourceBookingFindById.calledOnce).to.be.true + expect(stubPostEvent.calledOnce).to.be.true + expect(stubWorkPeriodFindAll.called).to.be.true + expect(stubCreateWorkPeriodService.callCount).to.eq(0) + expect(stubUpdateWorkPeriodService.callCount).to.eq(0) + expect(stubDeleteWorkPeriodService.callCount).to.eq(2) + expect(stubDeleteWorkPeriodService.getCall(0).args[1]).to.deep.eq(data.workPeriod.request[0]) + expect(stubDeleteWorkPeriodService.getCall(1).args[1]).to.deep.eq(data.workPeriod.request[1]) + }) + }) + describe('Delete resource booking unsuccessfully', () => { + it('T16:Fail to delete resource booking with paid work periods', async () => { + const data = testData.T16 const stubResourceBookingFindById = sinon.stub(ResourceBooking, 'findById').callsFake(async () => { - return testData.resourceBookingUpdate.response4 + return data.resourceBooking.value }) const stubWorkPeriodFindAll = sinon.stub(WorkPeriod, 'findAll').callsFake(async () => { - return testData.resourceBookingUpdate.workPeriodResponse4 + return data.workPeriod.response }) - let httpStatus + let error try { - await service.deleteResourceBooking(testData.currentUser, testData.resourceBookingUpdate.response4.dataValues.id) + await service.deleteResourceBooking(commonData.currentUser, data.resourceBooking.value.dataValues.id) } catch (err) { - httpStatus = err.httpStatus + error = err } - expect(httpStatus).to.eq(400) - expect(stubResourceBookingFindById.calledOnce).to.be.false - expect(stubPostEvent.calledOnce).to.be.false + expect(error.httpStatus).to.eq(data.error.httpStatus) + expect(error.message).to.eq(data.error.message) + expect(stubResourceBookingFindById.notCalled).to.be.true + expect(stubPostEvent.notCalled).to.be.true expect(stubWorkPeriodFindAll.called).to.be.true expect(stubCreateWorkPeriodService.callCount).to.eq(0) expect(stubUpdateWorkPeriodService.callCount).to.eq(0) diff --git a/test/unit/WorkPeriodPaymentService.test.js b/test/unit/WorkPeriodPaymentService.test.js index 6ec6248a..5e90b072 100644 --- a/test/unit/WorkPeriodPaymentService.test.js +++ b/test/unit/WorkPeriodPaymentService.test.js @@ -6,7 +6,8 @@ const sinon = require('sinon') const models = require('../../src/models') const service = require('../../src/services/WorkPeriodPaymentService') const paymentService = require('../../src/services/PaymentService') -const testData = require('./common/testData') +const commonData = require('./common/CommonData') +const testData = require('./common/WorkPeriodPaymentData') const helper = require('../../src/common/helper') // const esClient = helper.getESClient() const busApiClient = helper.getBusApiClient() @@ -35,7 +36,7 @@ describe('workPeriod service test', () => { }) it('create work period success', async () => { - const response = await service.createWorkPeriodPayment(testData.currentUser, testData.workPeriodPayment01.request, { paymentProcessingSwitch: 'ON' }) + const response = await service.createWorkPeriodPayment(commonData.currentUser, testData.workPeriodPayment01.request, { paymentProcessingSwitch: 'ON' }) expect(stubGetUserId.calledOnce).to.be.true expect(stubEnsureWorkPeriodById.calledOnce).to.be.true expect(stubEnsureResourceBookingById.calledOnce).to.be.true @@ -45,7 +46,7 @@ describe('workPeriod service test', () => { }) it('create work period success - billingAccountId is set', async () => { - await service.createWorkPeriodPayment(testData.currentUser, testData.workPeriodPayment01.request, { paymentProcessingSwitch: 'ON' }) + await service.createWorkPeriodPayment(commonData.currentUser, testData.workPeriodPayment01.request, { paymentProcessingSwitch: 'ON' }) expect(stubCreatePayment.calledOnce).to.be.true expect(stubCreatePayment.args[0][0]).to.include({ billingAccountId: testData.workPeriodPayment01.ensureResourceBookingByIdResponse.billingAccountId @@ -61,7 +62,7 @@ describe('workPeriod service test', () => { sinon.stub(helper, 'ensureResourceBookingById').callsFake(async () => testData.workPeriodPayment01.ensureResourceBookingByIdResponse02) try { - await service.createWorkPeriodPayment(testData.currentUser, testData.workPeriodPayment01.request) + await service.createWorkPeriodPayment(commonData.currentUser, testData.workPeriodPayment01.request) } catch (err) { expect(err.message).to.include('"ResourceBooking" Billing account is not assigned to the resource booking') } @@ -69,11 +70,11 @@ describe('workPeriod service test', () => { describe('when PAYMENT_PROCESSING_SWITCH is ON/OFF', async () => { it('do not create payment if PAYMENT_PROCESSING_SWITCH is OFF', async () => { - await service.createWorkPeriodPayment(testData.currentUser, testData.workPeriodPayment01.request, { paymentProcessingSwitch: 'OFF' }) + await service.createWorkPeriodPayment(commonData.currentUser, testData.workPeriodPayment01.request, { paymentProcessingSwitch: 'OFF' }) expect(stubCreatePayment.calledOnce).to.be.false }) it('create payment if PAYMENT_PROCESSING_SWITCH is ON', async () => { - await service.createWorkPeriodPayment(testData.currentUser, testData.workPeriodPayment01.request, { paymentProcessingSwitch: 'ON' }) + await service.createWorkPeriodPayment(commonData.currentUser, testData.workPeriodPayment01.request, { paymentProcessingSwitch: 'ON' }) expect(stubCreatePayment.calledOnce).to.be.true }) }) diff --git a/test/unit/common/CommonData.js b/test/unit/common/CommonData.js new file mode 100644 index 00000000..08f8aa66 --- /dev/null +++ b/test/unit/common/CommonData.js @@ -0,0 +1,12 @@ +const currentUser = { + userId: '00000000-0000-0000-0000-000000000000', + isMachine: true +} +const UserTCConnCopilot = { + userId: '4709473d-f060-4102-87f8-4d51ff0b34c1', + handle: 'TCConnCopilot' +} +module.exports = { + currentUser, + UserTCConnCopilot +} diff --git a/test/unit/common/ResourceBookingData.js b/test/unit/common/ResourceBookingData.js new file mode 100644 index 00000000..4679a835 --- /dev/null +++ b/test/unit/common/ResourceBookingData.js @@ -0,0 +1,1004 @@ +const T01 = { + resourceBooking: { + request: { + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '36762910-4efa-4db4-9b2a-c9ab54c232ed', + startDate: '2021-04-03', + endDate: '2021-05-02', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + billingAccountId: 68800079 + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-03', + endDate: '2021-05-02', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + workPeriod: { + request: [{ + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + startDate: '2021-03-28', + endDate: '2021-04-03', + daysWorked: null, + paymentStatus: 'pending' + }, + { + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + startDate: '2021-04-04', + endDate: '2021-04-10', + daysWorked: null, + paymentStatus: 'pending' + }, + { + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: null, + paymentStatus: 'pending' + }, + { + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + startDate: '2021-04-18', + endDate: '2021-04-24', + daysWorked: null, + paymentStatus: 'pending' + }, + { + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + startDate: '2021-04-25', + endDate: '2021-05-01', + daysWorked: null, + paymentStatus: 'pending' + }, + { + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + startDate: '2021-05-02', + endDate: '2021-05-08', + daysWorked: null, + paymentStatus: 'pending' + }] + } +} +T01.resourceBooking.response.toJSON = () => T01.resourceBooking.response.dataValues +const T02 = { + resourceBooking: { + request: { + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '36762910-4efa-4db4-9b2a-c9ab54c232ed', + startDate: '2021-04-11', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + billingAccountId: 68800079 + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-11', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + workPeriod: { + request: [{ + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: null, + paymentStatus: 'pending' + }] + } +} +T02.resourceBooking.response.toJSON = () => T02.resourceBooking.response.dataValues +const T03 = { + resourceBooking: { + request: { + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '36762910-4efa-4db4-9b2a-c9ab54c232ed', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + billingAccountId: 68800079 + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: null, + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + } +} +T03.resourceBooking.response.toJSON = () => T03.resourceBooking.response.dataValues +const T04 = { + resourceBooking: { + request: { + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '36762910-4efa-4db4-9b2a-c9ab54c232ed', + startDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + billingAccountId: 68800079 + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-17', + endDate: null, + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + } +} +T04.resourceBooking.response.toJSON = () => T04.resourceBooking.response.dataValues +const T05 = { + resourceBooking: { + request: { + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '36762910-4efa-4db4-9b2a-c9ab54c232ed', + startDate: '2021-04-17', + endDate: '2021-04-16', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + billingAccountId: 68800079 + } + }, + error: { + message: 'endDate cannot be earlier than startDate' + } +} +const T06 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-11', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + }, + request: { + startDate: '2021-04-13', + endDate: '2021-04-15' + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-13', + endDate: '2021-04-15', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: null, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }] + } +} +T06.resourceBooking.value.toJSON = () => T06.resourceBooking.value.dataValues +T06.resourceBooking.value.update = () => T06.resourceBooking.response +T06.resourceBooking.response.toJSON = () => T06.resourceBooking.response.dataValues +const T07 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-11', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + }, + request: { + startDate: '2021-04-10', + endDate: '2021-04-15' + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-10', + endDate: '2021-04-15', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: null, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }], + request: [ + { + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + startDate: '2021-04-04', + endDate: '2021-04-10', + daysWorked: null, + paymentStatus: 'pending' + } + ] + } +} +T07.resourceBooking.value.toJSON = () => T07.resourceBooking.value.dataValues +T07.resourceBooking.value.update = () => T07.resourceBooking.response +T07.resourceBooking.response.toJSON = () => T07.resourceBooking.response.dataValues +const T08 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-11', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + }, + request: { + startDate: '2021-04-12', + endDate: '2021-04-18' + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-12', + endDate: '2021-04-18', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: null, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }], + request: [ + { + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + startDate: '2021-04-18', + endDate: '2021-04-24', + daysWorked: null, + paymentStatus: 'pending' + } + ] + } +} +T08.resourceBooking.value.toJSON = () => T08.resourceBooking.value.dataValues +T08.resourceBooking.value.update = () => T08.resourceBooking.response +T08.resourceBooking.response.toJSON = () => T08.resourceBooking.response.dataValues +const T09 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-10', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + }, + request: { + startDate: '2021-04-11', + endDate: '2021-04-15' + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-11', + endDate: '2021-04-15', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e90', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-04', + endDate: '2021-04-10', + daysWorked: null, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }, { + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: null, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }], + request: [ + '10faf505-d0e3-4d13-a817-7f1319625e90' + ] + } +} +T09.resourceBooking.value.toJSON = () => T09.resourceBooking.value.dataValues +T09.resourceBooking.value.update = () => T09.resourceBooking.response +T09.resourceBooking.response.toJSON = () => T09.resourceBooking.response.dataValues +const T10 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-10', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + }, + request: { + startDate: '2021-04-08', + endDate: '2021-04-10' + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-08', + endDate: '2021-04-10', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e90', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-04', + endDate: '2021-04-10', + daysWorked: null, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }, { + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: null, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }], + request: [ + '10faf505-d0e3-4d13-a817-7f1319625e91' + ] + } +} +T10.resourceBooking.value.toJSON = () => T10.resourceBooking.value.dataValues +T10.resourceBooking.value.update = () => T10.resourceBooking.response +T10.resourceBooking.response.toJSON = () => T10.resourceBooking.response.dataValues +const T11 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-10', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + }, + request: { + startDate: '2021-04-08', + endDate: '2021-04-13' + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-08', + endDate: '2021-04-13', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e90', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-04', + endDate: '2021-04-10', + daysWorked: 0, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }, { + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: 3, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }], + request: [ + '10faf505-d0e3-4d13-a817-7f1319625e91', + { daysWorked: 2 } + ] + } +} +T11.resourceBooking.value.toJSON = () => T11.resourceBooking.value.dataValues +T11.resourceBooking.value.update = () => T11.resourceBooking.response +T11.resourceBooking.response.toJSON = () => T11.resourceBooking.response.dataValues +const T12 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-05', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + }, + request: { + startDate: '2021-04-14', + endDate: '2021-04-24' + }, + response: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-14', + endDate: '2021-04-24', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e90', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-04', + endDate: '2021-04-10', + daysWorked: 4, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }, { + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: 4, + memberRate: null, + customerRate: null, + paymentStatus: 'partially-completed', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }], + request: [ + '10faf505-d0e3-4d13-a817-7f1319625e90', + '10faf505-d0e3-4d13-a817-7f1319625e91', + { daysWorked: 3 }, + { + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + startDate: '2021-04-18', + endDate: '2021-04-24', + daysWorked: null, + paymentStatus: 'pending' + } + ] + } +} +T12.resourceBooking.value.toJSON = () => T12.resourceBooking.value.dataValues +T12.resourceBooking.value.update = () => T12.resourceBooking.response +T12.resourceBooking.response.toJSON = () => T12.resourceBooking.response.dataValues +const T13 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-05', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + }, + request: { + status: 'cancelled' + } + }, + error: { + httpStatus: 400, + message: `WorkPeriods with id of 10faf505-d0e3-4d13-a817-7f1319625e91 + has completed or partially-completed payment status.` + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e90', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-04', + endDate: '2021-04-10', + daysWorked: 4, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }, { + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: 4, + memberRate: null, + customerRate: null, + paymentStatus: 'completed', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }] + } +} +T13.resourceBooking.value.toJSON = () => T13.resourceBooking.value.dataValues +const T14 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-05', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + }, + request: { + startDate: '2021-04-05', + endDate: '2021-04-10' + } + }, + error: { + httpStatus: 400, + message: `WorkPeriods with id of 10faf505-d0e3-4d13-a817-7f1319625e91 + has completed or partially-completed payment status.` + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e90', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-04', + endDate: '2021-04-10', + daysWorked: 4, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }, { + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: 4, + memberRate: null, + customerRate: null, + paymentStatus: 'completed', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }] + } +} +T14.resourceBooking.value.toJSON = () => T14.resourceBooking.value.dataValues +const T15 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-05', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e90', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-04', + endDate: '2021-04-10', + daysWorked: 4, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }, { + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: 4, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }], + request: ['10faf505-d0e3-4d13-a817-7f1319625e90', '10faf505-d0e3-4d13-a817-7f1319625e91'] + } +} +T15.resourceBooking.value.toJSON = () => T15.resourceBooking.value.dataValues +T15.resourceBooking.value.destroy = () => undefined +const T16 = { + resourceBooking: { + value: { + dataValues: { + id: '520bb632-a02a-415e-9857-93b2ecbf7d60', + projectId: 21, + userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', + jobId: '6093e58c-683d-4022-8482-5515e8345016', + startDate: '2021-04-05', + endDate: '2021-04-17', + memberRate: 13.23, + customerRate: 13, + rateType: 'hourly', + createdAt: '2020-10-09T04:24:01.048Z', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + status: 'sourcing', + billingAccountId: 68800079 + } + } + }, + error: { + httpStatus: 400, + message: `WorkPeriods with id of 10faf505-d0e3-4d13-a817-7f1319625e91 + has completed or partially-completed payment status.` + }, + workPeriod: { + response: [{ + id: '10faf505-d0e3-4d13-a817-7f1319625e90', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-04', + endDate: '2021-04-10', + daysWorked: 4, + memberRate: null, + customerRate: null, + paymentStatus: 'pending', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }, { + id: '10faf505-d0e3-4d13-a817-7f1319625e91', + resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', + userHandle: 'pshah_manager', + projectId: 21, + startDate: '2021-04-11', + endDate: '2021-04-17', + daysWorked: 4, + memberRate: null, + customerRate: null, + paymentStatus: 'completed', + createdBy: '00000000-0000-0000-0000-000000000000', + updatedBy: null, + createdAt: '2021-04-10T22:25:08.289Z', + updatedAt: '2021-04-10T22:25:08.289Z' + }] + } +} +T16.resourceBooking.value.toJSON = () => T16.resourceBooking.value.dataValues +module.exports = { + T01, + T02, + T03, + T04, + T05, + T06, + T07, + T08, + T09, + T10, + T11, + T12, + T13, + T14, + T15, + T16 +} diff --git a/test/unit/common/WorkPeriodPaymentData.js b/test/unit/common/WorkPeriodPaymentData.js new file mode 100644 index 00000000..d94d9280 --- /dev/null +++ b/test/unit/common/WorkPeriodPaymentData.js @@ -0,0 +1,41 @@ +const workPeriodPayment01 = { + request: { + workPeriodId: '467b4df7-ced4-41b9-9710-b83808cddaf4', + amount: 600, + status: 'completed' + }, + response: { + dataValues: { + workPeriodId: '467b4df7-ced4-41b9-9710-b83808cddaf4', + amount: 600, + status: 'completed', + id: '01971e6f-0f09-4a2a-bc2e-2adac0f00622', + challengeId: '00000000-0000-0000-0000-000000000000', + createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', + updatedAt: '2021-04-21T12:58:07.535Z', + createdAt: '2021-04-21T12:58:07.535Z', + updatedBy: null + } + }, + getUserIdResponse: '79a39efd-91af-494a-b0f6-62310495effd', + ensureWorkPeriodByIdResponse: { + projectId: 111, + userHandle: 'pshah_manager', + endDate: '2021-03-13' + }, + ensureResourceBookingByIdResponse: { + billingAccountId: 68800079 + }, + ensureResourceBookingByIdResponse02: {}, + createPaymentResponse: { + id: 'c65f0cbf-b197-423d-91cc-db6e3bad9075' + } +} + +workPeriodPayment01.response.toJSON = function () { + return workPeriodPayment01.response +} + +module.exports = { + workPeriodPayment01 +} diff --git a/test/unit/common/testData.js b/test/unit/common/testData.js deleted file mode 100644 index abf851b5..00000000 --- a/test/unit/common/testData.js +++ /dev/null @@ -1,545 +0,0 @@ - -const currentUser = { - userId: '00000000-0000-0000-0000-000000000000', - isMachine: true -} -const UserTCConnCopilot = { - userId: '4709473d-f060-4102-87f8-4d51ff0b34c1', - handle: 'TCConnCopilot' -} -const resourceBooking5Week = { - request: { - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '36762910-4efa-4db4-9b2a-c9ab54c232ed', - startDate: '2020-09-27', - endDate: '2020-10-27', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly' - }, - response: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-09-27', - endDate: '2020-10-27', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - status: 'sourcing' - } - }, - workPeriodRequests: [{ - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - startDate: '2020-09-27', - endDate: '2020-10-03', - daysWorked: 5, - paymentStatus: 'pending' - }, - { - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - startDate: '2020-10-04', - endDate: '2020-10-10', - daysWorked: 5, - paymentStatus: 'pending' - }, - { - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - startDate: '2020-10-11', - endDate: '2020-10-17', - daysWorked: 5, - paymentStatus: 'pending' - }, - { - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - startDate: '2020-10-18', - endDate: '2020-10-24', - daysWorked: 5, - paymentStatus: 'pending' - }, - { - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - startDate: '2020-10-25', - endDate: '2020-10-31', - daysWorked: 2, - paymentStatus: 'pending' - }] -} -resourceBooking5Week.response.toJSON = function () { - return resourceBooking5Week.response.dataValues -} -const resourceBooking1Week = { - request: { - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '36762910-4efa-4db4-9b2a-c9ab54c232ed', - startDate: '2020-11-20', - endDate: '2020-11-21', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly' - }, - response: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-11-20', - endDate: '2020-11-21', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - status: 'sourcing' - } - }, - workPeriodRequests: [{ - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - startDate: '2020-11-15', - endDate: '2020-11-21', - daysWorked: 1, - paymentStatus: 'pending' - }], - workPeriodResponse: [{ - id: '10faf505-d0e3-4d13-a817-7f1319625e91', - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - userHandle: 'pshah_manager', - projectId: 21, - startDate: '2020-11-15', - endDate: '2020-11-21', - daysWorked: 2, - memberRate: null, - customerRate: null, - paymentStatus: 'pending', - createdBy: '00000000-0000-0000-0000-000000000000', - updatedBy: null, - createdAt: '2021-04-10T22:25:08.289Z', - updatedAt: '2021-04-10T22:25:08.289Z' - }], - updateRequest: { - startDate: '2020-11-18' - }, - updateResponse: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-11-18', - endDate: '2020-11-21', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - updatedBy: '00000000-0000-0000-0000-000000000000', - status: 'sourcing' - } - }, - workPeriodUpdateRequests: [{ - daysWorked: 3 - }] -} -resourceBooking1Week.response.toJSON = function () { - return resourceBooking1Week.response.dataValues -} -resourceBooking1Week.updateResponse.toJSON = function () { - return resourceBooking1Week.updateResponse.dataValues -} -resourceBooking1Week.response.update = function () { - return resourceBooking1Week.updateResponse -} -const resourceBookingUpdate = { - response: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-08-20', - endDate: '2020-09-10', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - status: 'sourcing' - } - }, - workPeriodResponse: [{ - id: '10faf505-d0e3-4d13-a817-7f1319625e91', - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - userHandle: 'pshah_manager', - projectId: 21, - startDate: '2020-08-16', - endDate: '2020-08-22', - daysWorked: 2, - memberRate: null, - customerRate: null, - paymentStatus: 'pending', - createdBy: '00000000-0000-0000-0000-000000000000', - updatedBy: null, - createdAt: '2021-04-10T22:25:08.289Z', - updatedAt: '2021-04-10T22:25:08.289Z' - }, { - id: 'b18398fe-09d0-4671-95b9-a4f56e6c6879', - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - userHandle: 'pshah_manager', - projectId: 21, - startDate: '2020-08-23', - endDate: '2020-08-29', - daysWorked: 5, - memberRate: null, - customerRate: null, - paymentStatus: 'pending', - createdBy: '00000000-0000-0000-0000-000000000000', - updatedBy: null, - createdAt: '2021-04-10T22:25:08.289Z', - updatedAt: '2021-04-10T22:25:08.289Z' - }, { - id: 'de811f42-cae7-4cb7-8893-d1e1f83b998f', - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - userHandle: 'pshah_manager', - projectId: 21, - startDate: '2020-08-30', - endDate: '2020-09-05', - daysWorked: 5, - memberRate: null, - customerRate: null, - paymentStatus: 'pending', - createdBy: '00000000-0000-0000-0000-000000000000', - updatedBy: null, - createdAt: '2021-04-10T22:25:08.289Z', - updatedAt: '2021-04-10T22:25:08.289Z' - }, { - id: '171e7f32-36fd-4969-9a99-036ced807d53', - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - userHandle: 'pshah_manager', - projectId: 21, - startDate: '2020-09-06', - endDate: '2020-09-12', - daysWorked: 4, - memberRate: null, - customerRate: null, - paymentStatus: 'pending', - createdBy: '00000000-0000-0000-0000-000000000000', - updatedBy: null, - createdAt: '2021-04-10T22:25:08.289Z', - updatedAt: '2021-04-10T22:25:08.289Z' - }], - updateRequest: { - endDate: '2020-09-12' - }, - updateResponse: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-08-20', - endDate: '2020-09-12', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - updatedBy: '00000000-0000-0000-0000-000000000000', - status: 'sourcing' - } - }, - workPeriodUpdateRequests: [{ - daysWorked: 5 - }], - response2: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-08-20', - endDate: '2020-09-10', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - status: 'sourcing' - } - }, - updateRequest2: { - endDate: '2020-09-15' - }, - updateResponse2: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-08-20', - endDate: '2020-09-15', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - updatedBy: '00000000-0000-0000-0000-000000000000', - status: 'sourcing' - } - }, - workPeriodUpdateRequests2: [{ - daysWorked: 5 - }, { - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - startDate: '2020-09-13', - endDate: '2020-09-19', - daysWorked: 2, - paymentStatus: 'pending' - }], - response3: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-08-20', - endDate: '2020-09-10', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - status: 'sourcing' - } - }, - updateRequest3: { - startDate: '2020-08-25' - }, - updateResponse3: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-08-25', - endDate: '2020-09-10', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - updatedBy: '00000000-0000-0000-0000-000000000000', - status: 'sourcing' - } - }, - workPeriodUpdateRequests3: [ - 'b18398fe-09d0-4671-95b9-a4f56e6c6879', { - daysWorked: 4 - }, - '10faf505-d0e3-4d13-a817-7f1319625e91', - '10faf505-d0e3-4d13-a817-7f1319625e91', - 'b18398fe-09d0-4671-95b9-a4f56e6c6879', - 'de811f42-cae7-4cb7-8893-d1e1f83b998f', - '171e7f32-36fd-4969-9a99-036ced807d53' - ], - response4: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-08-20', - endDate: '2020-09-10', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - status: 'sourcing' - } - }, - workPeriodResponse4: [{ - id: '10faf505-d0e3-4d13-a817-7f1319625e91', - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - userHandle: 'pshah_manager', - projectId: 21, - startDate: '2020-08-16', - endDate: '2020-08-22', - daysWorked: 2, - memberRate: null, - customerRate: null, - paymentStatus: 'pending', - createdBy: '00000000-0000-0000-0000-000000000000', - updatedBy: null, - createdAt: '2021-04-10T22:25:08.289Z', - updatedAt: '2021-04-10T22:25:08.289Z' - }, { - id: 'b18398fe-09d0-4671-95b9-a4f56e6c6879', - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - userHandle: 'pshah_manager', - projectId: 21, - startDate: '2020-08-23', - endDate: '2020-08-29', - daysWorked: 5, - memberRate: null, - customerRate: null, - paymentStatus: 'completed', - createdBy: '00000000-0000-0000-0000-000000000000', - updatedBy: null, - createdAt: '2021-04-10T22:25:08.289Z', - updatedAt: '2021-04-10T22:25:08.289Z' - }, { - id: '89f89450-201c-42e3-a868-a87177b82584', - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - userHandle: 'pshah_manager', - projectId: 21, - startDate: '2020-08-30', - endDate: '2020-09-05', - daysWorked: 5, - memberRate: null, - customerRate: null, - paymentStatus: 'partially-completed', - createdBy: '00000000-0000-0000-0000-000000000000', - updatedBy: null, - createdAt: '2021-04-10T22:25:08.289Z', - updatedAt: '2021-04-10T22:25:08.289Z' - }, { - id: '3907e916-efdc-49d3-b0ef-970ccf7d78b0', - resourceBookingId: '520bb632-a02a-415e-9857-93b2ecbf7d60', - userHandle: 'pshah_manager', - projectId: 21, - startDate: '2020-09-06', - endDate: '2020-09-12', - daysWorked: 4, - memberRate: null, - customerRate: null, - paymentStatus: 'pending', - createdBy: '00000000-0000-0000-0000-000000000000', - updatedBy: null, - createdAt: '2021-04-10T22:25:08.289Z', - updatedAt: '2021-04-10T22:25:08.289Z' - }], - updateRequest4: { - startDate: '2020-08-25', - endDate: '2020-09-05' - }, - updateResponse4: { - dataValues: { - id: '520bb632-a02a-415e-9857-93b2ecbf7d60', - projectId: 21, - userId: 'a55fe1bc-1754-45fa-9adc-cf3d6d7c377a', - jobId: '6093e58c-683d-4022-8482-5515e8345016', - startDate: '2020-08-25', - endDate: '2020-09-05', - memberRate: 13.23, - customerRate: 13, - rateType: 'hourly', - createdAt: '2020-10-09T04:24:01.048Z', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - updatedBy: '00000000-0000-0000-0000-000000000000', - status: 'sourcing' - } - }, - workPeriodUpdateRequests4: [{ - daysWorked: 4 - }, '10faf505-d0e3-4d13-a817-7f1319625e91', '3907e916-efdc-49d3-b0ef-970ccf7d78b0'], - updateRequest5: { - startDate: '2020-08-24', - endDate: '2020-08-29' - }, - updateRequest6: { - status: 'cancelled' - } -} -resourceBookingUpdate.response.toJSON = function () { - return resourceBookingUpdate.response.dataValues -} -resourceBookingUpdate.updateResponse.toJSON = function () { - return resourceBookingUpdate.updateResponse.dataValues -} -resourceBookingUpdate.response.update = function () { - return resourceBookingUpdate.updateResponse -} -resourceBookingUpdate.response2.toJSON = function () { - return resourceBookingUpdate.response2.dataValues -} -resourceBookingUpdate.updateResponse2.toJSON = function () { - return resourceBookingUpdate.updateResponse2.dataValues -} -resourceBookingUpdate.response2.update = function () { - return resourceBookingUpdate.updateResponse2 -} -resourceBookingUpdate.response3.toJSON = function () { - return resourceBookingUpdate.response3.dataValues -} -resourceBookingUpdate.updateResponse3.toJSON = function () { - return resourceBookingUpdate.updateResponse3.dataValues -} -resourceBookingUpdate.response3.update = function () { - return resourceBookingUpdate.updateResponse3 -} -resourceBookingUpdate.response3.destroy = function () { - -} -resourceBookingUpdate.response4.toJSON = function () { - return resourceBookingUpdate.response4.dataValues -} -resourceBookingUpdate.updateResponse4.toJSON = function () { - return resourceBookingUpdate.updateResponse4.dataValues -} -resourceBookingUpdate.response4.update = function () { - return resourceBookingUpdate.updateResponse4 -} - -const workPeriodPayment01 = { - request: { - workPeriodId: '467b4df7-ced4-41b9-9710-b83808cddaf4', - amount: 600, - status: 'completed' - }, - response: { - dataValues: { - workPeriodId: '467b4df7-ced4-41b9-9710-b83808cddaf4', - amount: 600, - status: 'completed', - id: '01971e6f-0f09-4a2a-bc2e-2adac0f00622', - challengeId: '00000000-0000-0000-0000-000000000000', - createdBy: '57646ff9-1cd3-4d3c-88ba-eb09a395366c', - updatedAt: '2021-04-21T12:58:07.535Z', - createdAt: '2021-04-21T12:58:07.535Z', - updatedBy: null - } - }, - getUserIdResponse: '79a39efd-91af-494a-b0f6-62310495effd', - ensureWorkPeriodByIdResponse: { - projectId: 111, - userHandle: 'pshah_manager', - endDate: '2021-03-13' - }, - ensureResourceBookingByIdResponse: { - billingAccountId: 68800079 - }, - ensureResourceBookingByIdResponse02: {}, - createPaymentResponse: { - id: 'c65f0cbf-b197-423d-91cc-db6e3bad9075' - } -} - -workPeriodPayment01.response.toJSON = function () { - return workPeriodPayment01.response -} - -module.exports = { - currentUser, - UserTCConnCopilot, - resourceBooking5Week, - resourceBooking1Week, - resourceBookingUpdate, - workPeriodPayment01 -}