persist match informtion in DB
This commit is contained in:
@@ -11,7 +11,12 @@ RSpec.describe MatchmakingService do
|
||||
# are reset per example, so a global counter is used).
|
||||
def uid(base)
|
||||
$matchmaking_spec_uid = ($matchmaking_spec_uid || 0) + 1
|
||||
$matchmaking_spec_uid * 1000 + base
|
||||
# Explicit ids stay unique across examples: Action Cable test-adapter
|
||||
# broadcasts persist between examples, so reusing ids would make a
|
||||
# previous example's broadcast leak into the next one.
|
||||
User.create!(id: 100_000 + $matchmaking_spec_uid,
|
||||
nickname: "mm_user_#{$matchmaking_spec_uid}",
|
||||
password: "secret123").id
|
||||
end
|
||||
|
||||
def broadcasts_for(user_id)
|
||||
@@ -71,6 +76,23 @@ RSpec.describe MatchmakingService do
|
||||
expect(broadcasts_for(a).size).to eq(1)
|
||||
expect(described_class.claim(a)).to be_nil
|
||||
end
|
||||
|
||||
it "persists a Match record in the database" do
|
||||
a, b = uid(1), uid(2)
|
||||
described_class.enqueue(a, rating: 1000)
|
||||
described_class.enqueue(b, rating: 1000)
|
||||
|
||||
match = Match.find_by!(uuid: broadcast_payloads(a).first[:match_id])
|
||||
expect([ match.player1_id, match.player2_id ]).to contain_exactly(a, b)
|
||||
expect(match).to be_ongoing
|
||||
expect(match.game_server).to eq(described_class.config.game_server_url)
|
||||
expect(match.started_at).to be_present
|
||||
expect(match.player1_rating_before).to eq(User.find(a).rating)
|
||||
expect(match.player2_rating_before).to eq(User.find(b).rating)
|
||||
expect(match.player1_rating_change).to eq(0)
|
||||
expect(match.player2_rating_change).to eq(0)
|
||||
expect(match.finished_at).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe ".sweep" do
|
||||
|
||||
Reference in New Issue
Block a user