Fix tests
This commit is contained in:
parent
7b9a454cb6
commit
bdcc6e1182
|
|
@ -478,17 +478,15 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#validate_set_timer_end_params' do
|
describe 'PATCH #set_timer_end' do
|
||||||
let(:tournament) { create(:tournament) }
|
before(:each) do
|
||||||
|
apply_authentication_headers_for @tournament.owner
|
||||||
before do
|
|
||||||
apply_authentication_headers_for tournament.owner
|
|
||||||
@request.env['HTTP_ACCEPT'] = 'application/json'
|
@request.env['HTTP_ACCEPT'] = 'application/json'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when timer_end is missing' do
|
context 'when timer_end is missing' do
|
||||||
it 'returns unprocessable entity' do
|
it 'returns unprocessable entity' do
|
||||||
patch :set_timer_end, params: { id: tournament.id }
|
patch :set_timer_end, params: { id: @tournament.id }
|
||||||
expect(response).to have_http_status(:unprocessable_entity)
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
expect(JSON.parse(response.body)).to include('error' => 'Timer end is required')
|
expect(JSON.parse(response.body)).to include('error' => 'Timer end is required')
|
||||||
end
|
end
|
||||||
|
|
@ -496,7 +494,7 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
|
|
||||||
context 'when timer_end is invalid datetime' do
|
context 'when timer_end is invalid datetime' do
|
||||||
it 'returns unprocessable entity' do
|
it 'returns unprocessable entity' do
|
||||||
patch :set_timer_end, params: { id: tournament.id, timer_end: 'invalid' }
|
patch :set_timer_end, params: { id: @tournament.id, timer_end: 'invalid' }
|
||||||
expect(response).to have_http_status(:unprocessable_entity)
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
expect(JSON.parse(response.body)).to include('error' => 'Invalid datetime format')
|
expect(JSON.parse(response.body)).to include('error' => 'Invalid datetime format')
|
||||||
end
|
end
|
||||||
|
|
@ -504,36 +502,42 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
|
|
||||||
context 'when timer_end is in the past' do
|
context 'when timer_end is in the past' do
|
||||||
it 'returns unprocessable entity' do
|
it 'returns unprocessable entity' do
|
||||||
patch :set_timer_end, params: { id: tournament.id, timer_end: 1.day.ago }
|
patch :set_timer_end, params: { id: @tournament.id, timer_end: 1.day.ago }
|
||||||
expect(response).to have_http_status(:unprocessable_entity)
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
expect(JSON.parse(response.body)).to include('error' => 'Timer end must be in the future')
|
expect(JSON.parse(response.body)).to include('error' => 'Timer end must be in the future')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when timer_end is valid' do
|
context 'when timer_end is valid' do
|
||||||
it 'passes validation' do
|
it 'updates the timer_end' do
|
||||||
patch :set_timer_end, params: { id: tournament.id, timer_end: 1.day.from_now }
|
valid_timer_end = 1.day.from_now.change(usec: 0)
|
||||||
|
patch :set_timer_end, params: { id: @tournament.id, timer_end: valid_timer_end }
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
|
expect(@tournament.reload.timer_end).to eq(valid_timer_end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #timer_end', focus:true do
|
describe 'GET #timer_end' do
|
||||||
let(:tournament) { create(:tournament) }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@request.env['HTTP_ACCEPT'] = 'application/json'
|
@request.env['HTTP_ACCEPT'] = 'application/json'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns success response' do
|
it 'returns success response' do
|
||||||
get :timer_end, params: { id: tournament.to_param }
|
get :timer_end, params: { id: @tournament.to_param }
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns timer_end value' do
|
it 'returns timer_end value' do
|
||||||
tournament.update(timer_end: Time.zone.now + 1.day)
|
@tournament.update(timer_end: Time.zone.now + 1.day)
|
||||||
get :timer_end, params: { id: tournament.to_param }
|
get :timer_end, params: { id: @tournament.to_param }
|
||||||
expect(JSON.parse(response.body)['timer_end']).to eq(tournament.timer_end.as_json)
|
expect(JSON.parse(response.body)['timer_end']).to eq(@tournament.timer_end.as_json)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil if timer_end is not set' do
|
||||||
|
@tournament.update(timer_end: nil)
|
||||||
|
get :timer_end, params: { id: @tournament.to_param }
|
||||||
|
expect(JSON.parse(response.body)['timer_end']).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue