Skip to content

Commit

Permalink
Fix specs for urn
Browse files Browse the repository at this point in the history
  • Loading branch information
fumimowdan committed Oct 2, 2023
1 parent afbda39 commit 2a714a2
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 8 deletions.
6 changes: 6 additions & 0 deletions spec/features/admin_console/applications_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

def given_there_are_few_applications
# Create 2 specific applications for search tests
create_list(:urn, 5, code: "TE")
create_list(:urn, 5, code: "ST")
unique_applicant = create(:applicant, given_name: "Unique Given Name", middle_name: "Unique Middle Name", family_name: "Unique Family Name", email_address: "[email protected]")
create(:application, applicant: unique_applicant, urn: "Unique Urn 1")

Expand All @@ -70,12 +72,16 @@ def given_there_are_few_applications
end

def given_there_is_an_application_that_breached_sla
create_list(:urn, 5, code: "TE")
create_list(:urn, 5, code: "ST")
applicant = create(:applicant)
application = create(:application, applicant:)
application.application_progress.update(initial_checks_completed_at: 4.days.ago)
end

def given_there_are_applications_with_different_dates
create_list(:urn, 5, code: "TE")
create_list(:urn, 5, code: "ST")
create(:application, application_progress: build(:application_progress, :initial_checks_completed, status: :initial_checks))
create(:application, application_progress: build(:application_progress, :home_office_checks_completed, status: :home_office_checks))
end
Expand Down
90 changes: 90 additions & 0 deletions spec/fixtures/urns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
te_one:
suffix: 5668
prefix: IRP
code: TE

te_two:
suffix: 21368
prefix: IRP
code: TE

te_three:
suffix: 5
prefix: IRP
code: TE

te_four:
suffix: 76998
prefix: IRP
code: TE

te_five:
suffix: 6559
prefix: IRP
code: TE

te_six:
suffix: 6
prefix: IRP
code: TE

te_seven:
suffix: 2298
prefix: IRP
code: TE

te_eight:
suffix: 1159
prefix: IRP
code: TE

te_nine:
suffix: 79298
prefix: IRP
code: TE

te_ten:
suffix: 19549
prefix: IRP
code: TE

st_one:
suffix: 5668
prefix: IRP
code: ST

st_two:
suffix: 29968
prefix: IRP
code: ST

st_three:
suffix: 5
prefix: IRP
code: ST

st_four:
suffix: 76998
prefix: IRP
code: ST

st_five:
suffix: 6559
prefix: IRP
code: ST

st_six:
suffix: 6
prefix: IRP
code: ST

st_seven:
suffix: 28
prefix: IRP
code: ST

st_eight:
suffix: 159
prefix: IRP
code: ST

5 changes: 4 additions & 1 deletion spec/models/urn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
require "rails_helper"

RSpec.describe Urn do

describe "next" do
subject(:next_urn) { described_class.next(route) }

Expand Down Expand Up @@ -41,6 +40,10 @@
context "when there is no more urn available to assign" do
let(:route) { "salaried_trainee" }

before do
allow(described_class).to receive(:find_by!).and_raise(ActiveRecord::RecordNotFound)
end

it { expect { next_urn }.to raise_error(Urn::NoUrnAvailableError) }
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
end
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = Rails.root.join("/spec/fixtures")
config.fixture_path = Rails.root.join("spec/fixtures")
config.global_fixtures = :urns

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
Expand Down
22 changes: 16 additions & 6 deletions spec/services/generate_urns_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
require "rails_helper"

RSpec.describe GenerateUrns do
subject(:service) { described_class }
describe ".generate" do
subject(:generate) { described_class.new(code:).generate }

describe ".call" do
it { fail }
end
before do
allow(Urn).to receive(:insert_all)
stub_const "Urn::MAX_SUFFIX", 3
generate
end

describe ".generate" do
it { fail }
let(:code) { "TE" }
let(:expected_data) do
[
{ prefix: "IRP", code: code, suffix: 1 },
{ prefix: "IRP", code: code, suffix: 2 },
]
end

it { expect(Urn).to have_received(:insert_all).with(match_array(expected_data)) }
end
end

0 comments on commit 2a714a2

Please sign in to comment.