-
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.
feat: 3909/add redirect url prisma (#3938)
* feat: get email url from getPublicEmailURL * fix: handle undefined url case and simplify parsing * fix: use only baseUrl in welcome and password emails * fix: fix test
- Loading branch information
1 parent
dfd580c
commit d54b9a6
Showing
6 changed files
with
101 additions
and
17 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Creates a email URL object from passed url applies redirectUrl and listingId query params if they exist | ||
* If they do not exist, the return value will be the email url with just the necessary token | ||
*/ | ||
|
||
export const getPublicEmailURL = ( | ||
url: string, | ||
token: string, | ||
actionPath?: string, | ||
): string => { | ||
if (!url) { | ||
return; | ||
} | ||
const urlObj = new URL(url); | ||
const redirectUrl = urlObj.searchParams.get('redirectUrl'); | ||
const listingId = urlObj.searchParams.get('listingId'); | ||
|
||
let emailUrl = `${urlObj.origin}${ | ||
actionPath ? actionPath : '' | ||
}?token=${token}`; | ||
|
||
if (!!redirectUrl && !!listingId) { | ||
emailUrl = emailUrl.concat( | ||
`&redirectUrl=${redirectUrl}&listingId=${listingId}`, | ||
); | ||
} | ||
return emailUrl; | ||
}; |
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 |
---|---|---|
|
@@ -311,15 +311,36 @@ describe('Testing user service', () => { | |
|
||
describe('getPublicConfirmationUrl', () => { | ||
it('should build public confirmation url', () => { | ||
const res = service.getPublicConfirmationUrl('url', 'tokenExample'); | ||
expect(res).toEqual('url?token=tokenExample'); | ||
const res = service.getPublicConfirmationUrl( | ||
'https://www.example.com', | ||
'tokenExample', | ||
); | ||
expect(res).toEqual('https://www.example.com?token=tokenExample'); | ||
}); | ||
it('should build public confirmation url with query params', () => { | ||
const res = service.getPublicConfirmationUrl( | ||
'https://www.example.com?redirectUrl=redirect&listingId=123', | ||
'tokenExample', | ||
); | ||
expect(res).toEqual( | ||
'https://www.example.com?token=tokenExample&redirectUrl=redirect&listingId=123', | ||
); | ||
}); | ||
it('should return undefined when url is undefined', () => { | ||
const res = service.getPublicConfirmationUrl(undefined, 'tokenExample'); | ||
expect(res).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('getPartnersConfirmationUrl', () => { | ||
it('should build partner confirmation url', () => { | ||
const res = service.getPartnersConfirmationUrl('url', 'tokenExample'); | ||
expect(res).toEqual('url/users/confirm?token=tokenExample'); | ||
const res = service.getPartnersConfirmationUrl( | ||
'https://www.example.com', | ||
'tokenExample', | ||
); | ||
expect(res).toEqual( | ||
'https://www.example.com/users/confirm?token=tokenExample', | ||
); | ||
}); | ||
}); | ||
|
||
|
@@ -910,7 +931,7 @@ describe('Testing user service', () => { | |
id: 'requestingUser id', | ||
userRoles: { isAdmin: true }, | ||
} as unknown as User, | ||
'juris name', | ||
'jurisdictionName', | ||
); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
include: { | ||
|
@@ -981,7 +1002,7 @@ describe('Testing user service', () => { | |
id: 'requestingUser id', | ||
userRoles: { isAdmin: true }, | ||
} as unknown as User, | ||
'juris name', | ||
'jurisdictionName', | ||
); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
include: { | ||
|
@@ -1055,7 +1076,7 @@ describe('Testing user service', () => { | |
id: 'requestingUser id', | ||
userRoles: { isAdmin: true }, | ||
} as unknown as User, | ||
'juris name', | ||
'jurisdictionName', | ||
), | ||
).rejects.toThrowError(`userID ${id}: request missing currentPassword`); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
|
@@ -1112,7 +1133,7 @@ describe('Testing user service', () => { | |
id: 'requestingUser id', | ||
userRoles: { isAdmin: true }, | ||
} as unknown as User, | ||
'juris name', | ||
'jurisdictionName', | ||
), | ||
).rejects.toThrowError( | ||
`userID ${id}: incoming password doesn't match stored password`, | ||
|
@@ -1161,14 +1182,14 @@ describe('Testing user service', () => { | |
lastName: 'last name', | ||
jurisdictions: [{ id: jurisId }], | ||
newEmail: '[email protected]', | ||
appUrl: 'www.example.com', | ||
appUrl: 'https://www.example.com', | ||
agreedToTermsOfService: true, | ||
}, | ||
{ | ||
id: 'requestingUser id', | ||
userRoles: { isAdmin: true }, | ||
} as unknown as User, | ||
'juris name', | ||
'jurisdictionName', | ||
); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
include: { | ||
|
@@ -1242,7 +1263,7 @@ describe('Testing user service', () => { | |
id: 'requestingUser id', | ||
userRoles: { isAdmin: true }, | ||
} as unknown as User, | ||
'juris name', | ||
'jurisdictionName', | ||
); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
include: { | ||
|
@@ -1334,7 +1355,7 @@ describe('Testing user service', () => { | |
id: 'requestingUser id', | ||
userRoles: { isAdmin: true }, | ||
} as unknown as User, | ||
'juris name', | ||
'jurisdictionName', | ||
), | ||
).rejects.toThrowError(`user id: ${id} was requested but not found`); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
|
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