dvla-application_helper 5.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. checksums.yaml +7 -0
  2. data/.drone.yml +481 -0
  3. data/.env.template +4 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +21 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/README.md +674 -0
  9. data/Rakefile +31 -0
  10. data/config/settings/drone-dev.yml +41 -0
  11. data/config/settings/drone-ext.yml +35 -0
  12. data/config/settings/drone-link.yml +35 -0
  13. data/config/settings/drone-perf.yml +35 -0
  14. data/config/settings/local-dev.yml +40 -0
  15. data/config/settings/local-ext.yml +35 -0
  16. data/config/settings/local-link.yml +35 -0
  17. data/config/settings/local-perf.yml +35 -0
  18. data/config/settings.yml +29 -0
  19. data/config/yarp.yml +6 -0
  20. data/functional-tests/Rakefile +74 -0
  21. data/functional-tests/chutney.yml +110 -0
  22. data/functional-tests/features/codl.feature +170 -0
  23. data/functional-tests/features/codl_image_review_states.feature +140 -0
  24. data/functional-tests/features/csudl.feature +54 -0
  25. data/functional-tests/features/csudl_image_review_states.feature +20 -0
  26. data/functional-tests/features/step_definitions/app_domain_steps.rb +213 -0
  27. data/functional-tests/features/step_definitions/application_creation_steps.rb +115 -0
  28. data/functional-tests/features/step_definitions/image_steps.rb +144 -0
  29. data/functional-tests/features/step_definitions/state_machine_steps.rb +43 -0
  30. data/functional-tests/features/support/data/artefacts.rb +27 -0
  31. data/functional-tests/features/support/data/image_helpers.rb +20 -0
  32. data/functional-tests/features/support/data/schema_helpers.rb +3 -0
  33. data/functional-tests/features/support/data/string_manipulation.rb +9 -0
  34. data/functional-tests/features/support/env.rb +25 -0
  35. data/functional-tests/features/support/hooks.rb +56 -0
  36. data/functional-tests/features/support/yarp_integration/yarp_helpers.rb +23 -0
  37. data/functional-tests/features/uodl_image_review_states.feature +244 -0
  38. data/functional-tests/features/uodl_non_processable.feature +441 -0
  39. data/functional-tests/features/uodl_processable.feature +416 -0
  40. data/lib/dvla/application_helper/builders/V1/application_builder.rb +298 -0
  41. data/lib/dvla/application_helper/builders/V1/codl_application_builder.rb +205 -0
  42. data/lib/dvla/application_helper/builders/V1/csudl_application_builder.rb +329 -0
  43. data/lib/dvla/application_helper/builders/V2/base_uodl_v2_application_builder.rb +357 -0
  44. data/lib/dvla/application_helper/builders/V2/cop_v2_application_builder.rb +59 -0
  45. data/lib/dvla/application_helper/builders/V2/dup_v2_application_builder.rb +84 -0
  46. data/lib/dvla/application_helper/builders/V2/exc_v2_application_builder.rb +55 -0
  47. data/lib/dvla/application_helper/builders/V2/rep_v2_application_builder.rb +84 -0
  48. data/lib/dvla/application_helper/builders/V2/tyr_v2_application_builder.rb +62 -0
  49. data/lib/dvla/application_helper/builders/V2/uodl_v2_application_builder.rb +278 -0
  50. data/lib/dvla/application_helper/builders/V3/base_uodl_v3_application_builder.rb +342 -0
  51. data/lib/dvla/application_helper/builders/V3/cop_v3_application_builder.rb +56 -0
  52. data/lib/dvla/application_helper/builders/V3/dup_v3_application_builder.rb +78 -0
  53. data/lib/dvla/application_helper/builders/V3/exc_v3_application_builder.rb +56 -0
  54. data/lib/dvla/application_helper/builders/V3/rep_v3_application_builder.rb +81 -0
  55. data/lib/dvla/application_helper/builders/V3/tyr_v3_application_builder.rb +59 -0
  56. data/lib/dvla/application_helper/builders/dup_rep_builder_mixin.rb +71 -0
  57. data/lib/dvla/application_helper/builders/photo_builder_mixin.rb +49 -0
  58. data/lib/dvla/application_helper/builders/photo_signature_builder_mixin.rb +68 -0
  59. data/lib/dvla/application_helper/configuration.rb +37 -0
  60. data/lib/dvla/application_helper/constants.rb +21 -0
  61. data/lib/dvla/application_helper/enums/review_state.rb +30 -0
  62. data/lib/dvla/application_helper/enums/unable_to_prove_licence_possession_reasons.rb +8 -0
  63. data/lib/dvla/application_helper/factories/address.rb +21 -0
  64. data/lib/dvla/application_helper/factories/application_details.rb +353 -0
  65. data/lib/dvla/application_helper/factories/casework.rb +7 -0
  66. data/lib/dvla/application_helper/factories/csudl_photo_signature_image.rb +156 -0
  67. data/lib/dvla/application_helper/factories/csudl_photo_signature_images.rb +85 -0
  68. data/lib/dvla/application_helper/factories/organ_donor.rb +32 -0
  69. data/lib/dvla/application_helper/factories/person.rb +73 -0
  70. data/lib/dvla/application_helper/factories/photo_image.rb +147 -0
  71. data/lib/dvla/application_helper/factories/photo_images.rb +183 -0
  72. data/lib/dvla/application_helper/factories/photo_signature_image.rb +158 -0
  73. data/lib/dvla/application_helper/factories/photo_signature_images.rb +64 -0
  74. data/lib/dvla/application_helper/fixtures/photo/comparison_image.jpeg +0 -0
  75. data/lib/dvla/application_helper/fixtures/photo/passport_image.jpg +0 -0
  76. data/lib/dvla/application_helper/fixtures/photo/photocard_back.jpg +0 -0
  77. data/lib/dvla/application_helper/fixtures/photo/photocard_front.jpg +0 -0
  78. data/lib/dvla/application_helper/fixtures/photo/rejected_user_uploaded_image.jpeg +0 -0
  79. data/lib/dvla/application_helper/fixtures/photo/user_uploaded_image.jpg +0 -0
  80. data/lib/dvla/application_helper/fixtures/signature/csudl_signature_image.tiff +0 -0
  81. data/lib/dvla/application_helper/fixtures/signature/passport_image.jpg +0 -0
  82. data/lib/dvla/application_helper/fixtures/signature/rejected_user_uploaded_image.jpg +0 -0
  83. data/lib/dvla/application_helper/fixtures/signature/user_uploaded_image.jpg +0 -0
  84. data/lib/dvla/application_helper/processors/application_status.rb +45 -0
  85. data/lib/dvla/application_helper/processors/application_task.rb +301 -0
  86. data/lib/dvla/application_helper/services/application_diary.rb +123 -0
  87. data/lib/dvla/application_helper/services/application_domain.rb +239 -0
  88. data/lib/dvla/application_helper/services/application_process_engine.rb +120 -0
  89. data/lib/dvla/application_helper/services/check_aws_credentials.rb +24 -0
  90. data/lib/dvla/application_helper/services/driving_licence_channel_api.rb +67 -0
  91. data/lib/dvla/application_helper/services/image_service.rb +116 -0
  92. data/lib/dvla/application_helper/services/image_utility.rb +82 -0
  93. data/lib/dvla/application_helper/services/state_machine_helpers.rb +146 -0
  94. data/lib/dvla/application_helper/version.rb +5 -0
  95. data/lib/dvla/application_helper.rb +92 -0
  96. data/renovate.json +4 -0
  97. data/scripts/application-login.sh +56 -0
  98. data/scripts/drone-aws-login.sh +18 -0
  99. data/scripts/seed_application.rb +268 -0
  100. data/sonar-project.properties +4 -0
  101. metadata +343 -0
