|
|
|
|
@ -6,6 +6,8 @@ RSpec.describe OrganisationsController, type: :request do
|
|
|
|
|
let(:headers) { { "Accept" => "text/html" } } |
|
|
|
|
let(:page) { Capybara::Node::Simple.new(response.body) } |
|
|
|
|
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
|
|
|
|
let(:new_value) { "Test Name 35" } |
|
|
|
|
let(:params) { { id: organisation.id, organisation: { name: new_value } } } |
|
|
|
|
|
|
|
|
|
context "a not signed in user" do |
|
|
|
|
describe "#show" do |
|
|
|
|
@ -74,6 +76,11 @@ RSpec.describe OrganisationsController, type: :request do
|
|
|
|
|
expected_html = "<h2 class=\"govuk-visually-hidden\"> Details" |
|
|
|
|
expect(response.body).to include(expected_html) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "has a change details link" do |
|
|
|
|
expected_html = "data-qa=\"change-name\" href=\"/organisations/#{organisation.id}/edit\"" |
|
|
|
|
expect(response.body).to include(expected_html) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "organisation that are not in scope for the user, i.e. that they do not belong to" do |
|
|
|
|
@ -127,6 +134,66 @@ RSpec.describe OrganisationsController, type: :request do
|
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "#edit" do |
|
|
|
|
context "organisation that the user belongs to" do |
|
|
|
|
before do |
|
|
|
|
sign_in user |
|
|
|
|
get "/organisations/#{organisation.id}/edit", headers: headers, params: {} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "shows an edit form" do |
|
|
|
|
expect(response.body).to include("Change #{organisation.name}'s details") |
|
|
|
|
expect(page).to have_field("organisation-name-field") |
|
|
|
|
expect(page).to have_field("organisation-phone-field") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "organisation that the user does not belong to" do |
|
|
|
|
before do |
|
|
|
|
sign_in user |
|
|
|
|
get "/organisations/#{unauthorised_organisation.id}/edit", headers: headers, params: {} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "returns a 404 not found" do |
|
|
|
|
expect(response).to have_http_status(:not_found) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "#update" do |
|
|
|
|
context "organisation that the user belongs to" do |
|
|
|
|
before do |
|
|
|
|
sign_in user |
|
|
|
|
patch "/organisations/#{organisation.id}", headers: headers, params: params |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "updates the org" do |
|
|
|
|
organisation.reload |
|
|
|
|
expect(organisation.name).to eq(new_value) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "redirects to the organisation details page" do |
|
|
|
|
expect(response).to redirect_to("/organisations/#{organisation.id}/details") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "shows a success banner" do |
|
|
|
|
follow_redirect! |
|
|
|
|
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "organisation that the user does not belong to" do |
|
|
|
|
before do |
|
|
|
|
sign_in user |
|
|
|
|
patch "/organisations/#{unauthorised_organisation.id}", headers: headers, params: {} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "returns a 404 not found" do |
|
|
|
|
expect(response).to have_http_status(:not_found) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "As a data provider user" do |
|
|
|
|
@ -154,6 +221,11 @@ RSpec.describe OrganisationsController, type: :request do
|
|
|
|
|
expected_html = "<h2 class=\"govuk-visually-hidden\"> Details" |
|
|
|
|
expect(response.body).to include(expected_html) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not have a change details link" do |
|
|
|
|
expected_html = "data-qa=\"change-name\" href=\"/organisations/#{organisation.id}/edit\"" |
|
|
|
|
expect(response.body).not_to include(expected_html) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "organisation that are not in scope for the user, i.e. that they do not belong to" do |
|
|
|
|
@ -178,6 +250,28 @@ RSpec.describe OrganisationsController, type: :request do
|
|
|
|
|
expect(response).to have_http_status(:unauthorized) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "#edit" do |
|
|
|
|
before do |
|
|
|
|
sign_in user |
|
|
|
|
get "/organisations/#{organisation.id}/edit", headers: headers, params: {} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "redirects to home" do |
|
|
|
|
expect(response).to have_http_status(:unauthorized) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "#update" do |
|
|
|
|
before do |
|
|
|
|
sign_in user |
|
|
|
|
patch "/organisations/#{organisation.id}", headers: headers, params: params |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "redirects to home" do |
|
|
|
|
expect(response).to have_http_status(:unauthorized) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|