Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asmega committed Jan 17, 2025
1 parent 04a5c5b commit 17e2000
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 25 deletions.
26 changes: 1 addition & 25 deletions app/models/journeys/navigator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@ def initialize(current_slug:, slug_sequence:, params:, session:)
@session = session
end

def slug_to_load
return "ineligible" if eligibility_checker.ineligible?

slug_sequence.slugs.each do |slug|
form_class = journey.form_class_for_slug(slug:)
form = form_class.new(
journey:,
journey_session:,
params: {},
session:
)

if form.invalid?
return slug
end
end
end

def previous_slug
last_valid_slug = nil

Expand Down Expand Up @@ -61,7 +43,7 @@ def next_slug
form = form_class.new(
journey:,
journey_session:,
params: ActionController::Parameters.new,
params:,
session:
)
form.skip_tree_walking_validation!
Expand Down Expand Up @@ -90,12 +72,6 @@ def next_slug
end
end

def previous?
end

def next?
end

private

def journey
Expand Down
85 changes: 85 additions & 0 deletions spec/models/journeys/navigator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
require "rails_helper"

RSpec.describe Journeys::Navigator do
subject { described_class.new(current_slug:, slug_sequence:, params:, session:) }

let(:current_slug) { "teaching-responsibilities" }
let(:slug_sequence) { Journeys::FurtherEducationPayments::SlugSequence.new(journey_session) }
let(:params) { ActionController::Parameters.new }
let(:session) { {} }
let(:journey_session) do
create(:further_education_payments_session, answers: answers)
end

describe "#next_slug" do
context "when should be first slug" do
let(:answers) do
build(
:further_education_payments_answers
)
end

it "returns first slug" do
expect(subject.next_slug).to eql("teaching-responsibilities")
end
end

context "when should be second slug" do
let(:current_slug) { "teaching-responsibilities" }
let(:params) do
ActionController::Parameters.new(claim: {
teaching_responsibilities: "true"
})
end

let(:answers) do
build(
:further_education_payments_answers,
)
end

it "returns second slug" do
expect(subject.next_slug).to eql("further-education-provision-search")
end
end

context "when should be third slug" do
let(:current_slug) { "further-education-provision-search" }
let(:params) do
ActionController::Parameters.new(claim: {
provision_search: "ply"
})
end

let(:answers) do
build(
:further_education_payments_answers,
teaching_responsibilities: true
)
end

before do
create(:school, name: "Plymouth")
end

it "returns third slug" do
expect(subject.next_slug).to eql("select-provision")
end
end

context "when should be ineligible" do
let(:current_slug) { "teaching-responsibilities" }

let(:answers) do
build(
:further_education_payments_answers,
teaching_responsibilities: false
)
end

it "returns ineligible" do
expect(subject.next_slug).to eql("ineligible")
end
end
end
end

0 comments on commit 17e2000

Please sign in to comment.