Skip to content

Commit 3afaf4b

Browse files
committed
Update tests for HistoryRecord component change
The OpenAPI spec we've moved HistoryRecord responses into components - this helps make the spec more DRY but means GetSandbox doesn't have an example response to return on all 13 "get" or "create" history endpoints. The solution is to mock only the BatchPayment history get and create with an example response for use in the unit tests. This validate ALL history calls since they all use the same part of the spec. Remove Required attributes on objects that are used for create/update and as nested children. This makes the objects are more flexibile for different use cases. Objects changed. - Items - LinkedTransaction - PurchaseOrder
1 parent 2d9432a commit 3afaf4b

19 files changed

Lines changed: 41 additions & 330 deletions

src/main/java/com/xero/api/client/AccountingApi.java

Lines changed: 28 additions & 28 deletions
Large diffs are not rendered by default.

src/main/java/com/xero/models/accounting/Accounts.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public Accounts addAccountsItem(Account accountsItem) {
5353
* Get accounts
5454
* @return accounts
5555
**/
56-
@ApiModelProperty(example = "{ \"Accounts\": [ { \"AccountID\": \"66b262e2-561e-423e-8937-47d558f13442\", \"Code\": \"123456\", \"Name\": \"Foobar\", \"Status\": \"ACTIVE\", \"Type\": \"EXPENSE\", \"TaxType\": \"INPUT\", \"Description\": \"Hello World\", \"Class\": \"EXPENSE\", \"EnablePaymentsToAccount\": false, \"ShowInExpenseClaims\": false, \"ReportingCode\": \"EXP\", \"ReportingCodeName\": \"Expense\", \"UpdatedDateUTC\": \"/Date(1550793549320+0000)/\" } ] }", value = "")
56+
@ApiModelProperty(value = "")
5757
public List<Account> getAccounts() {
5858
return accounts;
5959
}

src/main/java/com/xero/models/accounting/Item.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public Item inventoryAssetAccountCode(String inventoryAssetAccountCode) {
126126
* The inventory asset account for the item. The account must be of type INVENTORY. The COGSAccountCode in PurchaseDetails is also required to create a tracked item
127127
* @return inventoryAssetAccountCode
128128
**/
129-
@ApiModelProperty(required = true, value = "The inventory asset account for the item. The account must be of type INVENTORY. The COGSAccountCode in PurchaseDetails is also required to create a tracked item")
129+
@ApiModelProperty(value = "The inventory asset account for the item. The account must be of type INVENTORY. The COGSAccountCode in PurchaseDetails is also required to create a tracked item")
130130
public String getInventoryAssetAccountCode() {
131131
return inventoryAssetAccountCode;
132132
}

src/main/java/com/xero/models/accounting/LinkedTransaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public LinkedTransaction sourceLineItemID(UUID sourceLineItemID) {
214214
* The line item identifier from the source transaction.
215215
* @return sourceLineItemID
216216
**/
217-
@ApiModelProperty(required = true, value = "The line item identifier from the source transaction.")
217+
@ApiModelProperty(value = "The line item identifier from the source transaction.")
218218
public UUID getSourceLineItemID() {
219219
return sourceLineItemID;
220220
}

src/main/java/com/xero/models/accounting/PurchaseOrder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public PurchaseOrder contact(Contact contact) {
202202
* Get contact
203203
* @return contact
204204
**/
205-
@ApiModelProperty(required = true, value = "")
205+
@ApiModelProperty(value = "")
206206
public Contact getContact() {
207207
return contact;
208208
}
@@ -217,6 +217,9 @@ public PurchaseOrder lineItems(List<LineItem> lineItems) {
217217
}
218218

219219
public PurchaseOrder addLineItemsItem(LineItem lineItemsItem) {
220+
if (this.lineItems == null) {
221+
this.lineItems = new ArrayList<LineItem>();
222+
}
220223
this.lineItems.add(lineItemsItem);
221224
return this;
222225
}
@@ -225,7 +228,7 @@ public PurchaseOrder addLineItemsItem(LineItem lineItemsItem) {
225228
* See LineItems
226229
* @return lineItems
227230
**/
228-
@ApiModelProperty(required = true, value = "See LineItems")
231+
@ApiModelProperty(value = "See LineItems")
229232
public List<LineItem> getLineItems() {
230233
return lineItems;
231234
}

src/main/java/com/xero/models/accounting/Quote.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ public Quote addLineItemsItem(LineItem lineItemsItem) {
228228
}
229229

230230
/**
231-
* The LineItems collection can contain any number of individual LineItem sub-elements. At minimum, a description is required to create a complete quote.
231+
* See LineItems
232232
* @return lineItems
233233
**/
234-
@ApiModelProperty(required = true, value = "The LineItems collection can contain any number of individual LineItem sub-elements. At minimum, a description is required to create a complete quote.")
234+
@ApiModelProperty(required = true, value = "See LineItems")
235235
public List<LineItem> getLineItems() {
236236
return lineItems;
237237
}

src/test/java/com/xero/api/client/AccountingApiBankTransactionTest.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -198,29 +198,5 @@ public void updateBankTransactionAttachmentByFileNameTest() throws IOException {
198198
199199
}
200200
*/
201-
@Test
202-
public void testGetBankTransactionsHistory() throws Exception {
203-
System.out.println("@Test - getBankTransactionsHistory");
204-
UUID bankTransactionID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
205-
HistoryRecords hr = accountingApi.getBankTransactionsHistory(accessToken,xeroTenantId,bankTransactionID);
206-
assertThat(hr.getHistoryRecords().get(0).getUser(), is(equalTo("System Generated")));
207-
assertThat(hr.getHistoryRecords().get(0).getChanges(), is(equalTo("Attached a file")));
208-
//System.out.println(hr.getHistoryRecords().toString());
209-
}
210-
211-
@Test
212-
public void testCreateBankTransactionHistoryRecord() throws Exception {
213-
System.out.println("@Test - createBankTransactionHistoryRecord - not implemented");
214-
215-
/*
216-
HistoryRecords newHistoryRecords = new HistoryRecords();
217-
HistoryRecord newHistoryRecord = new HistoryRecord();
218-
newHistoryRecord.setDetails("Hello World");
219-
newHistoryRecords.addHistoryRecordsItem(newHistoryRecord);
220-
HistoryRecords newHistory = accountingApi.createBankTransactionHistoryRecord(bankTransactionID,newHistoryRecords);
221-
//assertThat(newHistory.getHistoryRecords().get(0).getDetails(), is(equalTo("Hello World")));
222-
System.out.println(newHistory.getHistoryRecords().toString());
223-
*/
224-
}
225201

226202
}

src/test/java/com/xero/api/client/AccountingApiBankTransferTest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,6 @@ public void createBankTransferTest() throws IOException {
133133
assertThat(response.getBankTransfers().get(0).getFromBankAccount().getAccountID(), is(equalTo(UUID.fromString("7e5e243b-9fcd-4aef-8e3a-c70be1e39bfa"))));
134134
//System.out.println(response.getBankTransfers().get(0).toString());
135135
}
136-
@Test
137-
public void getBankTransferHistoryTest() throws IOException {
138-
System.out.println("@Test - getBankTransferHistoryTest");
139-
140-
UUID bankTransferID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
141-
HistoryRecords response = accountingApi.getBankTransferHistory(accessToken,xeroTenantId,bankTransferID);
142-
assertThat(response.getHistoryRecords().get(0).getUser(), is(equalTo("System Generated")));
143-
assertThat(response.getHistoryRecords().get(0).getChanges(), is(equalTo("Attached a file")));
144-
assertThat(response.getHistoryRecords().get(0).getDetails(), is(equalTo("Attached the file sample2.jpg through the Xero API using Xero API Partner")));
145-
//System.out.println(response.getHistoryRecords().get(0).toString());
146-
}
147-
148-
@Test
149-
public void createBankTransferHistoryRecordTest() throws IOException {
150-
System.out.println("@Test - createBankTransferHistoryRecordTest - not implemented at this time");
151-
152-
//HistoryRecords historyRecords = null;
153-
//HistoryRecords response = accountingApi.createBankTransferHistoryRecord(bankTransferID, historyRecords);
154-
// TODO: test validations
155-
}
156136

157137
@Test
158138
public void createBankTransferAttachmentByFileNameTest() throws IOException {

src/test/java/com/xero/api/client/AccountingApiContactsTest.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -223,31 +223,6 @@ public void updateContactTest() throws IOException {
223223
//System.out.println(response.getContacts().get(0).toString());
224224
}
225225

226-
@Test
227-
public void getContactHistoryTest() throws IOException {
228-
System.out.println("@Test - getContactHistoryTest");
229-
230-
UUID contactID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
231-
HistoryRecords response = accountingApi.getContactHistory(accessToken,xeroTenantId,contactID);
232-
assertThat(response.getHistoryRecords().get(0).getUser(), is(equalTo("System Generated")));
233-
assertThat(response.getHistoryRecords().get(0).getChanges(), is(equalTo("Edited")));
234-
assertThat(response.getHistoryRecords().get(0).getDetails(), is(equalTo("Name changed from Foo9987 to Bar8156.")));
235-
assertThat(response.getHistoryRecords().get(0).getDateUTC(), is(equalTo(OffsetDateTime.parse("2019-02-28T16:15:22.350-08:00"))));
236-
//System.out.println(response.getHistoryRecords().get(0).toString());
237-
}
238-
239-
@Test
240-
public void createContactHistoryTest() throws IOException {
241-
System.out.println("@Test - createContactHistoryTest - not implemented at this time");
242-
243-
UUID contactID = UUID.fromString("297c2dc5-cc47-4afd-8ec8-74990b8761e9");
244-
HistoryRecords historyRecords = new HistoryRecords();
245-
HistoryRecords response = accountingApi.createContactHistory(accessToken,xeroTenantId,contactID, historyRecords);
246-
assertThat(response.getHistoryRecords().get(0).getDetails(), is(equalTo("Hello World")));
247-
assertThat(response.getHistoryRecords().get(0).getDateUTC(), is(equalTo(OffsetDateTime.parse("2019-02-28T16:15:24.272-08:00"))));
248-
//System.out.println(response.getHistoryRecords().get(0).toString());
249-
}
250-
251226
@Test
252227
public void createContactAttachmentByFileNameTest() throws IOException {
253228
System.out.println("@Test - createContactAttachmentByFileNameTest");

src/test/java/com/xero/api/client/AccountingApiCreditNotesTest.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public void createCreditNoteAllocationTest() throws IOException {
131131
//System.out.println(response.getAllocations().get(0).toString());
132132
}
133133

134+
/*
134135
@Test
135136
public void createCreditNoteAttachmentByFileNameTest() throws IOException {
136137
System.out.println("@Test - createCreditNoteAttachmentByFileName");
@@ -146,20 +147,7 @@ public void createCreditNoteAttachmentByFileNameTest() throws IOException {
146147
assertThat(response.getAttachments().get(0).getIncludeOnline(), is(equalTo(null)));
147148
//System.out.println(response.getAttachments().get(0).toString());
148149
}
149-
150-
151-
@Test
152-
public void createCreditNoteHistoryTest() throws IOException {
153-
System.out.println("@Test - createCreditNoteHistory");
154-
UUID creditNoteID = UUID.fromString("8138a266-fb42-49b2-a104-014b7045753d");
155-
HistoryRecords historyRecords = new HistoryRecords();
156-
HistoryRecords response = accountingApi.createCreditNoteHistory(accessToken,xeroTenantId,creditNoteID, historyRecords);
157-
158-
assertThat(response.getHistoryRecords().get(0).getDetails(), is(equalTo("Hello World")));
159-
assertThat(response.getHistoryRecords().get(0).getDateUTC(), is(equalTo(OffsetDateTime.parse("2019-03-05T15:29:04.585-08:00"))));
160-
//System.out.println(response.getHistoryRecords().get(0).toString());
161-
}
162-
150+
*/
163151
@Test
164152
public void getCreditNoteTest() throws IOException {
165153
System.out.println("@Test - getCreditNote");
@@ -210,20 +198,6 @@ public void getCreditNoteAttachmentsTest() throws IOException {
210198
assertThat(response.getAttachments().get(0).getIncludeOnline(), is(equalTo(null)));
211199
//System.out.println(response.getAttachments().get(0).toString());
212200
}
213-
214-
@Test
215-
public void getCreditNoteHistoryTest() throws IOException {
216-
System.out.println("@Test - getCreditNoteHistory");
217-
UUID creditNoteID = UUID.fromString("8138a266-fb42-49b2-a104-014b7045753d");
218-
HistoryRecords response = accountingApi.getCreditNoteHistory(accessToken,xeroTenantId,creditNoteID);
219-
220-
assertThat(response.getHistoryRecords().get(0).getUser(), is(equalTo("Sidney Maestre")));
221-
assertThat(response.getHistoryRecords().get(0).getChanges(), is(equalTo("Cash Refunded")));
222-
assertThat(response.getHistoryRecords().get(0).getDetails(), is(equalTo("Payment made to Liam Gallagher on 14 March 2019 for 2.00. There is 32.50 credit remaining on this credit note.")));
223-
assertThat(response.getHistoryRecords().get(0).getDateUTC(), is(equalTo(OffsetDateTime.parse("2019-03-05T10:59:06.157-08:00"))));
224-
//System.out.println(response.getHistoryRecords().get(0).toString());
225-
}
226-
227201

228202
@Test
229203
public void getCreditNotesTest() throws IOException {

0 commit comments

Comments
 (0)