Skip to content

Commit 33ab4cd

Browse files
TSS-37: Add convenience methods for different task types in BusinessProcessBuilder (#87)
The following methods have been added: - `staff_task`: For creating tasks assigned to staff members - `system_process`: For creating automated process steps - `applicant_task`: For creating tasks assigned to applicants - `third_party_task`: For creating tasks assigned to external parties These methods act as semantic wrappers around the generic `step` method, making business process definitions more readable and type-safe. --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Loren Yu <yuloren@gmail.com> Co-authored-by: Loren Yu <loren@navapbc.com>
1 parent a4850e4 commit 33ab4cd

4 files changed

Lines changed: 44 additions & 45 deletions

File tree

app/models/flex/business_process_builder.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ def step(name, step)
5050
steps[name] = step
5151
end
5252

53+
def staff_task(name)
54+
step(name, Flex::StaffTask.new(name, StaffTaskCreationService))
55+
end
56+
57+
def system_process(name, callable)
58+
step(name, Flex::SystemProcess.new(name, callable))
59+
end
60+
61+
def applicant_task(name)
62+
step(name, Flex::ApplicantTask.new(name))
63+
end
64+
65+
def third_party_task(name)
66+
step(name, Flex::ThirdPartyTask.new(name))
67+
end
68+
5369
def transition(from, event_name, to)
5470
transitions[from] ||= {}
5571
transitions[from][event_name] = to

spec/acceptance/flex/passport_application_case_acceptance_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Flex
1212
kase = PassportCase.find_by_application_form_id(test_form.id)
1313
expect(kase).not_to be_nil
1414
expect(kase.status).to eq ("open")
15-
expect(kase.business_process_current_step).to eq ("collect_application_info")
15+
expect(kase.business_process_current_step).to eq ("submit_application")
1616

1717
# submit application
1818
test_form.first_name = "John"

spec/dummy/app/business_processes/passport_business_process.rb

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
PassportBusinessProcess = Flex::BusinessProcess.define(:passport, PassportCase) do |bp|
22
# Define steps
3-
bp.step('collect_application_info',
4-
Flex::StaffTask.new("Collect App Info", StaffTaskCreationService))
3+
bp.applicant_task('submit_application')
54

6-
bp.step('verify_identity',
7-
Flex::SystemProcess.new("Verify Identity", ->(kase) {
8-
IdentityVerificationService.new(kase).verify_identity
9-
}))
5+
bp.system_process('verify_identity', ->(kase) {
6+
IdentityVerificationService.new(kase).verify_identity
7+
})
108

11-
bp.step('manual_adjudicator_review',
12-
Flex::StaffTask.new("Manual Adjudicator Review", AdjudicatorTaskCreationService))
9+
bp.staff_task('manual_adjudicator_review')
1310

14-
bp.step('review_passport_photo',
15-
Flex::SystemProcess.new("Review Passport Photo", ->(kase) {
16-
PhotoVerificationService.new(kase).verify_photo
17-
}))
11+
bp.system_process('review_passport_photo', ->(kase) {
12+
PhotoVerificationService.new(kase).verify_photo
13+
})
1814

19-
bp.step('notify_user_passport_approved',
20-
Flex::SystemProcess.new("Notify Passport Approval", ->(kase) {
21-
UserNotificationService.new(kase).send_notification("approval")
22-
}))
15+
bp.system_process('notify_user_passport_approved', ->(kase) {
16+
UserNotificationService.new(kase).send_notification("approval")
17+
})
2318

24-
bp.step('notify_user_passport_rejected',
25-
Flex::SystemProcess.new("Notify Passport Rejection", ->(kase) {
26-
UserNotificationService.new(kase).send_notification("rejection")
27-
}))
19+
bp.system_process('notify_user_passport_rejected', ->(kase) {
20+
UserNotificationService.new(kase).send_notification("rejection")
21+
})
2822

2923
# Define start step
30-
bp.start_on_application_form_created('collect_application_info')
24+
bp.start_on_application_form_created('submit_application')
3125

3226
# Define transitions
33-
bp.transition('collect_application_info', 'PassportApplicationFormSubmitted', 'verify_identity')
34-
bp.transition('collect_application_info', 'application_cancelled', 'end')
27+
bp.transition('submit_application', 'PassportApplicationFormSubmitted', 'verify_identity')
28+
bp.transition('submit_application', 'application_cancelled', 'end')
3529
bp.transition('verify_identity', 'identity_verified', 'review_passport_photo')
3630
bp.transition('verify_identity', 'identity_warning', 'manual_adjudicator_review')
3731
bp.transition('manual_adjudicator_review', 'identity_verified', 'review_passport_photo')

spec/dummy/app/business_processes/test_business_process.rb

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
TestBusinessProcess = Flex::BusinessProcess.define(:test, TestCase) do |bp|
22
# Define steps
3-
bp.step('staff_task',
4-
Flex::StaffTask.new("staff_task", StaffTaskCreationService))
5-
6-
bp.step('system_process',
7-
Flex::SystemProcess.new("system_process", ->(kase) {
8-
Flex::EventManager.publish("event2", { case_id: kase.id })
9-
}))
10-
11-
bp.step('staff_task_2',
12-
Flex::StaffTask.new("staff_task_2", StaffTaskCreationService))
13-
14-
bp.step('applicant_task',
15-
Flex::ApplicantTask.new("Submit Required Documents"))
16-
17-
bp.step('third_party_task',
18-
Flex::ThirdPartyTask.new("Review Employee Leave Application"))
19-
20-
bp.step('system_process_2',
21-
Flex::SystemProcess.new("system_process_2", ->(kase) {
22-
Flex::EventManager.publish("event6", { case_id: kase.id })
23-
}))
3+
bp.staff_task('staff_task')
4+
bp.system_process('system_process', ->(kase) {
5+
Flex::EventManager.publish("event2", { case_id: kase.id })
6+
})
7+
bp.staff_task('staff_task_2')
8+
bp.applicant_task('applicant_task')
9+
bp.third_party_task('third_party_task')
10+
bp.system_process('system_process_2', ->(kase) {
11+
Flex::EventManager.publish("event6", { case_id: kase.id })
12+
})
2413

2514
# Define start step
2615
bp.start_on_application_form_created('staff_task')

0 commit comments

Comments
 (0)