Beispiel #1
0
func TestCustomerList(t *testing.T) {

	key := "test api key"

	var mockCustomersResponse invdendpoint.Customers
	mockCustomerResponseID := int64(1523)
	mockCustomerResponse := new(invdendpoint.Customer)
	mockCustomerResponse.Id = mockCustomerResponseID
	mockCustomerResponse.Name = "Mock Customer"
	mockCustomerResponse.Address1 = "23 Wayne street"
	mockCustomerResponse.City = "Austin"
	mockCustomerResponse.Country = "USA"
	mockCustomerResponse.CreatedAt = time.Now().UnixNano()
	mockCustomerResponse.Number = "CUST-21312"

	mockCustomersResponse = append(mockCustomersResponse, *mockCustomerResponse)

	server, err := invdmockserver.New(200, mockCustomersResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	customer := conn.NewCustomer()

	retrievedCustomer, err := customer.ListCustomerByNumber("CUST-21312")

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

	if !reflect.DeepEqual(retrievedCustomer.Customer, mockCustomerResponse) {
		t.Fatal("Retrieved Customer does not match the mock customer retrievedCustomer => ", retrievedCustomer.Customer, ", mockCustomer => ", mockCustomerResponse)
	}

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

	mockCustomerResponseID := int64(1523)
	mockCreatedTime := time.Now().UnixNano()
	mockName := "MOCK CUSTOMER"
	mockCustomerResponse := new(invdendpoint.Customer)
	mockCustomerResponse.Id = mockCustomerResponseID
	mockCustomerResponse.Name = mockName
	mockCustomerResponse.CreatedAt = mockCreatedTime

	server, err := invdmockserver.New(200, mockCustomerResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	customerToUpdate := conn.NewCustomer()

	customerToUpdate.Id = mockCustomerResponseID
	customerToUpdate.Name = "MOCK CUSTOMER"
	addressToUpdate := "7500 Rialto BLVD"
	customerToUpdate.Address1 = addressToUpdate
	mockCustomerResponse.Address1 = addressToUpdate

	apiErr := customerToUpdate.Save()

	if apiErr != nil {
		t.Fatal("Error Updating Customer", apiErr)
	}

	if !reflect.DeepEqual(mockCustomerResponse, customerToUpdate.Customer) {
		t.Fatal("Updated Customers Do Not Match Up")
	}

}