Skip to content

Commit

Permalink
Merge pull request #98 from mattrayner/cazwazacz-cazwazacz/webdev-865…
Browse files Browse the repository at this point in the history
…_create-procedure-step-work-packages

Cazwazacz cazwazacz/webdev 865 create procedure step work packages
  • Loading branch information
mattrayner committed Oct 25, 2018
2 parents 81eda91 + 189e17e commit 58fb466
Show file tree
Hide file tree
Showing 16 changed files with 27,231 additions and 1 deletion.
39 changes: 39 additions & 0 deletions app/controllers/procedure_steps/work_packages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module ProcedureSteps
class WorkPackagesController < ApplicationController
before_action :build_request, :data_check

ROUTE_MAP = {
index: proc { |params| ParliamentHelper.parliament_request.procedure_step_work_packages.set_url_params({ procedure_step_id: params[:procedure_step_id] }) }
}.freeze

def index
@procedure_step, @business_items = FilterHelper.filter(@api_request, 'ProcedureStep', 'BusinessItem')
@procedure_step = @procedure_step.first

@business_items = @business_items.sort_by(:date, :graph_id).reverse

list_components = @business_items.map do |business_item|
next nil unless business_item.work_package

list_description_items = nil
if business_item.date
list_description_items = [{ term: { content: 'procedure-steps.subsidiary-resources.actualised-date' }, description: [{ content: I18n.l(business_item.date) }] }]
end

CardFactory.new(
small: 'laid-thing.work-package',
heading_text: business_item.work_package.work_packaged_thing.try(:workPackagedThingName),
heading_url: work_package_path(business_item.work_package.graph_id),
description_list_content: list_description_items
).build_card
end
list_components.compact!

heading = ComponentSerializer::Heading1ComponentSerializer.new(heading_content: I18n.t('work_packages.title'), subheading_content: @procedure_step.try(:procedureStepName), subheading_link: procedure_step_path)

serializer = PageSerializer::ListPageSerializer.new(request: request, heading_component: heading, list_components: list_components, data_alternates: @alternates)

render_page(serializer)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def meta_info
houses = @procedure_step.try(:procedureStepHasHouse)
return if houses.nil? || houses.empty?

houses = houses.map { |house| house.try(:houseName) }.compact.join(' and ')
houses = houses.map { |house| house.try(:houseName) }.compact.to_sentence

[create_description_list_item('procedure-steps.houses', [houses])]
end
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ en:
procedure_steps:
index:
title: "Procedure Steps"
work_packages:
title: "Work Packages"
140 changes: 140 additions & 0 deletions spec/controllers/procedure_steps/work_packages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
require 'rails_helper'

RSpec.describe ProcedureSteps::WorkPackagesController, vcr: true do
describe 'GET index' do
let(:data_alternates) do
[{
href: "#{ENV['PARLIAMENT_BASE_URL']}/procedure_step_work_packages.nt?procedure_step_id=e9G2vHbc",
type: 'application/n-triples'
},
{href: "#{ENV['PARLIAMENT_BASE_URL']}/procedure_step_work_packages.ttl?procedure_step_id=e9G2vHbc",
type: 'text/turtle'},
{href: "#{ENV['PARLIAMENT_BASE_URL']}/procedure_step_work_packages.tsv?procedure_step_id=e9G2vHbc",
type: 'text/tab-separated-values'},
{href: "#{ENV['PARLIAMENT_BASE_URL']}/procedure_step_work_packages.csv?procedure_step_id=e9G2vHbc",
type: 'text/csv'},
{href: "#{ENV['PARLIAMENT_BASE_URL']}/procedure_step_work_packages.rj?procedure_step_id=e9G2vHbc",
type: 'application/json+rdf'},
{href: "#{ENV['PARLIAMENT_BASE_URL']}/procedure_step_work_packages.json?procedure_step_id=e9G2vHbc",
type: 'application/json+ld'},
{href: "#{ENV['PARLIAMENT_BASE_URL']}/procedure_step_work_packages.xml?procedure_step_id=e9G2vHbc",
type: 'application/rdf+xml'}]
end

