Skip to content

Commit

Permalink
EDM-686/Improve code coverage for lcpe lac and exams model (#1318)
Browse files Browse the repository at this point in the history
* Improve code coverage for lcpe lac and exams model

* linting
  • Loading branch information
jefftmarks authored Feb 19, 2025
1 parent 84faa60 commit 3fc6221
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/factories/lcpe/exams.rb
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
10 changes: 10 additions & 0 deletions spec/factories/lcpe/lacs.rb
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
52 changes: 52 additions & 0 deletions spec/models/lcpe/exam_spec.rb
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
52 changes: 52 additions & 0 deletions spec/models/lcpe/lac_spec.rb
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

0 comments on commit 3fc6221

Please sign in to comment.