-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: partner and public matching (#4090)
* fix: partner and public matching * fix: improved test coverage * fix: consistent text labeling * fix: unit testing
- Loading branch information
1 parent
1f96fbb
commit 0efab7a
Showing
3 changed files
with
222 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -664,12 +664,13 @@ describe('Testing user service', () => { | |
}); | ||
|
||
describe('forgotPassword', () => { | ||
it('should set resetToken', async () => { | ||
it('should set resetToken when public user on public site', async () => { | ||
const id = randomUUID(); | ||
const email = '[email protected]'; | ||
|
||
prisma.userAccounts.findUnique = jest.fn().mockResolvedValue({ | ||
id, | ||
jurisdictions: [{ publicUrl: 'http://localhost:3000' }], | ||
}); | ||
prisma.userAccounts.update = jest.fn().mockResolvedValue({ | ||
id, | ||
|
@@ -699,6 +700,109 @@ describe('Testing user service', () => { | |
}); | ||
}); | ||
|
||
it('should not set resetToken when public user on partner site', async () => { | ||
const id = randomUUID(); | ||
const email = '[email protected]'; | ||
|
||
prisma.userAccounts.findUnique = jest.fn().mockResolvedValue({ | ||
id, | ||
jurisdictions: [{ publicUrl: 'http://localhost:3000' }], | ||
}); | ||
prisma.userAccounts.update = jest.fn().mockResolvedValue({ | ||
id, | ||
resetToken: 'example reset token', | ||
}); | ||
emailService.forgotPassword = jest.fn(); | ||
|
||
await service.forgotPassword({ | ||
email, | ||
appUrl: process.env.PARTNERS_PORTAL_URL, | ||
}); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
include: { | ||
jurisdictions: true, | ||
listings: true, | ||
userRoles: true, | ||
}, | ||
where: { | ||
email, | ||
id: undefined, | ||
}, | ||
}); | ||
expect(prisma.userAccounts.update).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should set resetToken when partner user on partner site', async () => { | ||
const id = randomUUID(); | ||
const email = '[email protected]'; | ||
|
||
prisma.userAccounts.findUnique = jest.fn().mockResolvedValue({ | ||
id, | ||
userRoles: { isAdmin: true }, | ||
}); | ||
prisma.userAccounts.update = jest.fn().mockResolvedValue({ | ||
id, | ||
resetToken: 'example reset token', | ||
}); | ||
emailService.forgotPassword = jest.fn(); | ||
|
||
await service.forgotPassword({ | ||
email, | ||
appUrl: process.env.PARTNERS_PORTAL_URL, | ||
}); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
include: { | ||
jurisdictions: true, | ||
listings: true, | ||
userRoles: true, | ||
}, | ||
where: { | ||
email, | ||
id: undefined, | ||
}, | ||
}); | ||
expect(prisma.userAccounts.update).toHaveBeenCalledWith({ | ||
data: { | ||
resetToken: expect.anything(), | ||
}, | ||
where: { | ||
id, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should not set resetToken when partner user on public site', async () => { | ||
const id = randomUUID(); | ||
const email = '[email protected]'; | ||
|
||
prisma.userAccounts.findUnique = jest.fn().mockResolvedValue({ | ||
id, | ||
userRoles: { isAdmin: true }, | ||
}); | ||
prisma.userAccounts.update = jest.fn().mockResolvedValue({ | ||
id, | ||
resetToken: 'example reset token', | ||
}); | ||
emailService.forgotPassword = jest.fn(); | ||
|
||
await service.forgotPassword({ | ||
email, | ||
appUrl: 'http://localhost:3000', | ||
}); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
include: { | ||
jurisdictions: true, | ||
listings: true, | ||
userRoles: true, | ||
}, | ||
where: { | ||
email, | ||
id: undefined, | ||
}, | ||
}); | ||
expect(prisma.userAccounts.update).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should error when trying to set resetToken on nonexistent user', async () => { | ||
const email = '[email protected]'; | ||
|
||
|