package job

import (
	"encoding/json"
	"testing"
)

func TestJobJSONRoundTrip(t *testing.T) {
	in := Job{
		ID: "j1", Height: 2800000, BlockTemplate: "tpl", Difficulty: 100000,
		SeedHash: "seed", Target: "target", Blob: "deadbeef", Algo: "rx/0",
	}
	b, err := json.Marshal(in)
	if err != nil {
		t.Fatal(err)
	}
	var out Job
	if err := json.Unmarshal(b, &out); err != nil {
		t.Fatal(err)
	}
	if out.ID != in.ID || out.Blob != in.Blob || out.Algo != in.Algo {
		t.Fatalf("mismatch: %+v", out)
	}
}

func TestJobMinimalJSON(t *testing.T) {
	var out Job
	if err := json.Unmarshal([]byte(`{"job_id":"x"}`), &out); err != nil {
		t.Fatal(err)
	}
	if out.ID != "x" {
		t.Fatalf("got %q", out.ID)
	}
}
