Example #1
0
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")
	}

}
Example #2
0
func TestInvoiceCreate(t *testing.T) {
	key := "test api key"

	mockInvoiceResponseID := int64(1523)
	mockInvoiceResponse := new(invdendpoint.Invoice)
	mockInvoiceResponse.Id = mockInvoiceResponseID

	nowUnix := time.Now().UnixNano()

	s := strconv.FormatInt(nowUnix, 10)

	server, err := invdmockserver.New(200, mockInvoiceResponse, "json", true)
	if err != nil {
		t.Fatal(err)
	}
	defer server.Close()

	conn := mockConnection(key, server)

	invoice := conn.NewInvoice()

	invoiceToCreate := invoice.NewInvoice()

	invoiceToCreate.Name = "Test invoice Original " + s
	mockInvoiceResponse.Name = invoiceToCreate.Name

	createdInvoice, err := invoice.Create(invoiceToCreate)

	if err != nil {
		t.Fatal("Error Creating invoice", err)
	}

	if !reflect.DeepEqual(createdInvoice.Invoice, mockInvoiceResponse) {
		t.Fatal("Invoice Not Created Succesfully")
	}

}
Example #3
0
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")
	}

}