diff --git a/db/seeds.rb b/db/seeds.rb index 00a949eebc3..e7c6a8cadc4 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -38,6 +38,7 @@ def seed call_and_log_seed_step Seeds::Annotations call_and_log_seed_step Seeds::Tags # These must be ran before others + call_and_log_seed_step Seeds::BusinessLineOrg call_and_log_seed_step Seeds::Users call_and_log_seed_step Seeds::NotificationEvents # End of required to exist dependencies diff --git a/db/seeds/businesss_line_org.rb b/db/seeds/businesss_line_org.rb new file mode 100644 index 00000000000..6037ba31fbb --- /dev/null +++ b/db/seeds/businesss_line_org.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# Veterans Health Administration related seeds +# require "/sanitized_json_seeds.rb" + +module Seeds + class BusinessLineOrg < Base + def seed! + create_business_lines + end + + private + def create_business_lines + Seeds::SanitizedJsonSeeds.new.business_line_seeds + end + end +end diff --git a/db/seeds/sanitized_business_line_json/business_line.json b/db/seeds/sanitized_business_line_json/business_line.json new file mode 100644 index 00000000000..8f9e1c18848 --- /dev/null +++ b/db/seeds/sanitized_business_line_json/business_line.json @@ -0,0 +1,139 @@ +{ + "organizations": [ + { + "id": 219, + "type": "BusinessLine", + "name": "Education", + "role": null, + "url": "education", + "participant_id": null, + "created_at": null, + "updated_at": null, + "status": "active", + "status_updated_at": null, + "accepts_priority_pushed_cases": null, + "ama_only_push": false, + "ama_only_request": false + }, + { + "id": 220, + "type": "BusinessLine", + "name": "Veterans Readiness and Employment", + "role": null, + "url": "voc_rehab", + "participant_id": null, + "created_at": null, + "updated_at": null, + "status": "active", + "status_updated_at": null, + "accepts_priority_pushed_cases": null, + "ama_only_push": false, + "ama_only_request": false + }, + { + "id": 221, + "type": "BusinessLine", + "name": "Loan Guaranty", + "role": null, + "url": "loan_guaranty", + "participant_id": null, + "created_at": null, + "updated_at": null, + "status": "active", + "status_updated_at": null, + "accepts_priority_pushed_cases": null, + "ama_only_push": false, + "ama_only_request": false + }, + { + "id": 222, + "type": "BusinessLine", + "name": "Veterans Health Administration", + "role": null, + "url": "vha", + "participant_id": null, + "created_at": null, + "updated_at": null, + "status": "active", + "status_updated_at": null, + "accepts_priority_pushed_cases": null, + "ama_only_push": false, + "ama_only_request": false + }, + { + "id": 590, + "type": "BusinessLine", + "name": "Pension & Survivor's Benefits", + "role": null, + "url": "pension", + "participant_id": null, + "created_at": null, + "updated_at": null, + "status": "active", + "status_updated_at": null, + "accepts_priority_pushed_cases": null, + "ama_only_push": false, + "ama_only_request": false + }, + { + "id": 591, + "type": "BusinessLine", + "name": "Fiduciary", + "role": null, + "url": "fiduciary", + "participant_id": null, + "created_at": null, + "updated_at": null, + "status": "active", + "status_updated_at": null, + "accepts_priority_pushed_cases": null, + "ama_only_push": false, + "ama_only_request": false + }, + { + "id": 592, + "type": "BusinessLine", + "name": "Compensation", + "role": null, + "url": "compensation", + "participant_id": null, + "created_at": null, + "updated_at": null, + "status": "active", + "status_updated_at": null, + "accepts_priority_pushed_cases": null, + "ama_only_push": false, + "ama_only_request": false + }, + { + "id": 593, + "type": "BusinessLine", + "name": "Insurance", + "role": null, + "url": "insurance", + "participant_id": null, + "created_at": null, + "updated_at": null, + "status": "active", + "status_updated_at": null, + "accepts_priority_pushed_cases": null, + "ama_only_push": false, + "ama_only_request": false + }, + { + "id": 11, + "type": "BusinessLine", + "name": "National Cemetery Administration", + "role": null, + "url": "nca", + "participant_id": null, + "created_at": null, + "updated_at": null, + "status": "active", + "status_updated_at": null, + "accepts_priority_pushed_cases": null, + "ama_only_push": false, + "ama_only_request": false + } + ] +} diff --git a/db/seeds/sanitized_json_seeds.rb b/db/seeds/sanitized_json_seeds.rb index ff50f73e5dc..5ce86e8cdd3 100644 --- a/db/seeds/sanitized_json_seeds.rb +++ b/db/seeds/sanitized_json_seeds.rb @@ -15,13 +15,20 @@ def seed! import_json_seed_data end + def business_line_seeds + import_json("db/seeds/sanitized_business_line_json/business_line.json") + end + private def import_json_seed_data # appeal_ready_for_substitution_3.json requires this to exist FactoryBot.create(:higher_level_review, id: 2_000_050_893) + import_json("db/seeds/sanitized_json/*.json") + end - Dir.glob("db/seeds/sanitized_json/*.json").each do |json_seed| + def import_json(file_path) + Dir.glob(file_path).each do |json_seed| sji = SanitizedJsonImporter.from_file(json_seed, verbosity: 0) sji.import end diff --git a/db/seeds/users.rb b/db/seeds/users.rb index 05b43804ff8..fb3687a78a4 100644 --- a/db/seeds/users.rb +++ b/db/seeds/users.rb @@ -69,7 +69,6 @@ def create_users BvaIntake.singleton.add_user(bva_intake_user) Functions.grant!("System Admin", users: User.all.pluck(:css_id)) - create_team_admin create_colocated_users create_transcription_team @@ -282,7 +281,7 @@ def create_field_vso_and_users end def create_org_queue_users - nca = BusinessLine.create!(name: "National Cemetery Administration", url: "nca") + nca = BusinessLine.find_or_create_by!(name: "National Cemetery Administration", url: "nca") %w[Parveen Chandra Sydney Tai Kennedy].each do |name| u = User.create!(station_id: 101, css_id: "NCA_QUEUE_USER_#{name}", full_name: "#{name} NCAUser Carter") nca.add_user(u) diff --git a/spec/seeds/business_line_org_spec.rb b/spec/seeds/business_line_org_spec.rb new file mode 100644 index 00000000000..c8e6b214238 --- /dev/null +++ b/spec/seeds/business_line_org_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +describe Seeds::BusinessLineOrg do + describe "#seeds!" do + subject { described_class.new.seed! } + let(:sji1) { instance_double(SanitizedJsonImporter) } + + it "reads json file from specific directory" do + expect(subject).to eq ["db/seeds/sanitized_business_line_json/business_line.json"] + end + + it "creates business line organizations" do + expect { subject }.to_not raise_error + expect(BusinessLine.count).to eq 9 + end + + it "invokes SanitizedJsonImporter for each matching file" do + expect(Dir).to receive(:glob).with("db/seeds/sanitized_business_line_json/business_line.json") + .and_return(%w[business_line.json]) + + expect(SanitizedJsonImporter).to receive(:from_file) + .with("business_line.json", verbosity: 0).and_return(sji1) + expect(sji1).to receive(:import) + + subject + end + end +end