Added api/classifications endpoint, requiring a new query
This commit is contained in:
1 parent
378ac59f41
commit
0e27d2b2f3
9 files changed
+186
-6
No files matched your search
@@ -0,0 +1,41 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user