RezinaLMS-BackEnd/internal/domain/practice_stimulus_block_test.go
Yared Yemane 6dc352b5e0 Keep shared and question stimuli separate and additive.
Preserve matching stimulus IDs, validate question-owned payloads independently, and expose additive effective payloads without overriding shared content.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-16 11:35:56 -07:00

51 lines
1.7 KiB
Go

package domain
import "testing"
func TestMergeEffectiveDynamicPayload_blockAndQuestionStimulus(t *testing.T) {
block := []DynamicElementInstance{
{ID: "passage", Kind: "TEXT_PASSAGE", Value: "shared passage"},
{ID: "audio", Kind: "AUDIO_PROMPT", Value: "https://cdn.example.com/audio.mp3"},
}
question := &DynamicQuestionPayload{
Stimulus: []DynamicElementInstance{
{ID: "audio", Kind: "AUDIO_PROMPT", Value: "https://cdn.example.com/override.mp3"},
},
Response: []DynamicElementInstance{
{ID: "answer", Kind: "SHORT_ANSWER"},
},
}
got := MergeEffectiveDynamicPayload(block, question)
if got == nil {
t.Fatal("expected merged payload")
}
if len(got.Stimulus) != 3 {
t.Fatalf("expected all 3 stimulus elements, got %d", len(got.Stimulus))
}
if got.Stimulus[0].Value != "shared passage" {
t.Fatalf("expected block passage first, got %#v", got.Stimulus[0].Value)
}
if got.Stimulus[1].Value != "https://cdn.example.com/audio.mp3" {
t.Fatalf("expected shared audio to be preserved, got %#v", got.Stimulus[1].Value)
}
if got.Stimulus[2].Value != "https://cdn.example.com/override.mp3" {
t.Fatalf("expected question audio to be appended despite duplicate id, got %#v", got.Stimulus[2].Value)
}
if len(got.Response) != 1 {
t.Fatalf("expected response from question payload")
}
}
func TestValidateStimulusBlockKeyReferences_unknownKey(t *testing.T) {
memberships := []QuestionSetMembership{
{QuestionID: 1, DisplayOrder: 1, StimulusBlockKey: strPtr("missing")},
}
err := ValidateStimulusBlockKeyReferences(memberships, map[string]struct{}{"block-a": {}})
if err == nil {
t.Fatal("expected error for unknown stimulus_block_key")
}
}
func strPtr(s string) *string { return &s }