forked from bloom-housing/bloom
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 628/demographic-spoken-language-bugs
- Loading branch information
Showing
5 changed files
with
226 additions
and
12 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 |
---|---|---|
|
@@ -670,12 +670,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, | ||
|
@@ -705,6 +706,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]'; | ||
|
||
|
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