turniere-backend/spec/controllers/matches_controller_spec.rb

36 lines
971 B
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe MatchesController, type: :controller do
let(:valid_attributes) do
skip('Add a hash of attributes valid for your model')
end
let(:invalid_attributes) do
skip('Add a hash of attributes invalid for your model')
end
let(:valid_session) { {} }
before do
@match = create(:match)
@match.scores = create_pair(:score)
end
describe 'GET #show' do
it 'should return success' do
get :show, params: { id: @match.to_param }
expect(response).to be_successful
expect(response.content_type).to eq('application/json')
end
it 'should return the correct state' do
get :show, params: { id: @match.to_param }
body = ActiveModelSerializers::Deserialization.jsonapi_parse(JSON.parse(response.body))
expect(body[:state]).to be(@match.state)
expect(body[:score_ids]).to eq(@match.scores.map { |score| score.id.to_s })
end
end
end