Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/models/strata/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class Case < ApplicationRecord

has_many :tasks, as: :case, class_name: "Strata::Task"

# Cases that are currently in a staff-facing step
scope :actionable, -> do
staff_task_steps = business_process.steps.select { |step_name, step| step.is_a?(Strata::StaffTask) }.keys
where(business_process_current_step: staff_task_steps)
end

# Returns the base attributes that should be included in all case migrations.
# IMPORTANT: When adding new attributes to the Case model, add them here as well
# to ensure they're included in migrations created by the generator.
Expand Down
25 changes: 3 additions & 22 deletions spec/dummy/app/business_processes/passport_business_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,13 @@ class PassportBusinessProcess < Strata::BusinessProcess
IdentityVerificationService.new(kase).verify_identity
})

staff_task('manual_adjudicator_review', PassportTask)

system_process('review_passport_photo', ->(kase) {
PhotoVerificationService.new(kase).verify_photo
})

system_process('notify_user_passport_approved', ->(kase) {
UserNotificationService.new(kase).send_notification("approval")
})

system_process('notify_user_passport_rejected', ->(kase) {
UserNotificationService.new(kase).send_notification("rejection")
})
staff_task('review_passport_photo', PassportPhotoTask)

# Define start step
start_on_application_form_created('submit_application')

# Define transitions
transition('submit_application', 'PassportApplicationFormSubmitted', 'verify_identity')
transition('submit_application', 'application_cancelled', 'end')
transition('verify_identity', 'identity_verified', 'review_passport_photo')
transition('verify_identity', 'identity_warning', 'manual_adjudicator_review')
transition('manual_adjudicator_review', 'identity_verified', 'review_passport_photo')
transition('manual_adjudicator_review', 'identity_rejected', 'application_rejected')
transition('review_passport_photo', 'passport_photo_approved', 'notify_user_passport_approved')
transition('review_passport_photo', 'passport_photo_rejected', 'review_passport_photo')
transition('notify_user_passport_approved', 'notification_completed', 'end')
transition('notify_user_passport_rejected', 'notification_completed', 'end')
transition('verify_identity', 'IdentityVerified', 'review_passport_photo')
transition('review_passport_photo', 'PassportPhotoApproved', 'end')
end
3 changes: 2 additions & 1 deletion spec/dummy/app/controllers/passport_cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class PassportCasesController < StaffController
before_action :set_case, only: %i[ show application_details documents history notes tasks ]

def index
@cases = PassportCase.order(created_at: :desc)
@cases = PassportCase.actionable
.order(created_at: :desc)
.all
end

Expand Down
1 change: 1 addition & 0 deletions spec/dummy/app/services/identity_verification_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ def initialize(kase)
end

def verify_identity
Strata::EventManager.publish("IdentityVerified", { case_id: @kase.id })
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,10 @@
test_form.save!
test_form.submit_application
kase.reload
expect(kase.business_process_instance.current_step).to eq ("verify_identity")

# verify identity (simulate action that an adjudicator takes)
Strata::EventManager.publish("identity_verified", { case_id: kase.id })
kase.reload
expect(kase.business_process_instance.current_step).to eq ("review_passport_photo")

# approve passport photo
Strata::EventManager.publish("passport_photo_approved", { case_id: kase.id })
kase.reload
expect(kase.business_process_instance.current_step).to eq ("notify_user_passport_approved")

# notify user
Strata::EventManager.publish("notification_completed", { case_id: kase.id })
Strata::EventManager.publish("PassportPhotoApproved", { case_id: kase.id })

# check case status
kase.reload
Expand Down
25 changes: 25 additions & 0 deletions spec/models/strata/case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@
end
end

describe '.actionable scope' do
it 'returns cases that are in staff task steps' do
# Create cases in different steps
staff_case1 = create(:test_case)
staff_case1.update!(business_process_current_step: 'staff_task')

staff_case2 = create(:test_case)
staff_case2.update!(business_process_current_step: 'staff_task_2')

system_case = create(:test_case)
system_case.update!(business_process_current_step: 'system_process')

applicant_case = create(:test_case)
applicant_case.update!(business_process_current_step: 'applicant_task')

third_party_case = create(:test_case)
third_party_case.update!(business_process_current_step: 'third_party_task')

actionable_cases = TestCase.actionable.to_a

expect(actionable_cases).to include(staff_case1, staff_case2)
expect(actionable_cases).not_to include(system_case, applicant_case, third_party_case)
end
end

describe '.migrate_business_process_current_step' do
let(:from_step) { Faker::Alphanumeric.alpha(number: rand(5..15)) }
let(:to_step) { Faker::Alphanumeric.alpha(number: rand(5..15)) }
Expand Down