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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129require 'rails_helper'
describe Api::V3::RunsController do describe '#show' do let(:game) do instance_double( "Game", name: "Tron: Evolution", read_attribute_for_serialization: self, ) end let(:category) do instance_double( "Category", game: game, name: "Any% NG+", read_attribute_for_serialization: self, ) end let(:run) do instance_double( "Run", id: 10, id36: 'a', path: '/a', game: game, category: category, to_s: "Tron: Evolution Any% NG+", image_url: nil, realtime_sum_of_best_s: 2, splits: [ instance_double("Split", 'realtime_best' => 3, 'best=' => true) ], read_attribute_for_serialization: self, ) create(:run) end
context 'when given a valid id' do subject(:response) { get :show, params: {id: run.id36} } subject(:body) { JSON.parse(response.body)['run'] }
it '200s' do expect(response).to have_http_status(200) end
it 'returns a run with the correct id' do expect(body['id']).to eq(run.id) end end
context 'when given a bad id' do subject(:response) { get :show, params: {id: '...'} } subject(:body) { JSON.parse(response.body) }
it '404s' 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
describe '#create' do let(:run) do create(:run) end
context 'when given no OAuth token' do subject(:response) { post :create, params: {file: run.file} }
it '201s' do expect(response).to have_http_status(201) end end
context 'when given an invalid OAuth token' do subject(:response) { post :create, params: {file: run.file} }
it '401s' do request.headers['Authorization'] = 'Bearer bad_token'
expect(response).to have_http_status(401) end end
context 'when given a valid OAuth token with no scopes' do subject(:response) { post :create, params: {file: run.file} }
it '403s' do application = Doorkeeper::Application.create( name: 'Test Application', redirect_uri: 'http://localhost:3000/', owner: create(:user) ) authorization = Doorkeeper::AccessToken.create(application_id: application.id, resource_owner_id: create(:user)) auth_header = "Bearer #{authorization.token}" request.headers['Authorization'] = auth_header
expect(response).to have_http_status(403) end end
context 'when given a valid OAuth token with an upload_run scope' do subject(:response) { post :create, params: {file: run.file} }
it '201s' do application = Doorkeeper::Application.create( name: 'Test Application', redirect_uri: 'http://localhost:3000/', owner: create(:user) ) authorization = Doorkeeper::AccessToken.create( application_id: application.id, resource_owner_id: create(:user), scopes: 'upload_run' ) auth_header = "Bearer #{authorization.token}" request.headers['Authorization'] = auth_header
expect(response).to have_http_status(201) end end endend