Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/splits-io. a speedrunning data store and analysis engine splits.io
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110require 'rails_helper'
describe Api::V3::GamesController do let(:game) { FactoryBot.create(:game, name: 'Mario is Missing!') }
describe '#index' do context 'when given a search term which yields results' do subject(:response) { get(:index, params: {search: 'mario'}) } subject(:body) { JSON.parse(response.body)['games'] }
it 'returns an expected response code' do expect(response).to have_http_status(200) end
it 'returns with at least one result' do expect(body.count).to be > 0 end end
context 'when given a search term which does not yield results' do subject(:response) { get(:index, params: {search: 'fakegame123'}) } subject(:body) { JSON.parse(response.body)['games'] }
it 'returns an expected response code' do expect(response).to have_http_status(200) end
it 'returns an empty array' do expect(body).to eq [] end end
context 'when not given a search term' do subject(:response) { get :index } subject(:body) { JSON.parse(response.body)['games'] }
it 'returns an expected response code' do expect(response).to have_http_status(400) end end end
describe '#show' do let(:game) { FactoryBot.create(:game, :shortnamed) } let(:returned_attributes) { [:id, :name, :shortname, :categories] }
context 'when given an id' do context 'when the game exists' do subject(:response) { get(:show, params: {id: game.id}) } subject(:body) { JSON.parse(response.body)['game'] }
it 'returns an expected response code' do expect(response).to have_http_status(200) end
it 'returns the game' do returned_attributes.each do |attribute| expect(body[attribute.to_s]).to eq(game.send(attribute)) end end end
context 'when the game does not exist' do subject(:response) { get(:show, params: {id: 'bleep bloop blop'}) } subject(:body) { JSON.parse(response.body) }
it 'returns the correct response code' do expect(response).to have_http_status(404) end
it 'returns an error body' do expect(body['status']).to be_truthy expect(body['message']).to be_truthy end end end
context 'when given a shortname' do context 'when the game exists' do subject(:response) { get(:show, params: {id: game.id}) } subject(:body) { JSON.parse(response.body)['game'] }
it 'returns the correct response code' do expect(response).to have_http_status(200) end
it 'returns the game' do returned_attributes.each do |attribute| expect(body[attribute.to_s]).to eq(game.send(attribute)) end end end
context 'when the game does not exist' do subject(:response) { get(:show, params: {id: 'bleep bloop blop'}) } subject(:body) { JSON.parse(response.body) }
it 'returns the correct response code' do expect(response).to have_http_status(404) end
it 'returns an error body' do expect(body['status']).to be_truthy expect(body['message']).to be_truthy end end end endend