Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support to create a History note on an invoice #277

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/AccountingAPIClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import * as fs from 'fs';
import { Allocation, BankTransaction, BankTransfer, Contact, ContactGroup, CreditNote, Currency, Employee, ExpenseClaim, Invoice, Item, LinkedTransaction, ManualJournal, Payment, PurchaseOrder, Receipt, TaxRate, TrackingCategory, TrackingOption } from './AccountingAPI-models';
import { Allocation, BankTransaction, BankTransfer, Contact, ContactGroup, CreditNote, Currency, Employee, ExpenseClaim, Invoice, Item, LinkedTransaction, ManualJournal, Payment, PurchaseOrder, Receipt, TaxRate, TrackingCategory, TrackingOption, HistoryRecord } from './AccountingAPI-models';
import { AccountsResponse, AllocationsResponse, AttachmentsResponse, BankTransactionsResponse, BankTransfersResponse, BrandingThemesResponse, ContactGroupsResponse, ContactsResponse, CreditNotesResponse, CurrenciesResponse, EmployeesResponse, ExpenseClaimsResponse, HistoryResponse, InvoiceRemindersResponse, InvoicesResponse, ItemsResponse, JournalsResponse, LinkedTransactionsResponse, ManualJournalsResponse, OnlineInvoicesResponse, OrganisationResponse, OverpaymentsResponse, PaymentsResponse, PrepaymentsResponse, PurchaseOrdersResponse, ReceiptsResponse, RepeatingInvoicesResponse, ReportsResponse, TaxRatesResponse, TrackingCategoriesResponse, UsersResponse } from './AccountingAPI-responses';
import { BaseAPIClient, XeroClientConfiguration } from './internals/BaseAPIClient';
import { AccessToken, IOAuth1HttpClient } from './internals/OAuth1HttpClient';
Expand Down Expand Up @@ -526,6 +526,17 @@ export class AccountingAPIClient extends BaseAPIClient {
endpoint += '/history';

return this.oauth1Client.get<HistoryResponse>(endpoint);
},
create: async (args: { InvoiceID: string, HistoryNote: HistoryRecord }): Promise<HistoryResponse> => {
let endpoint = 'invoices';
if (args && args.InvoiceID) {
endpoint = endpoint + '/' + args.InvoiceID;
delete args.InvoiceID;
}

endpoint += '/history';

return this.oauth1Client.put<HistoryResponse>(endpoint, args.HistoryNote);
}
},
email: {
Expand Down
12 changes: 8 additions & 4 deletions src/__tests__/AccountingAPI-history.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,15 @@ describe('AccountingAPI endpoints', () => {

describe(`${endpoint} and getting History`, () => {
let result: any;
const args: any = {};
args[idValue] = guid1;

const mockedResponse = JSON.stringify({ a: 'response' });

beforeAll(async () => {
inMemoryOAuthLibFF.inMemoryOAuthLib.reset();
inMemoryOAuthLibFF.inMemoryOAuthLib.setResponse(false, mockedResponse, { statusCode: 200 });

const args: any = {};
args[idValue] = guid1;

result = await (xeroClient as any)[endpoint]['history'].get(args);
});

Expand All @@ -68,7 +67,12 @@ describe('AccountingAPI endpoints', () => {
it('matches the expected response', () => {
expect(result).toMatchObject(JSON.parse(mockedResponse));
});

if (endpoint === 'invoices') {
it('matches the expected response for creating a History Note', async () => {
result = await (xeroClient as any)[endpoint]['history'].create(args);
});
}
});
});

});