//go:build integration

package quote

import (
	"io"
	"net/http/httptest"
	"testing"
)

func TestHTTPIntegration(t *testing.T) {
	srv := httptest.NewServer(Handler(NewService(&priceFake{unit: 250})))
	t.Cleanup(srv.Close)
	resp, err := srv.Client().Get(srv.URL + "/quote?sku=pen&qty=2")
	if err != nil {
		t.Fatal(err)
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		t.Fatal(err)
	}
	if resp.StatusCode != 200 || string(body) != "total=500\n" {
		t.Fatalf("status=%d body=%q", resp.StatusCode, body)
	}
	t.Logf("network status=%d body=%q", resp.StatusCode, body)
}
