add invite game mode

This commit is contained in:
2026-11-15 19:19:35 +03:00
parent 8f70bb639d
commit a91eccbeaa
12 changed files with 600 additions and 58 deletions
@@ -30,6 +30,16 @@ RSpec.describe MatchmakingChannel, type: :channel do
expect(subscription).to be_confirmed
expect(transmissions.last).to eq(match_payload.as_json)
end
it "transmits current invite code if one was active for the user" do
allow(MatchmakingService).to receive(:claim).with(user.id).and_return(nil)
allow(MatchmakingService).to receive(:current_invite_code).with(user.id).and_return("ABCDE")
subscribe
expect(subscription).to be_confirmed
expect(transmissions.last).to eq({ "type" => "invite_created", "code" => "ABCDE" })
end
end
describe "#start" do
@@ -57,6 +67,46 @@ RSpec.describe MatchmakingChannel, type: :channel do
end
end
describe "#create_invite" do
it "calls MatchmakingService.create_invite and transmits invite_created" do
subscribe
expect(MatchmakingService).to receive(:create_invite).with(user.id).and_return("XYZAB")
perform :create_invite
expect(transmissions.last).to eq({ "type" => "invite_created", "code" => "XYZAB" })
end
end
describe "#join_invite" do
it "calls MatchmakingService.join_invite with code" do
subscribe
expect(MatchmakingService).to receive(:join_invite).with(user.id, "XYZAB").and_return({ ok: true })
perform :join_invite, { "code" => "XYZAB" }
end
it "transmits invite_error if join fails" do
subscribe
expect(MatchmakingService).to receive(:join_invite).with(user.id, "WRONG").and_return(
{ error: "not_found", message: "Приглашение не найдено или истекло" }
)
perform :join_invite, { "code" => "WRONG" }
expect(transmissions.last).to eq(
{ "type" => "invite_error", "error" => "not_found", "message" => "Приглашение не найдено или истекло" }
)
end
end
describe "#cancel_invite" do
it "calls MatchmakingService.cancel for the current user" do
subscribe
expect(MatchmakingService).to receive(:cancel).with(user.id)
perform :cancel_invite
end
end
describe "#unsubscribed" do
it "cancels matchmaking search when unsubscribing" do
subscribe