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

feat(tests): [nan-1763] add xero tests and adjust vitest #16

Merged
Merged
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
40 changes: 26 additions & 14 deletions flows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4716,6 +4716,7 @@ integrations:
output: Contact
sync_type: incremental
endpoint: GET /xero/contacts
version: 1.0.0
accounts:
description: >
Fetches all accounts in Xero (chart of accounts). Incremental sync,
Expand All @@ -4725,6 +4726,7 @@ integrations:
output: Account
sync_type: incremental
endpoint: GET /xero/accounts
version: 1.0.0
items:
description: >
Fetches all items in Xero. Incremental sync, does not detect deletes,
Expand All @@ -4736,6 +4738,7 @@ integrations:
output: Item
sync_type: incremental
endpoint: GET /xero/items
version: 1.0.0
invoices:
description: |
Fetches all invoices in Xero. Incremental sync.
Expand All @@ -4744,6 +4747,7 @@ integrations:
output: Invoice
sync_type: incremental
endpoint: GET /xero/invoices
version: 1.0.0
payments:
description: |
Fetches all payments in Xero. Incremental sync.
Expand All @@ -4752,6 +4756,7 @@ integrations:
output: Payment
sync_type: incremental
endpoint: GET /xero/payments
version: 1.0.0
actions:
create-contact:
description: |
Expand All @@ -4761,6 +4766,7 @@ integrations:
scopes: accounting.contacts
output: ContactActionResponse
endpoint: POST /xero/contacts
version: 1.0.0
update-contact:
description: >
Updates one or multiple contacts in Xero. Only fields that are passed
Expand All @@ -4770,6 +4776,7 @@ integrations:
scopes: accounting.contacts
output: ContactActionResponse
endpoint: PUT /xero/contacts
version: 1.0.0
create-invoice:
description: |
Creates one or more invoices in Xero.
Expand All @@ -4778,7 +4785,7 @@ integrations:
scopes: accounting.transactions
output: InvoiceActionResponse
endpoint: POST /xero/invoices
version: 1.0.0
version: 1.0.1
update-invoice:
description: |
Updates one or more invoices in Xero. To delete an invoice
Expand All @@ -4789,7 +4796,7 @@ integrations:
scopes: accounting.transactions
output: InvoiceActionResponse
endpoint: PUT /xero/invoices
version: 1.0.0
version: 1.0.1
create-credit-note:
description: |
Creates one or more credit notes in Xero.
Expand All @@ -4798,13 +4805,15 @@ integrations:
scopes: accounting.transactions
output: CreditNoteActionResponse
endpoint: POST /xero/creditnotes
version: 1.0.0
update-credit-note:
description: |
Updates one or more credit notes in Xero.
input: CreditNote[]
scopes: accounting.transactions
output: CreditNoteActionResponse
endpoint: PUT /xero/creditnotes
version: 1.0.0
create-payment:
description: |
Creates one or more payments in Xero.
Expand All @@ -4813,6 +4822,7 @@ integrations:
input: CreatePayment[]
output: PaymentActionResponse
endpoint: POST /xero/payments
version: 1.0.0
create-item:
description: |
Creates one or more items in Xero.
Expand All @@ -4821,13 +4831,15 @@ integrations:
input: Item[]
output: ItemActionResponse
endpoint: POST /xero/items
version: 1.0.0
update-item:
description: |
Updates one or more items in Xero.
scopes: accounting.settings
input: Item[]
output: ItemActionResponse
endpoint: PUT /xero/items
version: 1.0.0
models:
ActionErrorResponse:
message: string
Expand All @@ -4848,9 +4860,9 @@ integrations:
Contact:
name: string
id: string
external_id?: string
external_id: string | null
email: string | null
tax_number?: string | null
tax_number: string | null
address_line_1?: string | null
address_line_2?: string | null
city: string | null
Expand All @@ -4862,9 +4874,9 @@ integrations:
FailedContact:
name: string
id: string
external_id?: string
external_id: string | null
email: string | null
tax_number?: string | null
tax_number: string | null
address_line_1?: string | null
address_line_2?: string | null
city: string | null
Expand Down Expand Up @@ -5050,12 +5062,12 @@ integrations:
external_contact_id: string
status: string
number: string
is_taxable: boolean
tax_rate_id: string
tax_rate: number
is_taxable?: boolean
tax_rate_id?: string
tax_rate?: number
currency: string
reference: string
issuing_date: date
issuing_date: date | null
fees: CreditNoteFee[]
CreditNoteFee:
item_id: string
Expand All @@ -5073,12 +5085,12 @@ integrations:
external_contact_id: string
status: string
number: string
is_taxable: boolean
tax_rate_id: string
tax_rate: number
is_taxable?: boolean
tax_rate_id?: string
tax_rate?: number
currency: string
reference: string
issuing_date: date
issuing_date: date | null
fees: CreditNoteFee[]
validation_errors: any[]
CreditNoteActionResponse:
Expand Down
6 changes: 3 additions & 3 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {};

