コード例 #1
0
ファイル: product_test.go プロジェクト: mxmCherry/goshop
func TestCreateProduct(t *testing.T) {

	_name := generateName("Product")

	payload := data.Product{
		ID:   0,
		Name: _name,
		Price: data.Price{
			Vat:   20,
			Net:   100,
			Gross: 0,
		},
	}

	got := data.Product{}

	expected := data.Product{
		ID:   0,
		Name: _name,
		Price: data.Price{
			Vat:   20,
			Net:   100,
			Gross: 120,
		},
	}

	resp := postJSON(
		fmt.Sprintf("%s/products/", getURL()),
		payload,
		&got,
	)

	if resp.StatusCode != http.StatusCreated {
		t.Errorf("Got status: %d, expected: %d", resp.StatusCode, http.StatusCreated)
	}

	if got.ID == 0 {
		t.Errorf("Got ID: %d, expected: > 0", got.ID)
	}

	expected.ID = got.ID

	if !reflect.DeepEqual(got, expected) {
		t.Fatalf("Got: %s\n\nExpected: %s", testutils.JSON(got), testutils.JSON(expected))
		return
	}

}