Ejemplo n.º 1
0
func TestTransactionRetrieve(t *testing.T) {

	key := "test api key"

	mockTransactionResponseID := int64(1523)
	mockTransactionResponse := new(invdendpoint.Transaction)
	mockTransactionResponse.Id = mockTransactionResponseID
	mockTransactionResponse.Customer = 234112
	mockTransactionResponse.GatewayId = "234"

	mockTransactionResponse.CreatedAt = time.Now().UnixNano()

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

	conn := mockConnection(key, server)
	transaction := conn.NewTransaction()

	retrievedTransaction, err := transaction.Retrieve(mockTransactionResponseID)

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

	if !reflect.DeepEqual(retrievedTransaction.Transaction, mockTransactionResponse) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
Ejemplo n.º 2
0
func TestTransactionUpdate(t *testing.T) {
	key := "test api key"

	mockTransactionResponseID := int64(1523)
	mockTransactionResponse := new(invdendpoint.Transaction)
	mockTransactionResponse.Id = mockTransactionResponseID
	mockTransactionResponse.CreatedAt = time.Now().UnixNano()
	mockTransactionResponse.Customer = 234112
	mockTransactionResponse.GatewayId = "234"

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

	conn := mockConnection(key, server)

	transactionToUpdate := conn.NewTransaction()

	mockTransactionResponse.Amount = 42
	transactionToUpdate.Amount = 42

	err = transactionToUpdate.Save()

	if err != nil {
		t.Fatal("Error Updating Transaction", err)
	}

	if !reflect.DeepEqual(mockTransactionResponse, transactionToUpdate.Transaction) {
		t.Fatal("Error Transaction Not Updated Properly")
	}

}
Ejemplo n.º 3
0
func TestTransactionCreate(t *testing.T) {
	key := "test api key"

	mockTransactionResponseID := int64(1523)
	mockTransactionResponse := new(invdendpoint.Transaction)
	mockTransactionResponse.Id = mockTransactionResponseID
	mockTransactionResponse.CreatedAt = time.Now().UnixNano()
	mockTransactionResponse.Customer = 234112
	mockTransactionResponse.GatewayId = "234"

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

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

	defer server.Close()

	conn := mockConnection(key, server)

	transaction := conn.NewTransaction()

	transactionToCreate := transaction.NewTransaction()

	transactionToCreate.Customer = 234112
	transactionToCreate.Gateway = "dell"

	createdTransaction, err := transaction.Create(transactionToCreate)

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

	if !reflect.DeepEqual(createdTransaction.Transaction, mockTransactionResponse) {
		t.Fatal("Transaction Was Not Created Succesfully", createdTransaction.Transaction, mockTransactionResponse)
	}

}