func TestInvoiceList(t *testing.T) { key := "test api key" var mockInvoicesResponse invdendpoint.Invoices mockInvoiceResponseID := int64(1523) mockInvoiceNumber := "INV-3421" mockInvoiceResponse := new(invdendpoint.Invoice) mockInvoiceResponse.Id = mockInvoiceResponseID mockInvoiceResponse.Number = mockInvoiceNumber mockInvoiceResponse.PaymentTerms = "NET15" mockInvoiceResponse.CreatedAt = time.Now().UnixNano() mockInvoicesResponse = append(mockInvoicesResponse, *mockInvoiceResponse) server, err := invdmockserver.New(200, mockInvoicesResponse, "json", true) if err != nil { t.Fatal(err) } defer server.Close() conn := mockConnection(key, server) invoice := conn.NewInvoice() invoiceResp, err := invoice.ListInvoiceByNumber(mockInvoiceNumber) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(invoiceResp.Invoice, mockInvoiceResponse) { t.Fatal("Error Messages Do Not Match Up") } }
func TestInvoiceUpdate(t *testing.T) { key := "test api key" mockInvoiceResponseID := int64(1523) mockUpdatedTime := time.Now().UnixNano() mockInvoiceResponse := new(invdendpoint.Invoice) mockInvoiceResponse.Id = mockInvoiceResponseID mockInvoiceResponse.CreatedAt = mockUpdatedTime mockInvoiceResponse.Name = "MOCK invoice" mockInvoiceResponse.Balance = 42.22 server, err := invdmockserver.New(200, mockInvoiceResponse, "json", true) if err != nil { t.Fatal(err) } defer server.Close() conn := mockConnection(key, server) invoiceToUpdate := conn.NewInvoice() invoiceToUpdate.Balance = 42.22 err = invoiceToUpdate.Save() if err != nil { t.Fatal("Error Updating Invoice", err) } if !reflect.DeepEqual(mockInvoiceResponse, invoiceToUpdate.Invoice) { t.Fatal("Error Messages Do Not Match Up") } }