Пример #1
0
func TestSubscriptionRetrieve(t *testing.T) {

	key := "test api key"

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

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

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

	conn := mockConnection(key, server)
	subscription := conn.NewSubscription()

	retrievedSubscription, err := subscription.Retrieve(mockSubscriptionResponseID)

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

	if !reflect.DeepEqual(retrievedSubscription.Subscription, mockSubscriptionResponse) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
Пример #2
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")
	}

}
Пример #3
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)
	}

}