-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EDM-686/Improve code coverage for lcpe lac and exams model (#1318)
* Improve code coverage for lcpe lac and exams model * linting
- Loading branch information
1 parent
84faa60
commit 3fc6221
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :lcpe_exam, class: 'Lcpe::Exam' do | ||
facility_code { '57001151' } | ||
nexam_nm { 'AP-ADVANCED PLACEMENT EXAMS' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :lcpe_lac, class: 'Lcpe::Lac' do | ||
facility_code | ||
edu_lac_type_nm { 'License' } | ||
lac_nm { 'Gas Fitter' } | ||
state { 'AR' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Lcpe::Exam, type: :model do | ||
let(:version) { create :version, :production } | ||
let(:institution) { create :institution, version_id: version.id } | ||
let(:facility_code) { institution.facility_code } | ||
|
||
before { create :weam, facility_code: } | ||
|
||
describe 'when validating' do | ||
it 'has a valid factory' do | ||
expect(build(:lcpe_exam, facility_code:)).to be_valid | ||
end | ||
end | ||
|
||
describe '.with_enriched_id' do | ||
before { create :lcpe_exam, facility_code: } | ||
|
||
it 'returns exams with ref_code and enriched_id attribute' do | ||
exam_enriched = described_class.with_enriched_id.first | ||
ref = generate_ref_code_from(exam_enriched) | ||
id = exam_enriched.id.to_s + '@' + ref | ||
expect(exam_enriched.ref_code).to eq(ref) | ||
expect(exam_enriched.enriched_id).to eq(id) | ||
end | ||
end | ||
|
||
describe '.by_enriched_id' do | ||
subject(:exam) { create :lcpe_exam, facility_code: } | ||
|
||
let(:ref_code) { generate_ref_code_from(exam) } | ||
let(:enriched_id) { exam.id.to_s + '@' + ref_code } | ||
|
||
it 'finds Lcpe::Lac by enriched_id' do | ||
expect(described_class.by_enriched_id(enriched_id).first).to eq(exam) | ||
end | ||
end | ||
|
||
describe '.rebuild' do | ||
it 'generates sql query' do | ||
sql = described_class.rebuild | ||
expect(sql).to be_a Lcpe::SqlContext::Sql | ||
end | ||
end | ||
|
||
def generate_ref_code_from(exam) | ||
hash = exam.facility_code + '-' + exam.nexam_nm | ||
Digest::MD5.hexdigest(hash).last(5) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Lcpe::Lac, type: :model do | ||
let(:version) { create :version, :production } | ||
let(:institution) { create :institution, version_id: version.id } | ||
let(:facility_code) { institution.facility_code } | ||
|
||
before { create :weam, facility_code: } | ||
|
||
describe 'when validating' do | ||
it 'has a valid factory' do | ||
expect(build(:lcpe_lac, facility_code:)).to be_valid | ||
end | ||
end | ||
|
||
describe '.with_enriched_id' do | ||
before { create :lcpe_lac, facility_code: } | ||
|
||
it 'returns lacs with ref_code and enriched_id attribute' do | ||
lac_enriched = described_class.with_enriched_id.first | ||
ref = generate_ref_code_from(lac_enriched) | ||
id = lac_enriched.id.to_s + '@' + ref | ||
expect(lac_enriched.ref_code).to eq(ref) | ||
expect(lac_enriched.enriched_id).to eq(id) | ||
end | ||
end | ||
|
||
describe '.by_enriched_id' do | ||
subject(:lac) { create :lcpe_lac, facility_code: } | ||
|
||
let(:ref_code) { generate_ref_code_from(lac) } | ||
let(:enriched_id) { lac.id.to_s + '@' + ref_code } | ||
|
||
it 'finds Lcpe::Lac by enriched_id' do | ||
expect(described_class.by_enriched_id(enriched_id).first).to eq(lac) | ||
end | ||
end | ||
|
||
describe '.rebuild' do | ||
it 'generates sql query' do | ||
sql = described_class.rebuild | ||
expect(sql).to be_a Lcpe::SqlContext::Sql | ||
end | ||
end | ||
|
||
def generate_ref_code_from(lac) | ||
hash = lac.facility_code + '-' + lac.lac_nm | ||
Digest::MD5.hexdigest(hash).last(5) | ||
end | ||
end |