Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Commit

Permalink
feat: add --payee option
Browse files Browse the repository at this point in the history
Add an option to override the payee

re #21
  • Loading branch information
starsprung committed Jan 9, 2021
1 parent 44a836b commit 86da1a6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Options can also be saved in a config file. The location of this file is platfor
| --cleared | CLEARED | cleared | Whether transactions should be added as cleared by default | true |
| --debug-mode | DEBUG_MODE | debugMode | Run the internal browser in visible/slo-mo mode | false |
| --log-level | LOG_LEVEL | logLevel | Level of logs to output. Possible values: "debug", "info", "error", "none", "silly" | info |
| --payee | PAYEE | payee | Override the "Payee" field in YNAB with this value. If unset it will default to the seller name or Amazon.com | |
| --start-date | START_DATE | startDate | Only sync transactions which appear after this date. | 30 days ago |
| --ynab-access-token | YNAB_ACCESS_TOKEN | ynabAccessToken | [YNAB personal access token](https://api.youneedabudget.com/#personal-access-tokens) | |
| --ynab-account-name | YNAB_ACCOUNT_NAME | ynabAccountName | Name of YNAB account in which you wish to record Amazon transactions | |
Expand Down
1 change: 1 addition & 0 deletions src/__mocks__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const mocks = {
cacheDir: jest.fn(() => normalize('/path/to/cache/')),
cleared: jest.fn(() => true),
logLevel: jest.fn(() => 'none'),
payee: jest.fn(() => undefined),
ynabAccessToken: jest.fn(() => 'f82918ba-4aa7-4805-b9be-fe5e87eaacf3'),
ynabAccountName: jest.fn(() => 'Amazon.com'),
ynabBudgetName: jest.fn(() => 'Budget'),
Expand Down
12 changes: 12 additions & 0 deletions src/amazon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,18 @@ describe('amazon', () => {
expect(result[0]).toHaveProperty('cleared', 'uncleared');
});

it('should respect payee configuration', async () => {
const config = getConfig();
jest.spyOn(config, 'payee', 'get').mockReturnValueOnce('Test Payee');

const result: Array<AmazonTransaction> = [];
for await (const transaction of getAmazonTransactions()) {
result.push(transaction);
}

expect(result[0]).toHaveProperty('payee_name', 'Test Payee');
});

it('should use different import_ids for identical items', async () => {
const result: Array<AmazonTransaction> = [];
for await (const transaction of getAmazonTransactions()) {
Expand Down
2 changes: 1 addition & 1 deletion src/amazon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const createTransation = (
: title
? `${(quantity ?? 0) > 1 ? `${quantity} x ` : ''}${title}`.substr(0, 200)
: '',
payee_name: seller ?? 'Amazon.com',
payee_name: config.payee ?? seller ?? 'Amazon.com',
});

export const getAmazonTransactions = async function* (): AsyncGenerator<AmazonTransaction> {
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface Config {
cleared: boolean;
debugMode: boolean;
logLevel: string;
payee: string;
startDate: string;
ynabBudgetName: string;
ynabAccountName: string;
Expand Down Expand Up @@ -89,6 +90,10 @@ export const getConfig = (): Config => {
describe: 'Level of logs to output',
type: 'string',
})
.option('payee', {
describe: 'Override the "Payee" field in YNAB with this value',
type: 'string',
})
.options('start-date', {
describe: 'Sync transactions that occur after this date',
default: (() => {
Expand Down

0 comments on commit 86da1a6

Please sign in to comment.