remove create_new functionality, when exercise exists on CH but is not editable

This commit is contained in:
Karol
2019-12-13 16:43:19 +01:00
parent eb7a4d5933
commit f680916385
8 changed files with 44 additions and 56 deletions

View File

@@ -350,7 +350,7 @@ describe ExercisesController do
include('button').and(include('Abort')).and(include('Retry'))
)
expect(JSON.parse(response.body).symbolize_keys[:actions]).to(
not_include('Create new').and(not_include('Export')).and(not_include('Hide'))
not_include('Export').and(not_include('Hide'))
)
end
end
@@ -362,7 +362,7 @@ describe ExercisesController do
post_request
expect(JSON.parse(response.body).symbolize_keys[:message]).to eq('message')
expect(JSON.parse(response.body).symbolize_keys[:actions]).to(
include('button').and(include('Abort')).and(include('Create new'))
include('button').and(include('Abort'))
)
expect(JSON.parse(response.body).symbolize_keys[:actions]).to(
not_include('Retry').and(not_include('Export')).and(not_include('Hide'))
@@ -375,8 +375,7 @@ describe ExercisesController do
render_views
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
let(:post_request) { post :export_external_confirm, params: {push_type: push_type, id: exercise.id, codeharbor_link: codeharbor_link.id} }
let(:push_type) { 'create_new' }
let(:post_request) { post :export_external_confirm, params: {id: exercise.id, codeharbor_link: codeharbor_link.id} }
let(:error) {}
let(:zip) { 'zip' }
@@ -407,15 +406,6 @@ describe ExercisesController do
expect(JSON.parse(response.body).symbolize_keys[:actions]).to(not_include('Abort'))
end
end
context 'without push_type' do
let(:push_type) {}
it 'responds with status 500' do
post_request
expect(response).to have_http_status(:internal_server_error)
end
end
end
describe '#import_uuid_check' do
@@ -433,7 +423,6 @@ describe ExercisesController do
expect(JSON.parse(response.body).symbolize_keys[:exercise_found]).to be true
expect(JSON.parse(response.body).symbolize_keys[:update_right]).to be true
expect(JSON.parse(response.body).symbolize_keys[:message]).to(include('has been found').and(include('Overwrite')))
end
context 'when api_key is incorrect' do
@@ -445,7 +434,7 @@ describe ExercisesController do
end
end
context 'when the user is cannot update the exercise' do
context 'when the user cannot update the exercise' do
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link, api_key: 'anotherkey') }
it 'renders correct response' do
@@ -454,7 +443,6 @@ describe ExercisesController do
expect(JSON.parse(response.body).symbolize_keys[:exercise_found]).to be true
expect(JSON.parse(response.body).symbolize_keys[:update_right]).to be false
expect(JSON.parse(response.body).symbolize_keys[:message]).to(include('has been found').and(not_include('Overwrite')))
end
end
@@ -466,7 +454,6 @@ describe ExercisesController do
expect(response).to have_http_status(:success)
expect(JSON.parse(response.body).symbolize_keys[:exercise_found]).to be false
expect(JSON.parse(response.body).symbolize_keys[:message]).to(include('No corresponding exercise'))
end
end
end

View File

@@ -42,17 +42,25 @@ describe ExerciseService::CheckExternal do
end
context 'when response contains a JSON with expected keys' do
let(:response) { {message: 'message', exercise_found: true, update_right: true}.to_json }
let(:response) { {exercise_found: true, update_right: true}.to_json }
it 'returns the correct hash' do
expect(check_external_service).to eql(error: false, message: 'message', exercise_found: true, update_right: true)
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.exercise_found'), exercise_found: true, update_right: true)
end
context 'with different values' do
let(:response) { {message: 'message', exercise_found: false, update_right: false}.to_json }
context 'with exercise_found: false and no update_right' do
let(:response) { {exercise_found: false}.to_json }
it 'returns the correct hash' do
expect(check_external_service).to eql(error: false, message: 'message', exercise_found: false, update_right: false)
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.no_exercise'), exercise_found: false)
end
end
context 'with exercise_found: true and update_right: false' do
let(:response) { {exercise_found: true, update_right: false}.to_json }
it 'returns the correct hash' do
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.exercise_found_no_right'), exercise_found: true, update_right: false)
end
end
end