let(:heading) {'a heading component'}

before(:each) do
allow(PageSerializer::ListPageSerializer).to receive(:new)
allow(ComponentSerializer::Heading1ComponentSerializer).to receive(:new) {heading}

allow(controller.request).to receive(:env).and_return({'ApplicationInsights.request.id' => '|1234abcd.'})

get :index, params: {procedure_step_id: 'e9G2vHbc'}
end

it 'should have a response with http status ok (200)' do
expect(response).to have_http_status(:ok)
end

context 'the correct instance variables' do
it 'assigns @procedure_step' do
expect(assigns(:procedure_step)).to be_a(Grom::Node)
expect(assigns(:procedure_step).type).to include('https://id.parliament.uk/schema/ProcedureStep')
end

it 'assigns @business_items' do
assigns(:business_items).each do |business_item|
expect(business_item).to be_a(Grom::Node)
expect(business_item.type).to include('https://id.parliament.uk/schema/BusinessItem')
end
end
end

context 'calling the serializers correctly' do
it 'calls the Heading1ComponentSerializer correctly' do
expect(ComponentSerializer::Heading1ComponentSerializer).to have_received(:new).with(heading_content: 'Work Packages', subheading_content: 'procedureStepName - 1', subheading_link: '/procedure-steps/e9G2vHbc')
end

it 'calls the ListPageSerializer correctly' do
list_components = [{"data" =>
{"heading" =>
{"data" =>
{"content" => "workPackagedThingName - 4",
"link" => "/work-packages/eCsYdAM3",
"size" => 2},
"name" => "heading"},
"list-description" =>
{"data" =>
{"items" =>
[{"description" => [{"content" => "16 May 2018"}],
"term" =>
{"content" =>
"procedure-steps.subsidiary-resources.actualised-date"}}]},
"name" => "list__description"},
"small" =>
{"data" => {"content" => "laid-thing.work-package"},
"name" => "partials__small"}},
"name" => "card__generic"},
{"data" =>
{"heading" =>
{"data" =>
{"content" => "workPackagedThingName - 2",
"link" => "/work-packages/PsB0pq0l",
"size" => 2},
"name" => "heading"},
"list-description" =>
{"data" =>
{"items" =>
[{"description" => [{"content" => "9 May 2018"}],
"term" =>
{"content" =>
"procedure-steps.subsidiary-resources.actualised-date"}}]},
"name" => "list__description"},
"small" =>
{"data" => {"content" => "laid-thing.work-package"},
"name" => "partials__small"}},
"name" => "card__generic"},
{"data" =>
{"heading" =>
{"data" =>
{"content" => "workPackagedThingName - 3",
"link" => "/work-packages/uBG5MdZZ",
"size" => 2},
"name" => "heading"},
"list-description" =>
{"data" =>
{"items" =>
[{"description" => [{"content" => "2 May 2018"}],
"term" =>
{"content" =>
"procedure-steps.subsidiary-resources.actualised-date"}}]},
"name" => "list__description"},
"small" =>
{"data" => {"content" => "laid-thing.work-package"},
"name" => "partials__small"}},
"name" => "card__generic"},
{"data" =>
{"heading" =>
{"data" =>
{"content" => "workPackagedThingName - 1",
"link" => "/work-packages/UsdZhECl",
"size" => 2},
"name" => "heading"},
"list-description" =>
{"data" =>
{"items" =>
[{"description" => [{"content" => "2 May 2018"}],
"term" =>
{"content" =>
"procedure-steps.subsidiary-resources.actualised-date"}}]},
"name" => "list__description"},
"small" =>
{"data" => {"content" => "laid-thing.work-package"},
"name" => "partials__small"}},
"name" => "card__generic"}]

expect(PageSerializer::ListPageSerializer).to have_received(:new).with(request: request, heading_component: heading, list_components: list_components, data_alternates: data_alternates)
end
end
end
end
Loading

0 comments on commit 58fb466

Please sign in to comment.