baarkerlounger
3 years ago
committed by
GitHub
14 changed files with 15 additions and 233 deletions
@ -1,5 +0,0 @@
|
||||
class LocalAuthority |
||||
def self.ons_code_mappings |
||||
FormHandler.instance.current_form.get_question("la", nil).answer_options |
||||
end |
||||
end |
@ -1,3 +0,0 @@
|
||||
class OrganisationLa < ApplicationRecord |
||||
belongs_to :organisation |
||||
end |
@ -1,23 +0,0 @@
|
||||
module Imports |
||||
class OrganisationLaImportService < ImportService |
||||
def create_organisation_las(folder) |
||||
import_from(folder, :create_organisation_la) |
||||
end |
||||
|
||||
private |
||||
|
||||
def create_organisation_la(xml_document) |
||||
xml_document.remove_namespaces! |
||||
organisation = Organisation.find_by(old_org_id: record_field_value(xml_document, "InstitutionId")) |
||||
|
||||
OrganisationLa.create!( |
||||
organisation:, |
||||
ons_code: record_field_value(xml_document, "ONSCode"), |
||||
) |
||||
end |
||||
|
||||
def record_field_value(xml_document, field) |
||||
xml_document.at_xpath("//#{field}")&.text |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,14 @@
|
||||
class DropOrganisationsLas < ActiveRecord::Migration[7.0] |
||||
def up |
||||
drop_table :organisation_las |
||||
end |
||||
|
||||
def down |
||||
create_table :organisation_las do |t| |
||||
t.belongs_to :organisation |
||||
t.column :ons_code, :string |
||||
|
||||
t.timestamps |
||||
end |
||||
end |
||||
end |
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<institution xmlns="http://www.ons.gov.uk/institutions-and-ons-la"> |
||||
<InstitutionId>44026acc7ed5c29516b26f2a5deb639e5e37966d</InstitutionId> |
||||
<AssociationId>7076</AssociationId> |
||||
<ONSCode>E07000041</ONSCode> |
||||
</institution> |
@ -1,16 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe LocalAuthority, type: :model do |
||||
describe "ons code mapping" do |
||||
let(:form) { Form.new("spec/fixtures/forms/2021_2022.json", "2021_2022") } |
||||
|
||||
before do |
||||
allow(FormHandler.instance).to receive(:current_form).and_return(form) |
||||
end |
||||
|
||||
it "maps ONS code to local authority names" do |
||||
expect(described_class.ons_code_mappings).to be_a(Hash) |
||||
expect(described_class.ons_code_mappings["E07000178"]).to eq("Oxford") |
||||
end |
||||
end |
||||
end |
@ -1,42 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Imports::OrganisationLaImportService do |
||||
let(:fixture_directory) { "spec/fixtures/softwire_imports/organisation_las" } |
||||
let(:old_org_id) { "44026acc7ed5c29516b26f2a5deb639e5e37966d" } |
||||
let(:old_id) { "00013f30e159d7f72a3abe9ea93fb5b685d311e4" } |
||||
let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") } |
||||
let(:storage_service) { instance_double(StorageService) } |
||||
let(:logger) { instance_double(ActiveSupport::Logger) } |
||||
|
||||
context "when importing organisation las" do |
||||
subject(:import_service) { described_class.new(storage_service, logger) } |
||||
|
||||
before do |
||||
allow(storage_service) |
||||
.to receive(:list_files) |
||||
.and_return(["organisation_la_directory/#{old_id}.xml"]) |
||||
allow(storage_service) |
||||
.to receive(:get_file_io) |
||||
.with("organisation_la_directory/#{old_id}.xml") |
||||
.and_return(import_file) |
||||
end |
||||
|
||||
context "when the organisation in the import file doesn't exist in the system" do |
||||
it "does not create an organisation la record" do |
||||
expect(logger).to receive(:error).with(/Organisation must exist/) |
||||
import_service.create_organisation_las("organisation_la_directory") |
||||
end |
||||
end |
||||
|
||||
context "when the organisation does exist" do |
||||
before do |
||||
FactoryBot.create(:organisation, old_org_id:) |
||||
end |
||||
|
||||
it "successfully create an organisation la record with the expected data" do |
||||
import_service.create_organisation_las("organisation_la_directory") |
||||
expect(Organisation.find_by(old_org_id:).organisation_las.pluck("ons_code")).to eq(%w[E07000041]) |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue