示例#1
0
func TestCustomerDeleteError(t *testing.T) {
	key := "api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "You do not have permission to do that"

	mockCustomerID := int64(-999)

	server, err := invdmockserver.New(403, mockErrorResponse, "json", false)

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

	defer server.Close()

	conn := mockConnection(key, server)

	customer := conn.NewCustomer()

	customer.Id = mockCustomerID

	err = customer.Delete()

	if err == nil {
		t.Fatal("Error Should Have Been Raised")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
示例#2
0
func TestCustomerDelete(t *testing.T) {

	key := "api key"

	mockCustomerResponse := ""
	mockCustomerID := int64(2341)

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

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

	defer server.Close()

	conn := mockConnection(key, server)

	customer := conn.NewCustomer()

	customer.Id = mockCustomerID

	err = customer.Delete()

	if err != nil {
		t.Fatal("Error occured deleting customer")
	}

}
func TestSubscriptionDeleteError(t *testing.T) {
	key := "api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "You do not have permission to do that"

	mockSubscriptionID := int64(-999)

	server, err := invdmockserver.New(403, mockErrorResponse, "json", true)

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

	defer server.Close()

	conn := mockConnection(key, server)

	subscription := conn.NewSubscription()

	subscription.Id = mockSubscriptionID

	err = subscription.Cancel()

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
示例#4
0
func TestInvoiceUpdateError(t *testing.T) {
	key := "wrong api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "We could not authenticate the supplied API Key."

	server, err := invdmockserver.New(401, mockErrorResponse, "json", true)

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

	defer server.Close()

	conn := mockConnection(key, server)

	invoiceToUpdate := conn.NewInvoice()

	invoiceToUpdate.Balance = 400.12

	err = invoiceToUpdate.Save()

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

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
示例#5
0
func TestInvoiceDeleteError(t *testing.T) {
	key := "api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "You Do Not Have Permission To Do That"

	server, err := invdmockserver.New(403, mockErrorResponse, "json", true)

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

	defer server.Close()

	conn := mockConnection(key, server)

	invoice := conn.NewInvoice()

	err = invoice.Delete()

	if err == nil {
		t.Fatal("Error Occured Deleting Invoice")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
示例#6
0
func TestTransactionDelete(t *testing.T) {

	key := "api key"

	mocktransactionResponse := ""
	mocktransactionID := int64(2341)

	server, err := invdmockserver.New(204, mocktransactionResponse, "json", true)

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

	defer server.Close()

	conn := mockConnection(key, server)

	transaction := conn.NewTransaction()

	transaction.Id = mocktransactionID

	err = transaction.Delete()

	if err != nil {
		t.Fatal("Error Occured Deleting Transaction")
	}

}
示例#7
0
func TestTransactionCreateError(t *testing.T) {
	key := "test api key"
	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "Name is invalid"
	mockErrorResponse.Param = "name"

	server, err := invdmockserver.New(400, mockErrorResponse, "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.GatewayId = "234"

	_, apiErr := transaction.Create(transactionToCreate)

	if apiErr == nil {
		t.Fatal("Api Should Have Errored Out")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), apiErr.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
示例#8
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")
	}

}
示例#9
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")
	}

}
示例#10
0
func TestTransactionRetrieveError(t *testing.T) {
	key := "api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "You do not have permission to do that"

	mockTransactionID := int64(-999)

	server, err := invdmockserver.New(403, mockErrorResponse, "json", true)

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

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

	_, err = transaction.Retrieve(mockTransactionID)

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
示例#11
0
func TestInvoiceListError(t *testing.T) {
	key := "api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "You do not have permission to do that"

	mockInvoiceNumber := "INV-32421"

	server, err := invdmockserver.New(403, mockErrorResponse, "json", true)

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

	defer server.Close()

	conn := mockConnection(key, server)

	invoice := conn.NewInvoice()

	_, err = invoice.ListInvoiceByNumber(mockInvoiceNumber)

	if err == nil {
		t.Fatal("Error occured deleting invoice")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
示例#12
0
func TestCustomerUpdateError(t *testing.T) {
	key := "wrong api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "We could not authenticate the supplied API Key."

	server, err := invdmockserver.New(401, mockErrorResponse, "json", true)

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

	defer server.Close()

	conn := mockConnection(key, server)

	customer := conn.NewCustomer()
	customer.Name = "Parag Patel"
	customer.Id = 3411111
	customer.City = "Austin"

	err = customer.Save()

	if err == nil {
		t.Fatal("Error Updating Customer => ", err)
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
示例#13
0
func TestInvoiceDelete(t *testing.T) {

	key := "api key"

	mockinvoiceResponse := ""
	mockinvoiceID := int64(2341)

	server, err := invdmockserver.New(204, mockinvoiceResponse, "json", true)

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

	defer server.Close()

	conn := mockConnection(key, server)

	invoice := conn.NewInvoice()

	invoice.Id = mockinvoiceID

	err = invoice.Delete()

	if err != nil {
		t.Fatal("Error Occured Deleting Invoice")
	}

}
示例#14
0
func TestSubscriptionUpdate(t *testing.T) {
	key := "test api key"

	mockSubscriptionResponseID := int64(1523)
	mockSubscriptionResponse := new(invdendpoint.Subscription)
	mockSubscriptionResponse.Id = mockSubscriptionResponseID
	mockSubscriptionResponse.CreatedAt = time.Now().UnixNano()
	mockSubscriptionResponse.Customer = 234112
	mockSubscriptionResponse.Plan = "234"

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

	conn := mockConnection(key, server)

	subscriptionToUpdate := conn.NewSubscription()

	mockSubscriptionResponse.Cycles = 42
	subscriptionToUpdate.Cycles = 42

	err = subscriptionToUpdate.Save()

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

	if !reflect.DeepEqual(mockSubscriptionResponse, subscriptionToUpdate.Subscription) {
		t.Fatal("Error Subscription Not Updated Properly")
	}

}
示例#15
0
func TestSubscriptionDelete(t *testing.T) {

	key := "api key"

	mocksubscriptionResponse := ""
	mocksubscriptionID := int64(2341)

	server, err := invdmockserver.New(204, mocksubscriptionResponse, "json", true)

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

	defer server.Close()

	conn := mockConnection(key, server)

	subscription := conn.NewSubscription()

	subscription.Id = mocksubscriptionID

	err = subscription.Cancel()

	if err != nil {
		t.Fatal("Error Occured Canceling Subscription")
	}

}
示例#16
0
func TestInvoiceCreateError(t *testing.T) {
	key := "test api key"
	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "Name is invalid"
	mockErrorResponse.Param = "name"

	server, err := invdmockserver.New(400, mockErrorResponse, "json", true)

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

	defer server.Close()

	conn := mockConnection(key, server)

	invoice := conn.NewInvoice()

	invoiceToCreate := invoice.NewInvoice()
	invoiceToCreate.Total = 342.234

	_, err = invoice.Create(invoiceToCreate)

	if err == nil {
		t.Fatal("Api Should Have Errored Out")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
示例#17
0
func TestCustomerCreateError(t *testing.T) {
	key := "test api key"
	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "Name is invalid"
	mockErrorResponse.Param = "name"

	server, err := invdmockserver.New(400, mockErrorResponse, "json", true)

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

	defer server.Close()

	conn := mockConnection(key, server)

	custConn := conn.NewCustomer()

	customerToCreate := custConn.NewCustomer()
	customerToCreate.Email = "*****@*****.**"

	_, apiErr := custConn.Create(customerToCreate)

	if apiErr == nil {
		t.Fatal("Api should have errored out")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), apiErr.Error()) {
		t.Fatal("Error messages do not match up", mockErrorResponse, ",", apiErr)
	}

}
示例#18
0
func TestCustomerCreate(t *testing.T) {

	//Set up the mock customer response
	mockCustomerResponseID := int64(1523)
	mockCustomerResponse := new(Customer)
	mockCustomerResponseData := new(invdendpoint.Customer)
	mockCustomerResponse.Customer = mockCustomerResponseData
	mockCustomerResponse.Id = mockCustomerResponseID

	//Launch our mock server
	server, err := invdmockserver.New(200, mockCustomerResponse, "json", true)

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

	defer server.Close()

	//Establish our mock connection
	key := "test api key"
	conn := mockConnection(key, server)

	customer := conn.NewCustomer()

	nowUnix := time.Now().UnixNano()
	s := strconv.FormatInt(nowUnix, 10)

	customerToCreate := customer.NewCustomer()
	customerToCreate.Name = "Test Customer Original " + s
	customerToCreate.Id = mockCustomerResponse.Id
	mockCustomerResponse.Name = customerToCreate.Name
	//mockCustomerResponse.Connection = conn

	//Make the call to create our customer
	createdCustomer, err := customer.Create(customerToCreate)

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

	//Customer that we wanted to create should equal the customer we created
	if !reflect.DeepEqual(createdCustomer, customerToCreate) {
		t.Fatal(createdCustomer.Customer, customerToCreate.Customer)
	}

}
示例#19
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)
	}

}
示例#20
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")
	}

}
示例#21
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")
	}

}
示例#22
0
func TestSubscriptionCreate(t *testing.T) {
	key := "test api key"

	mockSubscriptionResponseID := int64(1523)
	mockSubscriptionResponse := new(invdendpoint.Subscription)
	mockSubscriptionResponse.Id = mockSubscriptionResponseID
	mockSubscriptionResponse.CreatedAt = time.Now().UnixNano()
	mockSubscriptionResponse.Customer = 234112
	mockSubscriptionResponse.Plan = "234"

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

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

	defer server.Close()

	conn := mockConnection(key, server)

	subscription := conn.NewSubscription()

	subscriptionToCreate := subscription.NewSubscription()

	subscriptionToCreate.Customer = 234112
	subscriptionToCreate.Plan = "234"

	createdSubscription, err := subscription.Create(subscriptionToCreate)

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

	if !reflect.DeepEqual(createdSubscription.Subscription, mockSubscriptionResponse) {
		t.Fatal("Subscription Was Not Created Succesfully", createdSubscription.Subscription, mockSubscriptionResponse)
	}

}
示例#23
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)
	}

}
示例#24
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")
	}

}
示例#25
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")
	}

}