aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorTeddy Wing2017-12-06 15:53:57 +0100
committerTeddy Wing2017-12-06 15:53:57 +0100
commitfc0c6de84a34d98d87b655e103c88c42e2f18661 (patch)
treec4aa6a32f835995f2b8313076bb72528f866fa69 /spec
parent5ae238936d3c91e70709c2ec4ed8a73a6f4524dc (diff)
parent0bb71d8146126f4f2c53ca0c7145f0e7d5eaeda5 (diff)
downloadchouette-core-fc0c6de84a34d98d87b655e103c88c42e2f18661.tar.bz2
Merge remote-tracking branch 'origin/master' into 5024-prevent-duplicate-referentials-from-being-created-during-parallel-db-transactions--rb201711271659
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/compliance_check_sets_controller_spec.rb37
-rw-r--r--spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb52
-rw-r--r--spec/controllers/api/v1/internals/netex_imports_controller_spec.rb42
-rw-r--r--spec/controllers/compliance_check_sets_controller_spec.rb22
-rw-r--r--spec/support/shared_context.rb16
5 files changed, 110 insertions, 59 deletions
diff --git a/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb b/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb
deleted file mode 100644
index 1c3784807..000000000
--- a/spec/controllers/api/v1/compliance_check_sets_controller_spec.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-RSpec.describe Api::V1::ComplianceCheckSetsController, type: :controller do
- include_context 'iboo authenticated api user'
-
- describe "POST #validate" do
- let(:check_set) { create(:compliance_check_set) }
-
- it "calls #update_status on the ComplianceCheckSet" do
- expect_any_instance_of(ComplianceCheckSet).to receive(:update_status)
-
- patch :validated, id: check_set.id
- end
-
- context "responds with" do
- render_views
-
- it "object JSON on #update_status true" do
- allow_any_instance_of(
- ComplianceCheckSet
- ).to receive(:update_status).and_return(true)
-
- patch :validated, id: check_set.id
-
- expect(JSON.parse(response.body)['id']).to eq(check_set.id)
- end
-
- it "error JSON on #update_status false" do
- allow_any_instance_of(
- ComplianceCheckSet
- ).to receive(:update_status).and_return(false)
-
- patch :validated, id: check_set.id
-
- expect(response.body).to include('error')
- end
- end
- end
-end
diff --git a/spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb b/spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb
new file mode 100644
index 000000000..e73790384
--- /dev/null
+++ b/spec/controllers/api/v1/internals/compliance_check_sets_controller_spec.rb
@@ -0,0 +1,52 @@
+require 'rails_helper'
+
+RSpec.describe Api::V1::Internals::ComplianceCheckSetsController, type: :controller do
+ let(:check_set_1) { create :compliance_check_set }
+ let(:check_set_2) { create :compliance_check_set }
+
+ describe "GET #notify_parent" do
+ context 'unauthenticated' do
+ include_context 'iboo wrong authorisation internal api'
+
+ it 'should not be successful' do
+ get :notify_parent, id: check_set_1.id, format: :json
+ expect(response).to have_http_status 401
+ end
+ end
+
+ context 'authenticated' do
+ include_context 'iboo authenticated internal api'
+
+ describe "with existing record" do
+
+ before(:each) do
+ get :notify_parent, id: check_set_2.id, format: :json
+ end
+
+ it 'should be successful' do
+ expect(response).to have_http_status 200
+ end
+
+ describe "that has a parent" do
+ xit "calls #notify_parent on the import" do
+ expect(check_set_2.reload.notified_parent_at).not_to be_nil
+ end
+ end
+
+ describe "that does not have a parent" do
+ xit "should not be successful" do
+ expect(response.body).to include("error")
+ end
+ end
+
+ end
+
+ describe "with non existing record" do
+ it "should throw an error" do
+ get :notify_parent, id: 47, format: :json
+ expect(response.body).to include("error")
+ end
+ end
+ end
+ end
+end
diff --git a/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb b/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb
new file mode 100644
index 000000000..ccdc258f4
--- /dev/null
+++ b/spec/controllers/api/v1/internals/netex_imports_controller_spec.rb
@@ -0,0 +1,42 @@
+RSpec.describe Api::V1::Internals::NetexImportsController, type: :controller do
+ let(:import_1) { create :netex_import }
+ let(:import_2) { create :netex_import }
+
+ describe "GET #notify_parent" do
+ context 'unauthenticated' do
+ include_context 'iboo wrong authorisation internal api'
+
+ it 'should not be successful' do
+ get :notify_parent, id: import_1.id, format: :json
+ expect(response).to have_http_status 401
+ end
+ end
+
+ context 'authenticated' do
+ include_context 'iboo authenticated internal api'
+
+ describe "with existing record" do
+
+ before(:each) do
+ get :notify_parent, id: import_2.id, format: :json
+ end
+
+ it 'should be successful' do
+ expect(response).to have_http_status 200
+ end
+
+ it "calls #notify_parent on the import" do
+ expect(import_2.reload.notified_parent_at).not_to be_nil
+ end
+ end
+
+ describe "with non existing record" do
+ it "should throw an error" do
+ get :notify_parent, id: 47, format: :json
+ expect(response.body).to include("error")
+ end
+ end
+ end
+ end
+end
+
diff --git a/spec/controllers/compliance_check_sets_controller_spec.rb b/spec/controllers/compliance_check_sets_controller_spec.rb
deleted file mode 100644
index 3ddb1dad1..000000000
--- a/spec/controllers/compliance_check_sets_controller_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require 'rails_helper'
-
-RSpec.describe ComplianceCheckSetsController, type: :controller do
- login_user
-
- let(:compliance_check_set) { create :compliance_check_set }
-
- describe "GET executed" do
- it 'should be successful' do
- get :executed, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id
- expect(response).to be_success
- end
- end
-
- describe "GET index" do
- it 'should be successful' do
- get :index, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id
- expect(response).to be_success
- end
- end
-
-end
diff --git a/spec/support/shared_context.rb b/spec/support/shared_context.rb
index e9b0025a2..5e472eb85 100644
--- a/spec/support/shared_context.rb
+++ b/spec/support/shared_context.rb
@@ -13,3 +13,19 @@ shared_context 'iboo wrong authorisation api user' do
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('fake code', api_key.token)
end
end
+
+shared_context 'iboo authenticated internal api' do
+ let(:api_key) { Rails.application.secrets.api_token }
+
+ before do
+ request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(api_key)
+ end
+end
+
+shared_context 'iboo wrong authorisation internal api' do
+ let(:api_key) { "false_api_token" }
+
+ before do
+ request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(api_key)
+ end
+end