forked from longtao.wu/droboticflow
48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"droboticflow/internal/domain"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func putReviewDraft(t *testing.T, f combinedDraftFixture, endpoint, resultVersion, operationID string, version int, problems []map[string]any, headers map[string]string) *httptest.ResponseRecorder {
|
|
t.Helper()
|
|
payload := map[string]any{"version": version, "resultVersion": resultVersion, "operationId": operationID, "problems": problems}
|
|
return reviewSessionRequest(f, http.MethodPut, endpoint, f.reviewer, payload, headers)
|
|
}
|
|
|
|
func readReviewDraft(t *testing.T, f combinedDraftFixture, endpoint string) domain.ReviewDraft {
|
|
t.Helper()
|
|
w := f.request(http.MethodGet, endpoint, f.reviewer, nil)
|
|
if w.Code != 200 {
|
|
t.Fatalf("read draft %d %s", w.Code, w.Body.String())
|
|
}
|
|
var state struct {
|
|
Draft domain.ReviewDraft `json:"draft"`
|
|
}
|
|
if e := json.Unmarshal(w.Body.Bytes(), &state); e != nil {
|
|
t.Fatalf("draft json %v %s", e, w.Body.String())
|
|
}
|
|
return state.Draft
|
|
}
|
|
|
|
func problemEntry(id, scope, source, slice, action, text string, at float64) map[string]any {
|
|
return map[string]any{"id": id, "scope": scope, "sourceItemId": source, "sliceId": slice, "actionId": action, "text": text, "atSeconds": at}
|
|
}
|
|
|
|
func checkProblemList(t *testing.T, draft domain.ReviewDraft, wantIDs ...string) []domain.ReviewProblem {
|
|
t.Helper()
|
|
if len(draft.Problems) != len(wantIDs) {
|
|
t.Fatalf("problem count %d want %d: %+v", len(draft.Problems), len(wantIDs), draft.Problems)
|
|
}
|
|
for i, want := range wantIDs {
|
|
if draft.Problems[i].ID != want {
|
|
t.Fatalf("problem %d is %q want %q (order: %+v)", i, draft.Problems[i].ID, want, draft.Problems)
|
|
}
|
|
}
|
|
return draft.Problems
|
|
}
|