declare global {
var vitest: {
NangoSyncMock: new (config: { name: string; Model: string }) => any;
};
var vitest: {
NangoSyncMock: new (config: { name: string; Model: string }) => any;
};
}
27 changes: 27 additions & 0 deletions integrations/xero/fixtures/credit-note.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"id": "12345",
"type": "ACCPAYCREDIT",
"external_contact_id": "e1f8418e-a946-4013-80f6-ef52bb88f920",
"status": "DRAFT",
"number": "CN001",
"is_taxable": true,
"tax_rate_id": "TR001",
"tax_rate": 0.15,
"reference": "Invoice123",
"issuing_date": "2024-07-31",
"fees": [
{
"item_id": "ea10a915-3787-4c37-9ff7-ab33cc6b35f3",
"item_code": "item-1",
"description": "Consulting services",
"units": 10,
"precise_unit_amount": 100.0,
"account_code": "4000",
"account_external_id": "acc_123",
"amount_cents": 100000,
"taxes_amount_cents": 15000
}
]
}
]
5 changes: 5 additions & 0 deletions integrations/xero/fixtures/item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"item_code": "item-2"
}
]
22 changes: 12 additions & 10 deletions integrations/xero/mappers/to-contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ export function toContact(xeroContact: XeroContact): Contact {
: `${defaultPhone.PhoneAreaCode}${defaultPhone.PhoneNumber}`;
}

return {
const contact: Contact = {
id: xeroContact.ContactID,
name: xeroContact.Name,
external_id: xeroContact.ContactNumber,
tax_number: xeroContact.TaxNumber,
external_id: xeroContact.ContactNumber || null,
tax_number: xeroContact.TaxNumber || null,
email: xeroContact.EmailAddress,
address_line_1: streetAddress?.AddressLine1,
address_line_2: streetAddress?.AddressLine2,
city: streetAddress?.City,
zip: streetAddress?.PostalCode,
country: streetAddress?.Country,
state: streetAddress?.Region,
address_line_1: streetAddress?.AddressLine1 || null,
address_line_2: streetAddress?.AddressLine2 || null,
city: streetAddress?.City || null,
zip: streetAddress?.PostalCode || null,
country: streetAddress?.Country || null,
state: streetAddress?.Region || null,
phone: formattedPhoneNumber
} as Contact;
};

return contact;
}

export function toXeroContact(contact: Contact | CreateContact): XeroContact {
Expand Down
26 changes: 17 additions & 9 deletions integrations/xero/mappers/to-credit-note.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { FailedCreditNote, CreditNote, CreditNoteFee } from '../../models';
import type { CreditNote as XeroCreditNote } from '../types';
import { parseDate } from '../utils.js';

export function toCreditNote(xeroCreditNote: any): CreditNote {
return {
export function toCreditNote(xeroCreditNote: XeroCreditNote): CreditNote {
const creditNote: CreditNote = {
id: xeroCreditNote.CreditNoteID,
type: xeroCreditNote.Type,
external_contact_id: xeroCreditNote.Contact.ContactID,
Expand All @@ -12,11 +13,13 @@ export function toCreditNote(xeroCreditNote: any): CreditNote {
reference: xeroCreditNote.Reference,
issuing_date: xeroCreditNote.Date ? parseDate(xeroCreditNote.Date) : null,
fees: xeroCreditNote.LineItems.map(toCreditNoteItem)
} as CreditNote;
};

return creditNote;
}

function toCreditNoteItem(xeroCreditNoteItem: any): CreditNoteFee {
return {
const creditNoteItem: CreditNoteFee = {
item_id: xeroCreditNoteItem.LineItemID,
item_code: xeroCreditNoteItem.ItemCode,
description: xeroCreditNoteItem.Description,
Expand All @@ -26,11 +29,16 @@ function toCreditNoteItem(xeroCreditNoteItem: any): CreditNoteFee {
account_external_id: xeroCreditNoteItem.AccountId,
amount_cents: parseFloat(xeroCreditNoteItem.LineAmount) * 100, // Amounts in xero are not in cents
taxes_amount_cents: parseFloat(xeroCreditNoteItem.TaxAmount) * 100 // Amounts in xero are not in cents
} as CreditNoteFee;
};

return creditNoteItem;
}

export function toFailedCreditNote(xeroCreditNote: any): FailedCreditNote {
const failedCreditNote = toCreditNote(xeroCreditNote) as FailedCreditNote;
failedCreditNote.validation_errors = xeroCreditNote.ValidationErrors;
return failedCreditNote;
export function toFailedCreditNote(xeroCreditNote: XeroCreditNote): FailedCreditNote {
const failedCreditNote = toCreditNote(xeroCreditNote);
const failedCreditNoteWithValidationErrors: FailedCreditNote = {
...failedCreditNote,
validation_errors: xeroCreditNote?.ValidationErrors || []
};
return failedCreditNoteWithValidationErrors;
}
24 changes: 14 additions & 10 deletions integrations/xero/mappers/to-item.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { FailedItem, Item } from '../../models';
import type { Item as XeroItem } from '../types';

export function toItem(xeroItem: any): Item {
return {
export function toItem(xeroItem: XeroItem): Item {
const item: Item = {
id: xeroItem.ItemID,
item_code: xeroItem.Code,
name: xeroItem.Name,
description: xeroItem.Description,
account_code: xeroItem.SalesDetails ? xeroItem.SalesDetails.AccountCode : null
} as Item;
name: xeroItem.Name || xeroItem.Code,
description: xeroItem.Description || null,
account_code: xeroItem.SalesDetails ? xeroItem.SalesDetails['AccountCode'] : null
};

return item;
}

export function toXeroItem(item: Item) {
Expand Down Expand Up @@ -36,8 +39,9 @@ export function toXeroItem(item: Item) {
return xeroItem;
}

export function toFailedItem(xeroItem: any): FailedItem {
const failedItem = toItem(xeroItem) as FailedItem;
failedItem.validation_errors = xeroItem.ValidationErrors;
return failedItem;
export function toFailedItem(xeroItem: XeroItem): FailedItem {
return {
...toItem(xeroItem),
validation_errors: xeroItem?.ValidationErrors || []
};
}
1 change: 1 addition & 0 deletions integrations/xero/mocks/accounts/batchDelete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Loading