|
1 | 1 | describe AppropriateBodies::Importers::AppropriateBodyImporter do |
2 | | - let!(:ab_1) { FactoryBot.create(:appropriate_body, legacy_id: '025e61e7-ec32-eb11-a813-000d3a228dfc') } |
3 | | - let!(:ab_2) { FactoryBot.create(:appropriate_body, legacy_id: '1ddf3e82-c1ae-e311-b8ed-005056822391') } |
| 2 | + subject { AppropriateBodies::Importers::AppropriateBodyImporter.new(nil, wanted_legacy_ids, nil, csv: sample_appropriate_body_csv, dfe_sign_in_mapping_csv: sample_mapping_csv) } |
| 3 | + |
| 4 | + let!(:ab_1) { FactoryBot.create(:appropriate_body, dqt_id: "025e61e7-ec32-eb11-a813-000d3a228dfc") } |
| 5 | + let!(:ab_2) { FactoryBot.create(:appropriate_body, dqt_id: "1ddf3e82-c1ae-e311-b8ed-005056822391") } |
4 | 6 |
|
5 | | - let(:wanted_legacy_ids) { [ab_1.legacy_id, ab_2.legacy_id] } |
| 7 | + let(:wanted_legacy_ids) { [ab_1.dqt_id, ab_2.dqt_id] } |
6 | 8 |
|
7 | 9 | let(:sample_appropriate_body_data) do |
8 | 10 | <<~CSV |
9 | 11 | id,name,dfe_sign_in_organisation_id,local_authority_code,establishment_number |
10 | | - #{ab_1.legacy_id},Testington Primary School,1234568,123/4567, |
11 | | - #{ab_2.legacy_id},Sampleville Primary School,23456789,987/6543, |
| 12 | + #{ab_1.dqt_id},Testington Primary School,1234568,123/4567, |
| 13 | + #{ab_2.dqt_id},Sampleville Primary School,23456789,987/6543, |
12 | 14 | CSV |
13 | 15 | end |
14 | 16 |
|
|
23 | 25 |
|
24 | 26 | let(:sample_mapping_csv) { CSV.parse(sample_mapping_data, headers: true) } |
25 | 27 |
|
26 | | - subject { AppropriateBodies::Importers::AppropriateBodyImporter.new(nil, wanted_legacy_ids, nil, csv: sample_appropriate_body_csv, dfe_sign_in_mapping_csv: sample_mapping_csv) } |
27 | | - |
28 | | - it 'converts the csv row to Row objects when initialized' do |
| 28 | + it "converts the csv row to Row objects when initialized" do |
29 | 29 | expect(subject.rows).to all(be_a(AppropriateBodies::Importers::AppropriateBodyImporter::Row)) |
30 | 30 | end |
31 | 31 |
|
32 | | - describe 'setting the local authority code and establishment number' do |
33 | | - context 'when the format is DDD' do |
| 32 | + describe "setting the local authority code and establishment number" do |
| 33 | + context "when the format is DDD" do |
34 | 34 | let(:sample_appropriate_body_data) do |
35 | 35 | <<~CSV |
36 | 36 | id,name,dfe_sign_in_organisation_id,local_authority_code,establishment_number |
37 | | - #{ab_1.legacy_id},Chesterton Primary School,1234568,123 |
| 37 | + #{ab_1.dqt_id},Chesterton Primary School,1234568,123 |
38 | 38 | CSV |
39 | 39 | end |
40 | 40 |
|
41 | | - it 'sets the local4 authority code to 123' do |
| 41 | + it "sets the local4 authority code to 123" do |
42 | 42 | expect(subject.rows[0].local_authority_code).to eql(123) |
43 | 43 | end |
44 | 44 | end |
45 | 45 |
|
46 | | - context 'when the format is DDDD' do |
| 46 | + context "when the format is DDDD" do |
47 | 47 | let(:sample_appropriate_body_data) do |
48 | 48 | <<~CSV |
49 | 49 | id,name,dfe_sign_in_organisation_id,local_authority_code,establishment_number |
50 | | - #{ab_1.legacy_id},Chesterton Primary School,1234568,1234 |
| 50 | + #{ab_1.dqt_id},Chesterton Primary School,1234568,1234 |
51 | 51 | CSV |
52 | 52 | end |
53 | 53 |
|
54 | | - it 'sets the establishment number to 1234' do |
| 54 | + it "sets the establishment number to 1234" do |
55 | 55 | expect(subject.rows[0].establishment_number).to eql(1234) |
56 | 56 | end |
57 | 57 | end |
58 | 58 |
|
59 | | - context 'when the appropriate body legacy_id is in the list of wanted_legacy_ids' do |
60 | | - it 'parses and builds the rows' do |
| 59 | + context "when the appropriate body legacy_id is in the list of wanted_legacy_ids" do |
| 60 | + it "parses and builds the rows" do |
61 | 61 | expect(subject.rows.map(&:legacy_id)).to match_array(wanted_legacy_ids) |
62 | 62 | end |
63 | 63 | end |
64 | 64 |
|
65 | | - context 'when the appropriate body legacy_id is not in the list of wanted_legacy_ids' do |
66 | | - let(:wanted_legacy_ids) { [ab_1.legacy_id] } |
| 65 | + context "when the appropriate body legacy_id is not in the list of wanted_legacy_ids" do |
| 66 | + let(:wanted_legacy_ids) { [ab_1.dqt_id] } |
67 | 67 |
|
68 | | - it 'omits the unwanted rows' do |
| 68 | + it "omits the unwanted rows" do |
69 | 69 | parsed_legacy_ids = subject.rows.map(&:legacy_id) |
70 | 70 |
|
71 | | - expect(parsed_legacy_ids).to include(ab_1.legacy_id) |
72 | | - expect(parsed_legacy_ids).not_to include(ab_2.legacy_id) |
| 71 | + expect(parsed_legacy_ids).to include(ab_1.dqt_id) |
| 72 | + expect(parsed_legacy_ids).not_to include(ab_2.dqt_id) |
73 | 73 | end |
74 | 74 | end |
75 | 75 |
|
76 | | - context 'when the format is DDDD/DDD' do |
| 76 | + context "when the format is DDDD/DDD" do |
77 | 77 | let(:sample_appropriate_body_data) do |
78 | 78 | <<~CSV |
79 | 79 | id,name,dfe_sign_in_organisation_id,local_authority_code,establishment_number |
80 | | - #{ab_1.legacy_id},Chesterton Primary School,1234568,567/1234 |
| 80 | + #{ab_1.dqt_id},Chesterton Primary School,1234568,567/1234 |
81 | 81 | CSV |
82 | 82 | end |
83 | 83 |
|
84 | | - it 'sets the establishment number to 1234' do |
| 84 | + it "sets the establishment number to 1234" do |
85 | 85 | expect(subject.rows[0].establishment_number).to eql(1234) |
86 | 86 | end |
87 | 87 |
|
88 | | - it 'sets the local authority code to 567' do |
| 88 | + it "sets the local authority code to 567" do |
89 | 89 | expect(subject.rows[0].local_authority_code).to eql(567) |
90 | 90 | end |
91 | 91 | end |
92 | 92 |
|
93 | | - context 'when the format is DDDDDDD' do |
| 93 | + context "when the format is DDDDDDD" do |
94 | 94 | let(:sample_appropriate_body_data) do |
95 | 95 | <<~CSV |
96 | 96 | id,name,dfe_sign_in_organisation_id,local_authority_code,establishment_number |
97 | | - #{ab_1.legacy_id},Chesterton Primary School,1234568,5671234 |
| 97 | + #{ab_1.dqt_id},Chesterton Primary School,1234568,5671234 |
98 | 98 | CSV |
99 | 99 | end |
100 | 100 |
|
101 | | - it 'sets the establishment number to 1234' do |
| 101 | + it "sets the establishment number to 1234" do |
102 | 102 | expect(subject.rows[0].establishment_number).to eql(1234) |
103 | 103 | end |
104 | 104 |
|
105 | | - it 'sets the local authority code to 567' do |
| 105 | + it "sets the local authority code to 567" do |
106 | 106 | expect(subject.rows[0].local_authority_code).to eql(567) |
107 | 107 | end |
108 | 108 | end |
109 | 109 | end |
110 | 110 |
|
111 | | - describe 'setting the name' do |
112 | | - context 'when there is no mapping in place' do |
113 | | - it 'sets the appropriate body name to the name field from the appropriate bodies csv' do |
114 | | - expect(subject.rows.map(&:name)).to match_array(['Testington Primary School', 'Sampleville Primary School']) |
| 111 | + describe "setting the name" do |
| 112 | + context "when there is no mapping in place" do |
| 113 | + it "sets the appropriate body name to the name field from the appropriate bodies csv" do |
| 114 | + expect(subject.rows.map(&:name)).to contain_exactly("Testington Primary School", "Sampleville Primary School") |
115 | 115 | end |
116 | 116 | end |
117 | 117 |
|
118 | | - context 'when there is a mapping in place' do |
| 118 | + context "when there is a mapping in place" do |
119 | 119 | let(:sample_mapping_data) do |
120 | 120 | <<~CSV |
121 | 121 | appropriate_body_name,lead_school_name,dfe_sign_in_organisation_id,dqt_id |
122 | | - Test TSH,Test Lead School,203606a4-4199-46a9-84e4-56fbc5da2a36,#{ab_1.legacy_id} |
| 122 | + Test TSH,Test Lead School,203606a4-4199-46a9-84e4-56fbc5da2a36,#{ab_1.dqt_id} |
123 | 123 | CSV |
124 | 124 | end |
125 | 125 |
|
126 | | - it 'sets the appropriate body name to the appropriate body name field from the mapping bodies csv' do |
127 | | - expect(subject.rows.map(&:name)).to match_array(['Test TSH', 'Sampleville Primary School']) |
| 126 | + it "sets the appropriate body name to the appropriate body name field from the mapping bodies csv" do |
| 127 | + expect(subject.rows.map(&:name)).to contain_exactly("Test TSH", "Sampleville Primary School") |
128 | 128 | end |
129 | 129 | end |
130 | 130 | end |
131 | 131 |
|
132 | | - describe 'setting the DfE Sign-in ID' do |
133 | | - context 'when there is no mapping in place' do |
134 | | - it 'sets the DfE Sign-in ID to nil' do |
| 132 | + describe "setting the DfE Sign-in ID" do |
| 133 | + context "when there is no mapping in place" do |
| 134 | + it "sets the DfE Sign-in ID to nil" do |
135 | 135 | expect(subject.rows.map(&:dfe_sign_in_organisation_id)).to all(be_nil) |
136 | 136 | end |
137 | 137 | end |
138 | 138 |
|
139 | | - context 'when there is a mapping in place' do |
| 139 | + context "when there is a mapping in place" do |
140 | 140 | let(:dfe_sign_in_organisation_id) { SecureRandom.uuid } |
141 | 141 |
|
142 | 142 | let(:sample_mapping_data) do |
143 | 143 | <<~CSV |
144 | 144 | appropriate_body_name,lead_school_name,dfe_sign_in_organisation_id,dqt_id |
145 | | - Test TSH,Test Lead School,#{dfe_sign_in_organisation_id},#{ab_1.legacy_id} |
| 145 | + Test TSH,Test Lead School,#{dfe_sign_in_organisation_id},#{ab_1.dqt_id} |
146 | 146 | CSV |
147 | 147 | end |
148 | 148 |
|
149 | | - it 'sets the DfE Sign-in ID to the value from the mappings CSV' do |
150 | | - ab_1_row = subject.rows.find { |r| r.legacy_id == ab_1.legacy_id } |
| 149 | + it "sets the DfE Sign-in ID to the value from the mappings CSV" do |
| 150 | + ab_1_row = subject.rows.find { |r| r.legacy_id == ab_1.dqt_id } |
151 | 151 |
|
152 | 152 | expect(ab_1_row.dfe_sign_in_organisation_id).to eql(dfe_sign_in_organisation_id) |
153 | 153 | end |
154 | 154 |
|
155 | | - it 'is nil when there is no mapping' do |
156 | | - ab_2_row = subject.rows.find { |r| r.legacy_id == ab_2.legacy_id } |
| 155 | + it "is nil when there is no mapping" do |
| 156 | + ab_2_row = subject.rows.find { |r| r.legacy_id == ab_2.dqt_id } |
157 | 157 |
|
158 | 158 | expect(ab_2_row.dfe_sign_in_organisation_id).to be_nil |
159 | 159 | end |
|
0 commit comments