diff --git a/src/AccountingAPIClient.ts b/src/AccountingAPIClient.ts index f56e8e812..b18ecaf0f 100644 --- a/src/AccountingAPIClient.ts +++ b/src/AccountingAPIClient.ts @@ -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'; @@ -526,6 +526,17 @@ export class AccountingAPIClient extends BaseAPIClient { endpoint += '/history'; return this.oauth1Client.get(endpoint); + }, + create: async (args: { InvoiceID: string, HistoryNote: HistoryRecord }): Promise => { + let endpoint = 'invoices'; + if (args && args.InvoiceID) { + endpoint = endpoint + '/' + args.InvoiceID; + delete args.InvoiceID; + } + + endpoint += '/history'; + + return this.oauth1Client.put(endpoint, args.HistoryNote); } }, email: { diff --git a/src/__tests__/AccountingAPI-history.tests.ts b/src/__tests__/AccountingAPI-history.tests.ts index 030f3e92c..2b78bd8cd 100644 --- a/src/__tests__/AccountingAPI-history.tests.ts +++ b/src/__tests__/AccountingAPI-history.tests.ts @@ -48,6 +48,8 @@ describe('AccountingAPI endpoints', () => { describe(`${endpoint} and getting History`, () => { let result: any; + const args: any = {}; + args[idValue] = guid1; const mockedResponse = JSON.stringify({ a: 'response' }); @@ -55,9 +57,6 @@ describe('AccountingAPI endpoints', () => { 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); }); @@ -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); + }); + } }); }); - });