-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GL-367: Add Admin UI screen to list the overrides (#705)
GL-457: Add admin UI to create new overrides GL-367: Add Admin UI screen to list the overrides GL-458: Add admin UI to remove overrides (#706)
- Loading branch information
Showing
9 changed files
with
240 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
app/controllers/green_lanes/exempting_certificate_overrides_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module GreenLanes | ||
class ExemptingCertificateOverridesController < AuthenticatedController | ||
before_action :disable_service_switching! | ||
before_action :check_service | ||
def index | ||
@exempting_certificate_overrides = GreenLanes::ExemptingCertificateOverride.all(page: current_page).fetch | ||
end | ||
|
||
def new | ||
@exempting_certificate_override = GreenLanes::ExemptingCertificateOverride.new | ||
end | ||
|
||
def create | ||
@exempting_certificate_override = GreenLanes::ExemptingCertificateOverride.new(eco_params) | ||
|
||
if @exempting_certificate_override.valid? && @exempting_certificate_override.save | ||
redirect_to green_lanes_exempting_certificate_overrides_path, notice: 'Exempting Certificate Override created' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def destroy | ||
@exempting_certificate_override = GreenLanes::ExemptingCertificateOverride.find(params[:id]) | ||
@exempting_certificate_override.destroy | ||
|
||
redirect_to green_lanes_exempting_certificate_overrides_path, notice: 'Exempting Certificate Override removed' | ||
end | ||
|
||
private | ||
|
||
def eco_params | ||
params.require(:exempting_certificate_override).permit( | ||
:certificate_type_code, | ||
:certificate_code, | ||
) | ||
end | ||
|
||
def check_service | ||
if TradeTariffAdmin::ServiceChooser.uk? | ||
raise ActionController::RoutingError, 'Invalid service' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module GreenLanes | ||
class ExemptingCertificateOverride | ||
include Her::JsonApi::Model | ||
use_api Her::XI_API | ||
extend HerPaginatable | ||
|
||
attributes :certificate_type_code, | ||
:certificate_code, | ||
:created_at, | ||
:updated_at | ||
|
||
collection_path '/admin/green_lanes/exempting_certificate_overrides' | ||
end | ||
end |
40 changes: 40 additions & 0 deletions
40
app/views/green_lanes/exempting_certificate_overrides/index.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<h2> | ||
Manage exempting certificate overrides | ||
</h2> | ||
|
||
<%= link_to 'Add a Exempting Certificate Override', new_green_lanes_exempting_certificate_override_path, class: 'govuk-button' %> | ||
|
||
<% if @exempting_certificate_overrides.any? %> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>ID</th> | ||
<th>Certificate Type Code</th> | ||
<th>Certificate Code</th> | ||
<th>Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @exempting_certificate_overrides.each do |eco| %> | ||
<tr id="<%= dom_id(eco) %>"> | ||
<td><%= eco.id %></td> | ||
<td><%= eco.certificate_type_code %></td> | ||
<td><%= eco.certificate_code %></td> | ||
<td> | ||
<%= link_to 'Remove', | ||
green_lanes_exempting_certificate_override_path(eco), | ||
method: :delete, | ||
class: 'govuk-button govuk-button--warning', | ||
data: { confirm: "Are you sure?", disable: 'Working ...' } %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<%= paginate @exempting_certificate_overrides %> | ||
<% else %> | ||
<div class="govuk-inset-text"> | ||
<p>No Exempting Certificate Override</p> | ||
</div> | ||
<% end %> |
16 changes: 16 additions & 0 deletions
16
app/views/green_lanes/exempting_certificate_overrides/new.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%= govuk_breadcrumbs 'Exempting Certificate Override': green_lanes_exempting_certificate_overrides_path %> | ||
|
||
<h2>New Exempting Certificate Override</h2> | ||
|
||
<%= govuk_form_for @exempting_certificate_override, as: :exempting_certificate_override do |f| %> | ||
|
||
<%= f.govuk_text_field :certificate_type_code, | ||
label: { text: 'Certificate Type Code' }, | ||
width: 'one-half' %> | ||
|
||
<%= f.govuk_text_field :certificate_code, | ||
label: { text: 'Certificate Code' }, | ||
width: 'one-half' %> | ||
|
||
<%= submit_and_back_buttons f, green_lanes_exempting_certificate_overrides_path %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
spec/factories/green_lanes/exempting_certificate_override_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryBot.define do | ||
factory :exempting_certificate_override, class: 'GreenLanes::ExemptingCertificateOverride' do | ||
sequence(:id) { |n| n } | ||
certificate_type_code { 'Y' } | ||
certificate_code { '435' } | ||
created_at { 2.days.ago.to_date } | ||
updated_at { nil } | ||
end | ||
end |
41 changes: 41 additions & 0 deletions
41
spec/models/green_lanes/exempting_certificate_override_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe GreenLanes::ExemptingCertificateOverride do | ||
subject(:exempting_certificate_override) { build :exempting_certificate_override } | ||
|
||
it { is_expected.to respond_to :id } | ||
it { is_expected.to respond_to :certificate_type_code } | ||
it { is_expected.to respond_to :certificate_code } | ||
it { is_expected.to respond_to :created_at } | ||
it { is_expected.to respond_to :updated_at } | ||
|
||
it { is_expected.to have_attributes id: exempting_certificate_override.id } | ||
it { is_expected.to have_attributes certificate_type_code: exempting_certificate_override.certificate_type_code } | ||
it { is_expected.to have_attributes certificate_code: exempting_certificate_override.certificate_code } | ||
it { is_expected.to have_attributes created_at: exempting_certificate_override.created_at } | ||
it { is_expected.to have_attributes updated_at: exempting_certificate_override.updated_at } | ||
|
||
describe '#all' do | ||
subject { described_class.all } | ||
|
||
before do | ||
allow(TradeTariffAdmin::ServiceChooser).to \ | ||
receive(:service_choice).and_return service_choice | ||
|
||
stub_api_request('/admin/green_lanes/exempting_certificate_overrides', backend: 'xi').to_return \ | ||
jsonapi_response(:exempting_certificate_override, attributes_for_list(:exempting_certificate_override, 2)) | ||
end | ||
|
||
context 'with UK service' do | ||
let(:service_choice) { 'uk' } | ||
|
||
it { is_expected.to have_attributes length: 2 } | ||
end | ||
|
||
context 'with XI service' do | ||
let(:service_choice) { 'xi' } | ||
|
||
it { is_expected.to have_attributes length: 2 } | ||
end | ||
end | ||
end |
70 changes: 70 additions & 0 deletions
70
spec/requests/green_lanes/exempting_certificate_overrides_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
RSpec.describe GreenLanes::ExemptingCertificateOverridesController do | ||
subject(:rendered_page) { create_user && make_request && response } | ||
|
||
let(:exempting_certificate_override) { build :exempting_certificate_override } | ||
let(:create_user) { create :user, permissions: ['signin', 'HMRC Editor'] } | ||
|
||
before do | ||
allow(TradeTariffAdmin::ServiceChooser).to receive(:service_choice).and_return 'xi' | ||
end | ||
|
||
describe 'GET #index' do | ||
before do | ||
stub_api_request('/admin/green_lanes/exempting_certificate_overrides?page=1', backend: 'xi').and_return \ | ||
jsonapi_response :exempting_certificate_overrides, attributes_for_list(:exempting_certificate_override, 3) | ||
end | ||
|
||
let(:make_request) { get green_lanes_exempting_certificate_overrides_path } | ||
|
||
it { is_expected.to have_http_status :success } | ||
it { is_expected.not_to include 'div.current-service' } | ||
end | ||
|
||
describe 'GET #new' do | ||
let(:make_request) { get new_green_lanes_exempting_certificate_override_path } | ||
|
||
it { is_expected.to have_http_status :ok } | ||
it { is_expected.not_to include 'div.current-service' } | ||
end | ||
|
||
describe 'POST #create' do | ||
before do | ||
stub_api_request('/admin/green_lanes/exempting_certificate_overrides', :post).to_return create_response | ||
end | ||
|
||
let :make_request do | ||
post green_lanes_exempting_certificate_overrides_path, | ||
params: { exempting_certificate_override: eco_params } | ||
end | ||
|
||
context 'with valid item' do | ||
let(:eco_params) { exempting_certificate_override.attributes.without(:id) } | ||
let(:create_response) { webmock_response(:created, exempting_certificate_override.attributes) } | ||
|
||
it { is_expected.to redirect_to green_lanes_exempting_certificate_overrides_path } | ||
end | ||
|
||
context 'with invalid item' do | ||
let(:eco_params) { exempting_certificate_override.attributes.without(:id, :certificate_type_code) } | ||
let(:create_response) { webmock_response(:error, certificate_type_code: "can't be blank'") } | ||
|
||
it { is_expected.to have_http_status :ok } | ||
it { is_expected.to have_attributes body: /can.+t be blank/ } | ||
it { is_expected.not_to include 'div.current-service' } | ||
end | ||
end | ||
|
||
describe 'DELETE #destroy' do | ||
before do | ||
stub_api_request("/admin/green_lanes/exempting_certificate_overrides/#{exempting_certificate_override.id}") | ||
.and_return jsonapi_response(:exempting_certificate_override, exempting_certificate_override.attributes) | ||
|
||
stub_api_request("/admin/green_lanes/exempting_certificate_overrides/#{exempting_certificate_override.id}", :delete) | ||
.and_return webmock_response :no_content | ||
end | ||
|
||
let(:make_request) { delete green_lanes_exempting_certificate_override_path(exempting_certificate_override) } | ||
|
||
it { is_expected.to redirect_to green_lanes_exempting_certificate_overrides_path } | ||
end | ||
end |