package store import ( "testing" "time" ) func TestProposalRecoverySQLBindsParticipantAndExpiresAtReadBoundary(t *testing.T) { for query, fragments := range map[string][]string{ ProposalExpireSQL: {"state = 'OPEN'", "expires_at <= $2", "revision = revision + 1"}, ProposalParticipantExpireSQL: {"response = 'PENDING'", "response = 'TIMED_OUT'", "proposals.expires_at <= $2"}, ProposalRecoverySelectSQL: {"proposal_id = $1", "player_id = $2", "EXISTS"}, ProposalParticipantsSelectSQL: {"proposal_id = $1", "ORDER BY player_id"}, ProposalResponseIdempotencyInsertSQL: {"ON CONFLICT (scope, idempotency_key) DO NOTHING", "payload_digest"}, ProposalLockSQL: {"proposal_id = $1", "FOR UPDATE"}, ProposalParticipantLockSQL: {"proposal_id = $1", "player_id = $2", "FOR UPDATE"}, ProposalParticipantRespondSQL: {"response = 'PENDING'", "responded_at"}, ProposalRevisionBumpSQL: {"revision = revision + 1", "state = 'OPEN'"}, ProposalDeclineRequeueSQL: {"SET state = 'QUEUED'", "state = 'PROPOSED'", "proposal_participants"}, } { for _, fragment := range fragments { if !contains(query, fragment) { t.Fatalf("query %q missing %q", query, fragment) } } } } func TestProposalRecoveryRejectsMissingAuthorityInputs(t *testing.T) { if _, err := GetProposal(nil, nil, "player-1", "proposal-1", time.Unix(1000, 0)); err == nil { t.Fatal("nil database accepted") } if _, err := GetProposal(nil, nil, "", "proposal-1", time.Unix(1000, 0)); err == nil { t.Fatal("empty player accepted") } }