-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from chaynHQ/develop
Merge Develop onto Main
- Loading branch information
Showing
7 changed files
with
335 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -431,6 +431,7 @@ describe('WebhooksService', () => { | |
courseSaveRepoSpy.mockClear(); | ||
}); | ||
}); | ||
|
||
describe('updatePartnerAccessTherapy', () => { | ||
it('should update the booking time when action is update and time is different TODO ', async () => { | ||
const newStartTime = '2022-09-12T09:30:00+0000'; | ||
|
@@ -447,17 +448,17 @@ describe('WebhooksService', () => { | |
expect(therapyRepoFindOneSpy).toBeCalled(); | ||
}); | ||
|
||
it('should throw when action is on a user that doesnt exist', async () => { | ||
it('should throw an error when action is on a user that doesnt exist', async () => { | ||
const userFindOneRepoSpy = jest | ||
.spyOn(mockedUserRepository, 'findOne') | ||
.mockImplementationOnce(() => undefined); | ||
await expect(service.updatePartnerAccessTherapy(mockSimplybookBodyBase)).rejects.toThrowError( | ||
'Unable to find user', | ||
'UpdatePartnerAccessTherapy - error finding user with userID 115e272a-5fc3-4991-8ea9-12dacad25bae and origin client_email [email protected]', | ||
); | ||
expect(userFindOneRepoSpy).toBeCalled(); | ||
}); | ||
|
||
it('when creating a new therapy session and the client_id/ userId is not provided, it should get userId from previous entry', async () => { | ||
it('when creating a new therapy session and the userId is not provided, it should get userId from previous entry', async () => { | ||
const findTherapySessionSpy = jest | ||
.spyOn(mockedTherapySessionRepository, 'findOne') | ||
.mockImplementationOnce(async () => { | ||
|
@@ -470,7 +471,7 @@ describe('WebhooksService', () => { | |
}); | ||
const newTherapySession = await service.updatePartnerAccessTherapy({ | ||
...mockSimplybookBodyBase, | ||
client_id: undefined, | ||
user_id: undefined, | ||
action: SIMPLYBOOK_ACTION_ENUM.NEW_BOOKING, | ||
}); | ||
|
||
|
@@ -484,16 +485,17 @@ describe('WebhooksService', () => { | |
}); | ||
|
||
expect(findTherapySessionSpy).toBeCalledWith({ | ||
clientEmail: mockSimplybookBodyBase.client_email, | ||
where: `"clientEmail" ILIKE '[email protected]' AND "bookingCode" LIKE 'abc'`, | ||
}); | ||
|
||
expect(findPartnerAccessSpy).toBeCalledWith({ | ||
userId: 'userId1', | ||
featureTherapy: true, | ||
active: true, | ||
}); | ||
}); | ||
|
||
it('when creating a new therapy session and the client_id/ userId is not provided and no previousTherapySession exists, it should get userId from the userDatabase', async () => { | ||
it('when creating a new therapy session and the user_id/ userId is not provided and no previousTherapySession exists, it should get userId from the userDatabase', async () => { | ||
const findTherapySessionSpy = jest | ||
.spyOn(mockedTherapySessionRepository, 'findOne') | ||
.mockImplementationOnce(async () => { | ||
|
@@ -508,7 +510,7 @@ describe('WebhooksService', () => { | |
}); | ||
const newTherapySession = await service.updatePartnerAccessTherapy({ | ||
...mockSimplybookBodyBase, | ||
client_id: undefined, | ||
user_id: undefined, | ||
action: SIMPLYBOOK_ACTION_ENUM.NEW_BOOKING, | ||
}); | ||
|
||
|
@@ -522,18 +524,28 @@ describe('WebhooksService', () => { | |
}); | ||
|
||
expect(findTherapySessionSpy).toBeCalledWith({ | ||
clientEmail: mockSimplybookBodyBase.client_email, | ||
where: `"clientEmail" ILIKE '[email protected]' AND "bookingCode" LIKE 'abc'`, | ||
}); | ||
expect(findUserSpy).toBeCalledWith({ | ||
email: mockSimplybookBodyBase.client_email, | ||
id: 'userId1', | ||
}); | ||
|
||
expect(findPartnerAccessSpy).toBeCalledWith({ | ||
userId: 'userId1', | ||
featureTherapy: true, | ||
active: true, | ||
}); | ||
}); | ||
|
||
it('should not error when client email is different case to user record email', async () => { | ||
await expect( | ||
service.updatePartnerAccessTherapy({ | ||
...mockSimplybookBodyBase, | ||
client_email: '[email protected]', | ||
}), | ||
).resolves.toHaveProperty('action', SIMPLYBOOK_ACTION_ENUM.UPDATED_BOOKING); | ||
}); | ||
|
||
it('should set a booking as cancelled when action is cancel', async () => { | ||
await expect( | ||
service.updatePartnerAccessTherapy({ | ||
|
@@ -542,12 +554,28 @@ describe('WebhooksService', () => { | |
}), | ||
).resolves.toHaveProperty('action', SIMPLYBOOK_ACTION_ENUM.CANCELLED_BOOKING); | ||
}); | ||
|
||
it('should add therapyRemaining to original partner access when action is cancel', async () => { | ||
const partnerAccessSaveSpy = jest.spyOn(mockedPartnerAccessRepository, 'save'); | ||
await expect( | ||
service.updatePartnerAccessTherapy({ | ||
...mockSimplybookBodyBase, | ||
...{ action: SIMPLYBOOK_ACTION_ENUM.CANCELLED_BOOKING }, | ||
}), | ||
).resolves.toHaveProperty('action', SIMPLYBOOK_ACTION_ENUM.CANCELLED_BOOKING); | ||
expect(partnerAccessSaveSpy).toBeCalledWith({ | ||
...mockPartnerAccessEntity, | ||
therapySessionsRemaining: mockPartnerAccessEntity.therapySessionsRemaining + 1, | ||
therapySessionsRedeemed: mockPartnerAccessEntity.therapySessionsRedeemed - 1, | ||
}); | ||
}); | ||
|
||
it('should set a booking as cancelled when action is cancel and there are no therapy sessions remaining TODO', async () => { | ||
// mock that there is no therapy sessions remaining on partner access | ||
const partnerAccessFindSpy = jest | ||
.spyOn(mockedPartnerAccessRepository, 'find') | ||
.spyOn(mockedPartnerAccessRepository, 'findOne') | ||
.mockImplementationOnce(async () => { | ||
return [{ ...mockPartnerAccessEntity, therapySessionsRemaining: 0 }]; | ||
return { ...mockPartnerAccessEntity, therapySessionsRemaining: 0 }; | ||
}); | ||
await expect( | ||
service.updatePartnerAccessTherapy({ | ||
|
@@ -567,7 +595,9 @@ describe('WebhooksService', () => { | |
...mockSimplybookBodyBase, | ||
...{ action: SIMPLYBOOK_ACTION_ENUM.NEW_BOOKING }, | ||
}), | ||
).rejects.toThrow('Unable to find partner access'); | ||
).rejects.toThrow( | ||
'newPartnerAccessTherapy - no partner therapy access - email [email protected] userId userId1', | ||
); | ||
}); | ||
it('should deduct therapyRemaining when user creates a new booking', async () => { | ||
jest.spyOn(mockedPartnerAccessRepository, 'find').mockImplementationOnce(async () => { | ||
|
@@ -611,7 +641,9 @@ describe('WebhooksService', () => { | |
...mockSimplybookBodyBase, | ||
...{ action: SIMPLYBOOK_ACTION_ENUM.NEW_BOOKING }, | ||
}), | ||
).rejects.toThrowError('No therapy sessions remaining'); | ||
).rejects.toThrowError( | ||
'newPartnerAccessTherapy - user has partner therapy access but has 0 therapy sessions remaining - email [email protected] userId userId1', | ||
); | ||
}); | ||
it('if user has 2 partner access codes and booking is tied to second code, user should be able to update booking', async () => { | ||
jest.spyOn(mockedPartnerAccessRepository, 'find').mockImplementationOnce(async () => { | ||
|
@@ -844,7 +876,7 @@ describe('WebhooksService', () => { | |
}); | ||
|
||
await expect(service.createEventLog(eventDto)).rejects.toThrowError( | ||
`webhooksService.createEventLog error, no user attached to email ${eventDto.email}`, | ||
`createEventLog webhook failed - no user attached to email [email protected]`, | ||
); | ||
}); | ||
it('should throw 500 if failed to create user', async () => { | ||
|
Oops, something went wrong.