65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"tutor/internal/config"
|
|
"tutor/internal/interview"
|
|
"tutor/internal/learnermemory"
|
|
"tutor/internal/ontology"
|
|
"tutor/internal/progression"
|
|
"tutor/internal/teachingassets"
|
|
"tutor/internal/workflows"
|
|
)
|
|
|
|
func TestTeachingAssetsHTTPFlow(t *testing.T) {
|
|
memory := learnermemory.NewService(learnermemory.NewMemoryStore())
|
|
service := interview.NewService(interview.NewMemoryStore(), workflows.NewStubRunner(), memory)
|
|
progress := progression.NewService(memory)
|
|
onto := ontology.NewService(ontology.NewMemoryStore())
|
|
assets := teachingassets.NewService(teachingassets.NewMemoryStore(), onto, "gpt-image-v2")
|
|
handler := NewHandler(config.Config{Environment: "test"}, service, memory, progress, onto, assets)
|
|
routes := handler.Routes()
|
|
|
|
ingestBody := bytes.NewBufferString(`{
|
|
"title":"Backend notes",
|
|
"body":"Idempotent API retries need transactions."
|
|
}`)
|
|
ingestReq := httptest.NewRequest(http.MethodPost, "/api/v1/materials", ingestBody)
|
|
ingestRec := httptest.NewRecorder()
|
|
routes.ServeHTTP(ingestRec, ingestReq)
|
|
if ingestRec.Code != http.StatusCreated {
|
|
t.Fatalf("ingest status = %d, body = %s", ingestRec.Code, ingestRec.Body.String())
|
|
}
|
|
|
|
promptBody := bytes.NewBufferString(`{
|
|
"concept_id":"http-idempotency",
|
|
"asset_type":"diagram"
|
|
}`)
|
|
promptReq := httptest.NewRequest(http.MethodPost, "/api/v1/teaching-assets/prompts", promptBody)
|
|
promptRec := httptest.NewRecorder()
|
|
routes.ServeHTTP(promptRec, promptReq)
|
|
if promptRec.Code != http.StatusCreated {
|
|
t.Fatalf("prompt status = %d, body = %s", promptRec.Code, promptRec.Body.String())
|
|
}
|
|
|
|
var prompt teachingassets.PromptCandidate
|
|
if err := json.NewDecoder(promptRec.Body).Decode(&prompt); err != nil {
|
|
t.Fatalf("decode prompt response: %v", err)
|
|
}
|
|
if !prompt.RequiresModelIDVerification {
|
|
t.Fatal("expected verification guard")
|
|
}
|
|
|
|
getReq := httptest.NewRequest(http.MethodGet, "/api/v1/teaching-assets", nil)
|
|
getRec := httptest.NewRecorder()
|
|
routes.ServeHTTP(getRec, getReq)
|
|
if getRec.Code != http.StatusOK {
|
|
t.Fatalf("assets status = %d, body = %s", getRec.Code, getRec.Body.String())
|
|
}
|
|
}
|