-
Notifications
You must be signed in to change notification settings - Fork 0
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 #186 from alphamanuscript/master
Remove country code from donate link
- Loading branch information
Showing
11 changed files
with
166 additions
and
32 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './types'; | ||
export { DistributionReports, REPORT_TYPE_DAILY, REPORT_TYPE_MONTHLY, DISTRIBUTION_REPORT_ENHANCED } from './distribution-report-service'; | ||
export { DistributionReports, REPORT_TYPE_DAILY, REPORT_TYPE_MONTHLY, EnhancedDistributionReport } from './distribution-report-service'; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './types'; | ||
export { Links } from './link-generator-service'; | ||
export { BitlyLinkShortener, LinkShortener } from './bitly-link-shortener'; | ||
export { BitlyLinkShortener } from './bitly-link-shortener'; |
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
74 changes: 74 additions & 0 deletions
74
server/src/core/link-generator/tests/link-generator-service.test.ts
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,74 @@ | ||
import { Links } from '../link-generator-service'; | ||
import { User } from '../../user'; | ||
import { LinkShortener } from '../types'; | ||
|
||
describe('LinkGeneratorService tests', () => { | ||
const baseUrl = 'https://test.com'; | ||
let shortener: LinkShortener; | ||
|
||
function getService() { | ||
return new Links({ shortener, baseUrl: baseUrl }); | ||
} | ||
|
||
beforeEach(() => { | ||
shortener = { | ||
shortenLink: (link) => Promise.resolve(`shorten_${link}`) | ||
}; | ||
}); | ||
|
||
|
||
describe('getDonateLink', () => { | ||
test('should generate shortened donate link with arguments url encoded', async () => { | ||
const service = getService(); | ||
const link = await service.getDonateLink({ | ||
name: 'John Doe', | ||
phone: '711000222', | ||
email: '[email protected]', | ||
amount: 3000 | ||
}); | ||
|
||
expect(link).toEqual('shorten_https://test.com?donate=1&n=John%20Doe&e=test%40mailer.com&p=711000222&a=3000'); | ||
}); | ||
|
||
test('should omit missing values from generated link', async () => { | ||
const service = getService(); | ||
const link = await service.getDonateLink({ | ||
name: 'John Doe', | ||
email: '[email protected]' | ||
}); | ||
|
||
expect(link).toEqual('shorten_https://test.com?donate=1&n=John%20Doe&e=test%40mailer.com'); | ||
}); | ||
|
||
test('should not shorten link if shorten option is false', async () => { | ||
const service = getService(); | ||
const link = await service.getDonateLink({ | ||
name: 'John Doe', | ||
phone: '711000222', | ||
email: '[email protected]', | ||
amount: 3000 | ||
}, false); | ||
|
||
expect(link).toEqual('https://test.com?donate=1&n=John%20Doe&e=test%40mailer.com&p=711000222&a=3000'); | ||
}); | ||
}); | ||
|
||
describe('getUserDonateLink', () => { | ||
test('should generate a shortened link for the specified user', async () => { | ||
const service = getService(); | ||
const link = await service.getUserDonateLink({ | ||
_id: 'u1', | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
phone: '254711000222', | ||
addedBy: '', | ||
donors: [], | ||
roles: [], | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}, 3000); | ||
|
||
expect(link).toEqual('shorten_https://test.com?donate=1&n=John%20Doe&e=test%40mailer.com&p=711000222&a=3000'); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,13 +1,44 @@ | ||
import { User } from '../user'; | ||
|
||
export interface DonateLinkArgs { | ||
name: string, | ||
email: string, | ||
phone: string, | ||
amount: number | ||
/** | ||
* name of the donor | ||
*/ | ||
name?: string, | ||
/** | ||
* email of the donor | ||
*/ | ||
email?: string, | ||
/** | ||
* phone number of the donor (should not include country code) | ||
*/ | ||
phone?: string, | ||
/** | ||
* The amount to donate | ||
*/ | ||
amount?: number, | ||
/** | ||
* Whether to shorten the link using a LinkShortener | ||
*/ | ||
shorten?: boolean | ||
} | ||
|
||
export interface LinkGeneratorService { | ||
getUserDonateLink(user: User, amount: number): Promise<string>; | ||
getDonateLink(args: DonateLinkArgs): string; | ||
} | ||
/** | ||
* Generates a donation link for the specified user | ||
* @param user the user to generate a link for | ||
* @param amount the amount to donate | ||
* @param shorten whether to shorten the link (defaults to true) | ||
*/ | ||
getUserDonateLink(user: User, amount: number, shorten?: boolean): Promise<string>; | ||
/** | ||
* Generates a donation link with the specified arguments | ||
* @param args | ||
* @param shorten whether to shorten link (defaults to true) | ||
*/ | ||
getDonateLink(args: DonateLinkArgs, shorten?: boolean): Promise<string>; | ||
} | ||
|
||
export interface LinkShortener { | ||
shortenLink(link: string): Promise<string>; | ||
} |
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