Skip to content

Commit 3fc6221

Browse files
authored
EDM-686/Improve code coverage for lcpe lac and exams model (#1318)
* Improve code coverage for lcpe lac and exams model * linting
1 parent 84faa60 commit 3fc6221

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

spec/factories/lcpe/exams.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
FactoryBot.define do
4+
factory :lcpe_exam, class: 'Lcpe::Exam' do
5+
facility_code { '57001151' }
6+
nexam_nm { 'AP-ADVANCED PLACEMENT EXAMS' }
7+
end
8+
end

spec/factories/lcpe/lacs.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
FactoryBot.define do
4+
factory :lcpe_lac, class: 'Lcpe::Lac' do
5+
facility_code
6+
edu_lac_type_nm { 'License' }
7+
lac_nm { 'Gas Fitter' }
8+
state { 'AR' }
9+
end
10+
end

spec/models/lcpe/exam_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe Lcpe::Exam, type: :model do
6+
let(:version) { create :version, :production }
7+
let(:institution) { create :institution, version_id: version.id }
8+
let(:facility_code) { institution.facility_code }
9+
10+
before { create :weam, facility_code: }
11+
12+
describe 'when validating' do
13+
it 'has a valid factory' do
14+
expect(build(:lcpe_exam, facility_code:)).to be_valid
15+
end
16+
end
17+
18+
describe '.with_enriched_id' do
19+
before { create :lcpe_exam, facility_code: }
20+
21+
it 'returns exams with ref_code and enriched_id attribute' do
22+
exam_enriched = described_class.with_enriched_id.first
23+
ref = generate_ref_code_from(exam_enriched)
24+
id = exam_enriched.id.to_s + '@' + ref
25+
expect(exam_enriched.ref_code).to eq(ref)
26+
expect(exam_enriched.enriched_id).to eq(id)
27+
end
28+
end
29+
30+
describe '.by_enriched_id' do
31+
subject(:exam) { create :lcpe_exam, facility_code: }
32+
33+
let(:ref_code) { generate_ref_code_from(exam) }
34+
let(:enriched_id) { exam.id.to_s + '@' + ref_code }
35+
36+
it 'finds Lcpe::Lac by enriched_id' do
37+
expect(described_class.by_enriched_id(enriched_id).first).to eq(exam)
38+
end
39+
end
40+
41+
describe '.rebuild' do
42+
it 'generates sql query' do
43+
sql = described_class.rebuild
44+
expect(sql).to be_a Lcpe::SqlContext::Sql
45+
end
46+
end
47+
48+
def generate_ref_code_from(exam)
49+
hash = exam.facility_code + '-' + exam.nexam_nm
50+
Digest::MD5.hexdigest(hash).last(5)
51+
end
52+
end

spec/models/lcpe/lac_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe Lcpe::Lac, type: :model do
6+
let(:version) { create :version, :production }
7+
let(:institution) { create :institution, version_id: version.id }
8+
let(:facility_code) { institution.facility_code }
9+
10+
before { create :weam, facility_code: }
11+
12+
describe 'when validating' do
13+
it 'has a valid factory' do
14+
expect(build(:lcpe_lac, facility_code:)).to be_valid
15+
end
16+
end
17+
18+
describe '.with_enriched_id' do
19+
before { create :lcpe_lac, facility_code: }
20+
21+
it 'returns lacs with ref_code and enriched_id attribute' do
22+
lac_enriched = described_class.with_enriched_id.first
23+
ref = generate_ref_code_from(lac_enriched)
24+
id = lac_enriched.id.to_s + '@' + ref
25+
expect(lac_enriched.ref_code).to eq(ref)
26+
expect(lac_enriched.enriched_id).to eq(id)
27+
end
28+
end
29+
30+
describe '.by_enriched_id' do
31+
subject(:lac) { create :lcpe_lac, facility_code: }
32+
33+
let(:ref_code) { generate_ref_code_from(lac) }
34+
let(:enriched_id) { lac.id.to_s + '@' + ref_code }
35+
36+
it 'finds Lcpe::Lac by enriched_id' do
37+
expect(described_class.by_enriched_id(enriched_id).first).to eq(lac)
38+
end
39+
end
40+
41+
describe '.rebuild' do
42+
it 'generates sql query' do
43+
sql = described_class.rebuild
44+
expect(sql).to be_a Lcpe::SqlContext::Sql
45+
end
46+
end
47+
48+
def generate_ref_code_from(lac)
49+
hash = lac.facility_code + '-' + lac.lac_nm
50+
Digest::MD5.hexdigest(hash).last(5)
51+
end
52+
end

0 commit comments

Comments
 (0)