@@ -0,0 +1,158 @@
1
+ require_relative('photo_image.rb')
2
+
3
+ module DVLA
4
+ module Application
5
+ class PhotoSignatureImageFactory < PhotoImageFactory
6
+ def initialize(unique_images:, no_comparison_image:, home_office_comparison_photo:)
7
+ @no_comparison_image = no_comparison_image
8
+ @home_office_comparison_photo = home_office_comparison_photo
9
+ super(unique_images:)
10
+ end
11
+
12
+ def build(type)
13
+ case type
14
+ when :user_signature
15
+ build_user_signature
16
+ when :passport_signature
17
+ build_passport_signature
18
+ when :passport_signature_moved
19
+ build_passport_signature_moved
20
+ when :passport_signature_utility
21
+ build_passport_active_signature_utility
22
+ else
23
+ super
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ PASSPORT_COMPARISON_IMAGE_ID = '727993a6-04c8-464d-b3e3-6c97c5795ba2'.freeze
30
+ HOME_OFFICE_COMPARISON_IMAGE_ID = 'ad3e0be1-63be-4e53-98b9-aee57eb74aaa'.freeze
31
+ USER_SIGNATURE_IMAGE_ID = '3baa5140-ad77-4b57-bac9-397af11cf2a9'.freeze
32
+ CSUDL_SIGNATURE_IMAGE_ID = '22b0342e-62d5-42e1-8f40-93f08f885938'.freeze
33
+ PASSPORT_SIGNATURE_IMAGE_ID_IMAGE_SERVICE = 'e0fa10d0-2f23-4faa-b8d7-f21d86b063b9'.freeze
34
+ PASSPORT_SIGNATURE_IMAGE_ID_IMAGE_UTILITY = '2422cd2a-9973-4573-a063-18fbfcc07eb8'.freeze
35
+
36
+ # Overridden from base class
37
+ def build_comparison
38
+ if @no_comparison_image
39
+ nil
40
+ elsif @home_office_comparison_photo
41
+ build_home_office_comparison
42
+ else
43
+ build_passport_comparison
44
+ end
45
+ end
46
+
47
+ def build_passport_comparison
48
+ image_id = @unique_images == false ? PASSPORT_COMPARISON_IMAGE_ID : Random.uuid
49
+ DVLA::Application::ImageService.put_passport_comparison_image_in_service(image_id:)
50
+ # This next step ensure image has seeded and D90 transformed image exists
51
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_type: 'Photo', image_origin: 'Passport')
52
+
53
+ {
54
+ imageId: image_id,
55
+ imageType: 'Photo',
56
+ imageSource: 'driving-licence-image-service',
57
+ imageOriginType: 'Passport',
58
+ imageStatus: 'Active',
59
+ imagePurpose: 'Comparison',
60
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
61
+ reviewHistory: [],
62
+ }
63
+ end
64
+
65
+ def build_home_office_comparison
66
+ image_id = @unique_images == false ? HOME_OFFICE_COMPARISON_IMAGE_ID : Random.uuid
67
+ DVLA::Application::ImageService.put_home_office_comparison_image_in_service(image_id:)
68
+ # This next step ensure image has seeded and D90 transformed image exists
69
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_type: 'Photo', image_origin: 'Home Office')
70
+
71
+ {
72
+ imageId: image_id,
73
+ imageType: 'Photo',
74
+ imageSource: 'driving-licence-image-service',
75
+ imageOriginType: 'Home Office',
76
+ imageStatus: 'Active',
77
+ imagePurpose: 'Comparison',
78
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
79
+ reviewHistory: [],
80
+ }
81
+ end
82
+
83
+ def build_user_signature
84
+ image_id = @unique_images == false ? USER_SIGNATURE_IMAGE_ID : Random.uuid
85
+ DVLA::Application::ImageService.put_user_uploaded_image_in_service(image_id:, image_type: 'Signature')
86
+ # This next step ensure image has seeded and D90 transformed image exists
87
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_type: 'Signature', image_origin: 'User')
88
+
89
+ {
90
+ imageId: image_id,
91
+ imageType: 'Signature',
92
+ imageSource: 'driving-licence-image-service',
93
+ imageOriginType: 'User',
94
+ imageStatus: 'Active',
95
+ imagePurpose: 'Application',
96
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
97
+ reviewHistory: [],
98
+ }
99
+ end
100
+
101
+ def build_passport_signature
102
+ image_id = @unique_images == false ? PASSPORT_SIGNATURE_IMAGE_ID_IMAGE_SERVICE : Random.uuid
103
+ DVLA::Application::ImageService.put_passport_image_in_service(image_id:, image_type: 'Signature')
104
+ # This next step ensure image has seeded and D90 transformed image exists
105
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_type: 'Signature', image_origin: 'Passport')
106
+
107
+ {
108
+ imageId: image_id,
109
+ imageType: 'Signature',
110
+ imageSource: 'driving-licence-image-service',
111
+ imageOriginType: 'Passport',
112
+ imageStatus: 'Active',
113
+ imagePurpose: 'Application',
114
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
115
+ reviewHistory: [],
116
+ }
117
+ end
118
+
119
+ def build_passport_signature_moved
120
+ image_id = @unique_images == false ? PASSPORT_SIGNATURE_IMAGE_ID_IMAGE_SERVICE : Random.uuid
121
+ DVLA::Application::ImageService.put_passport_image_in_service(image_id:, image_type: 'Signature')
122
+ # This next step ensure image has seeded and D90 transformed image exists
123
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_type: 'Signature', image_origin: 'Passport')
124
+
125
+ {
126
+ imageId: image_id,
127
+ imageType: 'Signature',
128
+ imageSource: 'driving-licence-image-service',
129
+ imageOriginType: 'Passport',
130
+ imageStatus: 'Moved',
131
+ imagePurpose: 'Application',
132
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
133
+ reviewHistory: [],
134
+ }
135
+ end
136
+
137
+ def build_passport_active_signature_utility
138
+ image_id = @unique_images == false ? PASSPORT_SIGNATURE_IMAGE_ID_IMAGE_UTILITY : Random.uuid
139
+ DVLA::Application::ImageService.put_passport_image_in_service(image_id:, image_type: 'Signature')
140
+ # This next step ensure image has seeded and D90 transformed image exists
141
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_type: 'Signature', image_origin: 'Passport')
142
+
143
+ DVLA::Application::ImageUtility.store_image_in_image_utility(image_id:, image_purpose: 'Application', image_origin: 'Passport', image_type: 'Signature', image_transformation_type: 'UI preview')
144
+
145
+ {
146
+ imageId: image_id,
147
+ imageType: 'Signature',
148
+ imageSource: 'image-utility',
149
+ imageOriginType: 'Passport',
150
+ imageStatus: 'Active',
151
+ imagePurpose: 'Application',
152
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
153
+ reviewHistory: [],
154
+ }
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,64 @@
1
+ require_relative('photo_images.rb')
2
+
3
+ module DVLA
4
+ module Application
5
+ class PhotoSignatureImagesFactory < PhotoImagesFactory
6
+ def initialize(photo_review_state, signature_review_state, unique_images, use_passport_images:, passport_images_preprocessed:, home_office_comparison_photo:)
7
+ @use_signature_passport_images = use_passport_images
8
+ @signature_review_state = signature_review_state
9
+ no_comparison_image = use_passport_images && !passport_images_preprocessed
10
+ image_factory = DVLA::Application::PhotoSignatureImageFactory.new(unique_images:, no_comparison_image:, home_office_comparison_photo:)
11
+ super(photo_review_state, unique_images, use_passport_images:, passport_images_preprocessed:, additional_passport_image_available: false, image_factory:)
12
+ end
13
+
14
+ def build
15
+ photo_images = super
16
+
17
+ signature_images = build_signature_images
18
+
19
+ images = photo_images + signature_images
20
+ images.select { |i| !i.nil? }
21
+ end
22
+
23
+ def build_signature_images
24
+ if(@use_signature_passport_images)
25
+ return build_passport_signatures
26
+ end
27
+
28
+ case @signature_review_state
29
+ when DVLA::Application::SignatureReviewState::CLERK_IN_PROGRESS, nil
30
+ build_clerk_signature
31
+ when DVLA::Application::SignatureReviewState::CLERK_REJECTED
32
+ build_clerk_signature_rejected
33
+ when DVLA::Application::SignatureReviewState::CLERK_APPROVED
34
+ build_clerk_signature_approved
35
+ else
36
+ raise 'Invalid review state passed to the Images factory'
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def build_passport_signatures
43
+ if @passport_images_preprocessed
44
+ [@image_factory.build(:passport_signature_moved),
45
+ @image_factory.build(:passport_signature_utility)]
46
+ else
47
+ [@image_factory.build(:passport_signature)]
48
+ end
49
+ end
50
+
51
+ def build_clerk_signature
52
+ [@image_factory.build(:user_signature)].flatten
53
+ end
54
+
55
+ def build_clerk_signature_rejected
56
+ add_review(build_clerk_signature, create_review('Clerk', 'Rejection on standards', ['Signature is not clear']))
57
+ end
58
+
59
+ def build_clerk_signature_approved
60
+ add_review(build_clerk_signature, create_review('Clerk', 'Success'))
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,45 @@
1
+ module DVLA
2
+ module Application
3
+ module ApplicationStatusProcessor
4
+ def self.process_to(application_id, application_status, update_reason: nil)
5
+ expected_application_types = [
6
+ 'Started', 'Received', 'Payment settlement requested', 'Preparing', 'Submitted', 'Approved', 'Returned', 'Unapproved',
7
+ 'Rejected', 'Completed', 'Deleted', 'Cancelled'
8
+ ].freeze
9
+ application_requiring_submit = %w[Approved Returned Unapproved Rejected Completed].freeze
10
+ application_requiring_received = application_requiring_submit + ['Submitted', 'Payment settlement requested', 'Preparing']
11
+
12
+ unless expected_application_types.include? application_status
13
+ raise "Invalid application status of, '#{application_status}' passed to the application status processor."
14
+ end
15
+
16
+ if application_requiring_received.include? application_status
17
+ self.update_application_status(application_id, 'Received')
18
+ end
19
+
20
+ if application_requiring_submit.include? application_status
21
+ self.update_application_status(application_id, 'Submitted')
22
+ end
23
+
24
+ if application_status == 'Completed'
25
+ self.update_application_status(application_id, 'Approved')
26
+ end
27
+
28
+ unless application_status == 'Started'
29
+ self.update_application_status(application_id, application_status, update_reason:)
30
+ end
31
+ end
32
+
33
+ def self.update_application_status(application_id, status, update_reason: nil)
34
+ application_state = {
35
+ 'status' => status,
36
+ 'timeUpdated' => Time.now.strftime('%FT%T.%3NZ') }
37
+
38
+ # only include when cancelled to avoid validation error regarding required string value
39
+ application_state['reason'] = update_reason if status == 'Cancelled'
40
+
41
+ DVLA::Application::ApplicationDomain.update_application_status(application_id:, application_state: )
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,301 @@
1
+ module DVLA
2
+ module Application
3
+ class ApplicationTaskProcessor
4
+ include BlockRepeater
5
+
6
+ class TaskNotFoundError < StandardError; end
7
+
8
+ def initialize(application_id:, target: 'Clerk')
9
+ @application_id = application_id
10
+ @target = target
11
+ end
12
+
13
+ def self.process_to(application_id, task_state, task_type: 'Photo review')
14
+ processor = new(application_id: application_id)
15
+ case task_state
16
+ when DVLA::Application::ReviewState::CLERK_REJECTED
17
+ processor.reject_photo
18
+ when DVLA::Application::ReviewState::CLERK_REJECT_COMPARISON_PHOTO
19
+ processor.reject_comparison_photo
20
+ when DVLA::Application::ReviewState::FRAUD_REJECT_COMPARISON_PHOTO
21
+ processor.refer_task_standards(task_type)
22
+ processor.refer_task_compare(task_type)
23
+ processor.reject_comparison_photo
24
+ when DVLA::Application::ReviewState::SUPERVISOR_REJECT_COMPARISON_PHOTO
25
+ processor.refer_task_standards(task_type)
26
+ processor.reject_comparison_photo
27
+ when DVLA::Application::SignatureReviewState::CLERK_REJECTED
28
+ processor.reject_signature
29
+ when DVLA::Application::ReviewState::CLERK_REFER_TO_SUPERVISOR_STANDARDS
30
+ processor.refer_task_standards(task_type)
31
+ when DVLA::Application::ReviewState::CLERK_REFER_TO_SUPERVISOR_COMPARE
32
+ processor.refer_task_compare(task_type)
33
+ when DVLA::Application::ReviewState::CLERK_APPROVED, DVLA::Application::SignatureReviewState::CLERK_APPROVED
34
+ processor.approve_task(task_type)
35
+ when DVLA::Application::ReviewState::SUPERVISOR_REJECTED
36
+ processor.refer_task_standards(task_type)
37
+ processor.reject_photo
38
+ when DVLA::Application::ReviewState::SUPERVISOR_REFER_TO_FRAUD
39
+ processor.refer_task_compare(task_type)
40
+ processor.refer_task_compare(task_type)
41
+ when DVLA::Application::ReviewState::SUPERVISOR_APPROVED
42
+ processor.refer_task_standards(task_type)
43
+ processor.approve_task(task_type)
44
+ when DVLA::Application::ReviewState::FRAUD_BEGIN_INVESTIGATION
45
+ processor.refer_task_compare(task_type)
46
+ processor.refer_task_compare(task_type)
47
+ processor.fraud_begin_investigation(task_type)
48
+ when DVLA::Application::ReviewState::FRAUD_APPROVED
49
+ processor.refer_task_standards(task_type)
50
+ processor.refer_task_compare(task_type)
51
+ processor.approve_task(task_type)
52
+ when DVLA::Application::ReviewState::FRAUD_REJECTED
53
+ processor.refer_task_standards(task_type)
54
+ processor.refer_task_compare(task_type)
55
+ processor.reject_photo
56
+ when DVLA::Application::ReviewState::FRAUD_REVIEW_REJECTION_WITH_REFUND
57
+ processor.refer_task_compare(task_type)
58
+ processor.refer_task_compare(task_type)
59
+ processor.fraud_begin_investigation(task_type)
60
+ processor.fraud_cancel_with_refund(task_type)
61
+ when DVLA::Application::ReviewState::FRAUD_REVIEW_REJECTION_WITHOUT_REFUND
62
+ processor.refer_task_compare(task_type)
63
+ processor.refer_task_compare(task_type)
64
+ processor.fraud_begin_investigation(task_type)
65
+ processor.fraud_cancel_without_refund(task_type)
66
+ when DVLA::Application::ReviewState::FRAUD_REVIEW_APPROVED
67
+ processor.refer_task_compare(task_type)
68
+ processor.refer_task_compare(task_type)
69
+ processor.fraud_begin_investigation(task_type)
70
+ processor.approve_task(task_type)
71
+ else
72
+ raise 'Invalid task state passed to the task processor'
73
+ end
74
+ end
75
+
76
+ def approve_task(task_type)
77
+ DVLA::Application.logger.info("Approving #{task_type} as #{@target}")
78
+ retrieve_and_submit_task(
79
+ {
80
+ outcome: 'Success',
81
+ taskTarget: @target,
82
+ taskType: task_type,
83
+ },
84
+ )
85
+ end
86
+
87
+ def reject_photo
88
+ DVLA::Application.logger.info("Rejecting photo as #{@target}")
89
+ retrieve_and_submit_task(
90
+ {
91
+ outcome: 'Rejection on standards',
92
+ rejectionReasons: [
93
+ 'Background is not light in colour',
94
+ 'Background is not plain',
95
+ 'Background is not clear',
96
+ ],
97
+ taskTarget: @target,
98
+ taskType: 'Photo review',
99
+ },
100
+ )
101
+ end
102
+
103
+ def reject_comparison_photo
104
+ DVLA::Application.logger.info("Rejecting photo comparison as #{@target}")
105
+ retrieve_and_submit_task({
106
+ outcome: 'Reject comparison photo',
107
+ taskTarget: @target,
108
+ taskType: 'Photo review',
109
+ })
110
+ end
111
+
112
+ def reject_signature
113
+ DVLA::Application.logger.info("Rejecting signature as #{@target}")
114
+ retrieve_and_submit_task(
115
+ {
116
+ outcome: 'Rejection on standards',
117
+ rejectionReasons: [
118
+ 'Signature is not clear',
119
+ ],
120
+ taskTarget: @target,
121
+ taskType: 'Signature review',
122
+ },
123
+ )
124
+ end
125
+
126
+ def refer_task_standards(task_type)
127
+ DVLA::Application.logger.info("Referring #{task_type} on standards as #{@target}")
128
+ retrieve_and_submit_task(
129
+ {
130
+ outcome: 'Referral at standards',
131
+ taskType: task_type,
132
+ taskTarget: @target,
133
+ },
134
+ )
135
+ DVLA::Application.logger.info("Referred #{task_type} on standards as #{@target}")
136
+ escalate_target
137
+ end
138
+
139
+ def refer_task_compare(task_type)
140
+ DVLA::Application.logger.info("Referring #{task_type} on compare as #{@target}")
141
+ retrieve_and_submit_task(
142
+ {
143
+ outcome: 'Referral at compare',
144
+ taskType: task_type,
145
+ taskTarget: @target,
146
+ },
147
+ )
148
+ escalate_target
149
+ end
150
+
151
+ def fraud_begin_investigation(task_type)
152
+ DVLA::Application.logger.info('Starting fraud investigation')
153
+ retrieve_and_submit_task(
154
+ {
155
+ caseNumber: DVLA::Application.generate_case_number,
156
+ outcome: 'Begin investigation',
157
+ taskType: task_type,
158
+ taskTarget: @target,
159
+ },
160
+ )
161
+ escalate_target
162
+ end
163
+
164
+ def fraud_cancel_with_refund(task_type)
165
+ DVLA::Application.logger.info('Fraud cancelling with refund')
166
+ retrieve_and_submit_task(
167
+ {
168
+ outcome: 'Rejection with refund',
169
+ taskType: task_type,
170
+ taskTarget: @target,
171
+ },
172
+ )
173
+ end
174
+
175
+ def fraud_cancel_without_refund(task_type)
176
+ DVLA::Application.logger.info('Fraud cancelling without refund')
177
+ retrieve_and_submit_task(
178
+ {
179
+ outcome: 'Rejection no refund',
180
+ taskType: task_type,
181
+ taskTarget: @target,
182
+ },
183
+ )
184
+ end
185
+
186
+ def casework_cancellation
187
+ DVLA::Application.logger.info('Casework cancellation')
188
+ retrieve_and_submit_task(
189
+ {
190
+ outcome: 'Cancellation',
191
+ taskTarget: 'Drivers caseworker',
192
+ taskType: 'CASP casework',
193
+ withNotification: true,
194
+ },
195
+ )
196
+ end
197
+
198
+ def casework_completion
199
+ DVLA::Application.logger.info('Casework completion')
200
+ retrieve_and_submit_task(
201
+ {
202
+ outcome: 'Completion',
203
+ taskTarget: 'Drivers caseworker',
204
+ taskType: 'CASP casework',
205
+ },
206
+ )
207
+ end
208
+
209
+ def switch_to_passport_image
210
+ DVLA::Application.logger.info('Switch to passport image')
211
+ retrieve_and_submit_task(
212
+ {
213
+ outcome: 'Switch to passport photo',
214
+ taskTarget: 'External',
215
+ taskType: 'Photo review',
216
+ },
217
+ )
218
+ end
219
+
220
+ # @param outcome [String] defaults to 'New photo uploaded', can also use 'New signature uploaded'
221
+ def user_upload_new_image(image_id:, task_type:, outcome: 'New photo uploaded')
222
+ DVLA::Application.logger.info("User upload new #{task_type} image")
223
+ retrieve_and_submit_task(
224
+ {
225
+ outcome: outcome,
226
+ taskTarget: 'External',
227
+ taskType: task_type,
228
+ imageId: image_id,
229
+ imageSource: 'driving-licence-image-service',
230
+ },
231
+ )
232
+ end
233
+
234
+ def user_upload_passport_photo(image_id:)
235
+ DVLA::Application.logger.info('User upload passport photo')
236
+ retrieve_and_submit_task(
237
+ {
238
+ outcome: 'Passport photo uploaded',
239
+ taskTarget: 'External',
240
+ taskType: 'Photo review',
241
+ imageId: image_id,
242
+ imageSource: 'driving-licence-image-service',
243
+ },
244
+ )
245
+ end
246
+
247
+ private
248
+
249
+ def escalate_target
250
+ @target = if @target == 'Clerk'
251
+ 'Supervisor'
252
+ elsif @target == 'Supervisor'
253
+ 'Fraud'
254
+ else
255
+ 'Fraud review'
256
+ end
257
+ end
258
+
259
+ def retrieve_and_submit_task(task_outcome)
260
+ channel_api_client = DVLA::Application::ChannelAPI.initialize_channel_api_instance
261
+
262
+ retrieve_tasks_request = DVLADrivingLicenceChannelApiOpenAPIClient::RetrieveTasksByApplicationIdRequest.new(
263
+ {
264
+ application_id: @application_id,
265
+ },
266
+ )
267
+
268
+ task = repeat(times: 30, delay: 3) do
269
+ tasks =
270
+ channel_api_client.get_tasks_by_application_id(
271
+ RequestHeaders::DVLA_RESOURCE,
272
+ RequestHeaders::DVLA_ORIGIN_RESOURCE,
273
+ retrieve_tasks_request,
274
+ DVLA::Application::ChannelAPI.driving_licence_channel_api_test_headers,
275
+ ).tasks
276
+
277
+ # Looking for the task for the expected review level and task type
278
+ tasks.find { |t| t.task_status == 'Active' && t.task_target == @target && t.task_type == task_outcome[:taskType] }
279
+ end.until(&:present?)
280
+
281
+ raise TaskNotFoundError, "Request: '#{retrieve_tasks_request}' found no tasks" unless task.present?
282
+
283
+ submit_task_outcome_request = DVLADrivingLicenceChannelApiOpenAPIClient::SubmitTaskOutcomeRequest.new(
284
+ {
285
+ application_id: @application_id,
286
+ task_id: task.task_id,
287
+ task_outcome:,
288
+ version: 1,
289
+ },
290
+ )
291
+
292
+ channel_api_client.submit_task_outcome_with_http_info(
293
+ RequestHeaders::DVLA_RESOURCE,
294
+ RequestHeaders::DVLA_ORIGIN_RESOURCE,
295
+ submit_task_outcome_request,
296
+ DVLA::Application::ChannelAPI.driving_licence_channel_api_test_headers_including_user,
297
+ )
298
+ end
299
+ end
300
+ end
301
+ end