mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
feat(multiplayer): publish allocation state events
This commit is contained in:
@@ -61,3 +61,22 @@ func TestDeliverResultOutboxEventRejectsMalformedRows(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeliverStateOutboxEventValidatesRevisionAndTargets(t *testing.T) {
|
||||
service := &Service{}
|
||||
first := service.getEventHub().subscribe("player-a")
|
||||
defer service.getEventHub().unsubscribe(first)
|
||||
payload := []byte(`{"event":"state_changed","revision":4,"resource_id":"match-1","occurred_at":"1970-01-01T00:16:40Z","state":"ASSIGNMENT_READY","match_id":"match-1","player_ids":["player-a"]}`)
|
||||
if err := deliverStateOutboxEvent(context.Background(), store.OutboxEvent{EventType: "state_changed", AggregateID: "match-1", Revision: 4, Payload: payload}, service); err != nil {
|
||||
t.Fatalf("valid state event rejected: %v", err)
|
||||
}
|
||||
select {
|
||||
case <-first.queue:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("participant did not receive state event")
|
||||
}
|
||||
bad := []byte(`{"event":"state_changed","revision":3,"resource_id":"match-1","state":"LIVE","player_ids":["player-a"]}`)
|
||||
if err := deliverStateOutboxEvent(context.Background(), store.OutboxEvent{EventType: "state_changed", AggregateID: "match-1", Revision: 4, Payload: bad}, service); err == nil {
|
||||
t.Fatal("revision-mismatched state event accepted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user