42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"git.avsdev.uk/Go/job-search/internal/types"
|
|
)
|
|
|
|
// The classifications the opportunities have are listed once each, by code.
|
|
func TestListClassifications(t *testing.T) {
|
|
url := opportunitiesServer(t, 3)
|
|
|
|
var classifications []types.ClassificationCode
|
|
status := request(t, "GET", url+"/classifications", &classifications)
|
|
if status != http.StatusOK {
|
|
t.Fatalf("status %d", status)
|
|
}
|
|
if len(classifications) != 2 ||
|
|
classifications[0].Code != "03000000" ||
|
|
classifications[1].Code != "72000000" ||
|
|
classifications[0].ID == 0 {
|
|
t.Errorf("got %+v; want 03000000 then 72000000, with ids", classifications)
|
|
}
|
|
}
|
|
|
|
// With no opportunities, the list is [] in JSON, not null.
|
|
func TestListClassificationsEmpty(t *testing.T) {
|
|
url := opportunitiesServer(t, 0)
|
|
res, err := http.Get(url + "/classifications")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer res.Body.Close()
|
|
var raw json.RawMessage
|
|
json.NewDecoder(res.Body).Decode(&raw)
|
|
if string(raw) != "[]" {
|
|
t.Errorf("body = %s; want []", raw)
|
|
}
|
|
}
|