예제 #1
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")
	}

}
예제 #2
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")
	}

}