Ejemplo n.º 1
0
func TestOrderListOptions(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders.json?limit=250&page=10&status=any",
		httpmock.NewBytesResponder(200, loadFixture("orders.json")))

	options := OrderListOptions{
		Page:   10,
		Limit:  250,
		Status: "any"}

	orders, err := client.Order.List(options)
	if err != nil {
		t.Errorf("Order.List returned error: %v", err)
	}

	// Check that orders were parsed
	if len(orders) != 1 {
		t.Errorf("Order.List got %v orders, expected: 1", len(orders))
	}

	order := orders[0]
	orderTests(t, order)
}
Ejemplo n.º 2
0
func MockHTTP() {
	httpmock.Activate()
	f, err := ioutil.ReadFile("testdata/feeds.xml")
	if err != nil {
		panic(err)
	}

	httpmock.RegisterResponder("GET", "https://github.com/pocke.private",
		httpmock.NewBytesResponder(http.StatusOK, f))

	f, err = ioutil.ReadFile("testdata/feeds_api.json")
	if err != nil {
		panic(err)
	}

	httpmock.RegisterResponder("GET", "https://api.github.com/feeds",
		httpmock.NewBytesResponder(http.StatusOK, f))
}
Ejemplo n.º 3
0
func TestWebhookGet(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/webhooks/4759306.json",
		httpmock.NewBytesResponder(200, loadFixture("webhook.json")))

	webhook, err := client.Webhook.Get(4759306, nil)
	if err != nil {
		t.Errorf("Webhook.Get returned error: %v", err)
	}

	webhookTests(t, *webhook)
}
Ejemplo n.º 4
0
func TestOrderGet(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/123456.json",
		httpmock.NewBytesResponder(200, loadFixture("order.json")))

	order, err := client.Order.Get(123456, nil)
	if err != nil {
		t.Errorf("Order.List returned error: %v", err)
	}

	orderTests(t, *order)
}
func TestSearchWikipedia(t *testing.T) {
	testPayload, _ = ioutil.ReadFile("../test_json/mount_blade.json")

	httpmock.Activate()
	defer httpmock.DeactivateAndReset()

	httpmock.RegisterResponder("GET", generateURL("Mount & Blade"), httpmock.NewBytesResponder(200, testPayload))

	session, _ = getSession("localhost")
	session.DB("steamfetcher_test").DropDatabase()
	db = &database.MongoDB{Collection: session.DB("steamfetcher_test").C("games")}
	db.SetSession(session)

	db.Collection.Insert(bson.M{"steam_id": 1, "name": "Mount & Blade"})

	t.Run("updating entries that do not have the wikipedia URL", testSearch)
}
Ejemplo n.º 6
0
func TestWebhookList(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/webhooks.json",
		httpmock.NewBytesResponder(200, loadFixture("webhooks.json")))

	webhooks, err := client.Webhook.List(nil)
	if err != nil {
		t.Errorf("Webhook.List returned error: %v", err)
	}

	// Check that webhooks were parsed
	if len(webhooks) != 1 {
		t.Errorf("Webhook.List got %v webhooks, expected: 1", len(webhooks))
	}

	webhookTests(t, webhooks[0])
}
Ejemplo n.º 7
0
func TestWebhookCreate(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/webhooks.json",
		httpmock.NewBytesResponder(200, loadFixture("webhook.json")))

	webhook := Webhook{
		Topic:   "orders/create",
		Address: "http://example.com",
	}

	returnedWebhook, err := client.Webhook.Create(webhook)
	if err != nil {
		t.Errorf("Webhook.Create returned error: %v", err)
	}

	webhookTests(t, *returnedWebhook)
}
Ejemplo n.º 8
0
func TestOrderList(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders.json",
		httpmock.NewBytesResponder(200, loadFixture("orders.json")))

	orders, err := client.Order.List(nil)
	if err != nil {
		t.Errorf("Order.List returned error: %v", err)
	}

	// Check that orders were parsed
	if len(orders) != 1 {
		t.Errorf("Order.List got %v orders, expected: 1", len(orders))
	}

	order := orders[0]
	orderTests(t, order)
}
Ejemplo n.º 9
0
func TestShopGet(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/shop.json",
		httpmock.NewBytesResponder(200, loadFixture("shop.json")))

	shop, err := client.Shop.Get(nil)
	if err != nil {
		t.Errorf("Shop.Get returned error: %v", err)
	}

	// Check that dates are parsed
	d := time.Date(2007, time.December, 31, 19, 00, 00, 0, time.UTC)
	if !d.Equal(*shop.CreatedAt) {
		t.Errorf("Shop.CreatedAt returned %+v, expected %+v", shop.CreatedAt, d)
	}

	// Test a few fields
	cases := []struct {
		field    string
		expected interface{}
		actual   interface{}
	}{
		{"ID", 690933842, shop.ID},
		{"ShopOwner", "Steve Jobs", shop.ShopOwner},
		{"Address1", "1 Infinite Loop", shop.Address1},
		{"Name", "Apple Computers", shop.Name},
		{"Email", "*****@*****.**", shop.Email},
		{"HasStorefront", true, shop.HasStorefront},
	}

	for _, c := range cases {
		if c.expected != c.actual {
			t.Errorf("Shop.%v returned %v, expected %v", c.field, c.actual, c.expected)
		}
	}
}