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,329 @@
1
+ require_relative('../photo_signature_builder_mixin.rb')
2
+
3
+ module DVLA
4
+ module Application
5
+ class CSUDLApplicationBuilder
6
+ # Including all properties and methods needed to support photos and signatures
7
+ include DVLA::Application::PhotoSignatureBuilderMixin
8
+
9
+ def initialize
10
+ @processable = false
11
+ @unique_images = false
12
+ @applicant = nil
13
+ @application_id = SecureRandom::uuid
14
+ @application_status = 'Preparing'
15
+ @customer_id = :default
16
+ @update_reason = nil
17
+ @product_type = 'Driving Licence'
18
+ @update_address = false # Optional field
19
+ @unable_to_prove_licence_possession_reason = nil # Optional field
20
+ @organ_donor = nil
21
+ @photo_compliance_checks = false # Optional fields within
22
+ @investigation_required = false # Optional field
23
+ @reminder_barcode_contents = nil # Optional field
24
+ @licence_data = nil # Optional fields within
25
+ @counter_service_metadata = nil
26
+ init_photo_signature_properties
27
+ end
28
+
29
+ # Some builder methods are automatically included from PhotoSignatureBuilderMixin
30
+
31
+ # Marks the application as processable, doing this will ensure that real services are used to create the
32
+ # application. For example, the channel api will process the tasks rather than stub data being provided.
33
+ # Whilst this results in a more complete application, this option is more expensive.
34
+ # Avoid excessive use in QA tests.
35
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
36
+ def processable
37
+ @processable = true
38
+ self
39
+ end
40
+
41
+ # Marks the application as non-processable. This will result in the application being created using the test application endpoint.
42
+ # These applications cannot be actioned via the task service.
43
+ # This is typically the default option to be used.
44
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
45
+ def non_processable
46
+ @processable = false
47
+ self
48
+ end
49
+
50
+ # APE uses very specific generated uuid to test with, the inspectable hooks filter the last 12 integers to return specific responses
51
+ # @param application_id [UUID]
52
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
53
+ def with_application_id(application_id)
54
+ @application_id = application_id
55
+ self
56
+ end
57
+
58
+ # The application will be made for the given customer
59
+ # @param customer_id [String] The customer ID to use
60
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
61
+ def with_customer_id(customer_id)
62
+ @customer_id = customer_id
63
+ self
64
+ end
65
+
66
+ # The application will contain the provided applicant data.
67
+ # @param applicant [ApplicantObject] Application data.
68
+ # @return [Builder]
69
+ def with_applicant(applicant)
70
+ @applicant = applicant
71
+ self
72
+ end
73
+
74
+ def is_welsh_language
75
+ @welsh_language = true
76
+ self
77
+ end
78
+
79
+ # The application will contain a phone number.
80
+ # @return [Builder]
81
+ def has_phone_number
82
+ @phone_number = true
83
+ self
84
+ end
85
+
86
+ def with_low_confidence_level
87
+ @identity_confidence_level = 'LOW'
88
+ self
89
+ end
90
+
91
+ # The application will contain a specific application status.
92
+ # How this state is reached will depend on if the application has been marked as processable or not.
93
+ # If processable is used here, we will also contain all actions.
94
+ # @param application_status [String] The application status the application should be in.
95
+ # @param update_reason [String] The reason for the change in status.
96
+ # @return [DVLA::Application::CSUDLApplicationBuilder].
97
+ def with_application_status(application_status, update_reason = nil)
98
+ @application_status = application_status
99
+ @update_reason = update_reason
100
+ self
101
+ end
102
+
103
+ # Sets the organ donor status of the application.
104
+ # By default, no organ donation is made
105
+ # Passing true will cause all_organs to be selected.
106
+ # Passing false will ensure no organs are selected.
107
+ # @param donor [boolean] Organ donor status.
108
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
109
+ def is_organ_donor(donor)
110
+ @organ_donor = donor
111
+ self
112
+ end
113
+
114
+ # Adds the customer provided reason for not being able to prove licence possession to the application
115
+ # @param reason [DVLA::Application::UnableToProveLicencePossessionReasons] the reason for not being able to prove licence possession
116
+ # @return [BuilderUsingMixin]
117
+ def with_unable_to_prove_licence_possession_reason(reason)
118
+ @unable_to_prove_licence_possession_reason = reason
119
+ self
120
+ end
121
+
122
+ # The application will contain unique imageIds
123
+ # Allows images to be interacted with during test, e.g. deleted
124
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
125
+ def unique_images
126
+ @unique_images = true
127
+ self
128
+ end
129
+
130
+ # The application will have a new address to be updated.
131
+ # If an address isn't passed in, it will generate a random address.
132
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
133
+ def with_update_address(new_address = 'Random')
134
+ @update_address = new_address
135
+ self
136
+ end
137
+
138
+ # The application wil have Photo Compliance Checks Present
139
+ # @param photo_compliance_checks [Hash] The photo compliance checks to be used in the application.
140
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
141
+ def with_photo_compliance_checks(photo_compliance_checks = nil)
142
+ @photo_compliance_checks = photo_compliance_checks || {
143
+ photoOverride: false,
144
+ icaoCompliant: true,
145
+ eyesOpen: true,
146
+ exposure: true,
147
+ frontalView: true,
148
+ greyscaleDensity: true,
149
+ uniformLighting: true,
150
+ headWidth: true,
151
+ headLength: true,
152
+ widthHeightRatio: true,
153
+ resolution: true,
154
+ verticalPosition: true,
155
+ horizontallyCentered: true,
156
+ }
157
+ self
158
+ end
159
+
160
+ # Flags the application as requiring an investigation by a counter service clerk.
161
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
162
+ def with_investigation_required
163
+ @investigation_required = true
164
+ self
165
+ end
166
+
167
+ # At the moment, this will not function, as the happy path expects an applicant to be present.
168
+ # Driver reminder service may not bew able to find a customer, which could cause this case
169
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
170
+ def with_no_applicant
171
+ @applicant = false
172
+ self
173
+ end
174
+
175
+ # Sets the contents of the scanned bartcode from the reminder letter sent to the applicant.
176
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
177
+ def with_reminder_barcode_contents(barcode_contents)
178
+ @reminder_barcode_contents = barcode_contents
179
+ self
180
+ end
181
+
182
+ # Sets the data captured from the driver's licence. if licence_data is not provided, it will default to a set of values.
183
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
184
+ def with_licence_data(licence_data = nil)
185
+ @licence_data = licence_data || {
186
+ photocard_surrendered: true,
187
+ photoCardIssueNumber: '2',
188
+ }
189
+ self
190
+ end
191
+
192
+ # Sets the counter service metadata for the application. Optional as there is already default metadata set in the application factory.
193
+ # @return [DVLA::Application::CSUDLApplicationBuilder]
194
+ def with_counter_service_metadata(counter_service_metadata)
195
+ @counter_service_metadata = counter_service_metadata
196
+ self
197
+ end
198
+
199
+ def check_application_validity
200
+ # Allows validation of the application before building it
201
+ end
202
+
203
+ # Creating the images that the BaseUODLV2ApplicationBuilder will include in the app
204
+ def application_images
205
+ generate_csudl_photo_signature_images(@processable, @unique_images)
206
+ end
207
+
208
+ # Advance and submits the tasks based on the phot and signature review state specified | DL-14939
209
+ # def process_application_tasks(app)
210
+ # process_photo_signature_tasks(app) if @processable
211
+ # end
212
+ #
213
+ def set_application_specific_fields!(app)
214
+ unless @unable_to_prove_licence_possession_reason.nil?
215
+ app.data.unable_to_prove_licence_possession_reason = @unable_to_prove_licence_possession_reason
216
+ end
217
+
218
+ if @update_address
219
+ app.data.update_address = if @update_address === 'Random'
220
+ { newAddress: { unstructuredAddress: FM[:application_unstructured_address].build } }
221
+ else
222
+ @update_address
223
+ end
224
+ end
225
+
226
+ if @photo_compliance_checks
227
+ app.data.photo_compliance_checks = @photo_compliance_checks
228
+ end
229
+
230
+ if @investigation_required
231
+ app.data.investigation_required = true
232
+ end
233
+
234
+ if @reminder_barcode_contents
235
+ app.data.reminder_barcode_contents = @reminder_barcode_contents
236
+ end
237
+
238
+ if @licence_data
239
+ app.data.licence_data = @licence_data
240
+ end
241
+
242
+ if @counter_service_metadata
243
+ app.data.counter_service_metadata = @counter_service_metadata
244
+ end
245
+ end
246
+
247
+ def build
248
+ # Sense check to ensure AWS credentials are present.
249
+ DVLA::Application.check_aws_credentials
250
+
251
+ check_application_validity
252
+
253
+ factory = if @processable
254
+ # FM[:csudl_processable_application]
255
+ # DL-14939
256
+ # Processable CSUDL not available yet, throw an error
257
+ raise 'Processable CSUDL application is not available yet.'
258
+ else
259
+ FM[:csudl_application]
260
+ end
261
+
262
+ app = factory.build do |b|
263
+ update_main_properties!(b)
264
+
265
+ update_applicant!(b)
266
+ update_organ_donor!(b)
267
+
268
+ b.images = application_images
269
+
270
+ set_application_specific_fields!(b)
271
+ end
272
+
273
+ # DL-14939 - Process tasks
274
+ # process_application_tasks(app)
275
+ process_application(app)
276
+
277
+ DVLA::Application::ApplicationDomain.retrieve_application_by_app_id(application_id: app.application_id)
278
+ end
279
+
280
+ private
281
+
282
+ # -- Methods allowing specific actions that occur during the application build process --
283
+ def update_main_properties!(app)
284
+ app.application_id = @application_id
285
+ app.customer_id = @customer_id unless @customer_id == :default
286
+ unless @processable
287
+ app.data_schema = 'https://osl-data-dictionary-schemas.engineering.dvla.gov.uk/driving-licence-application/applications/v1/counter-service-update-driving-licence-application.json'
288
+ app.product_type = @product_type
289
+ end
290
+ end
291
+
292
+ def update_applicant!(app)
293
+ if @applicant == false
294
+ app.data.applicant = nil
295
+ else
296
+ app.data.applicant = @applicant if @applicant
297
+ app.data.applicant[:phoneNumber] = Faker::PhoneNumber.phone_number if @phone_number
298
+ app.data.applicant[:languagePreference] = 'Welsh' if @welsh_language
299
+ app.data.applicant[:identityTokenData][:confidenceLevel] = @identity_confidence_level
300
+ end
301
+ end
302
+
303
+ def update_organ_donor!(app)
304
+ app.data.organ_donor = if @organ_donor
305
+ set_any_organs(any_organs_bool: @organ_donor)
306
+ elsif @application_status == 'Rejected'
307
+ FM[:organ_donor_d90_response].build(attributes: { kidneys: true })
308
+ elsif @application_status == 'Returned'
309
+ FM[:organ_donor_d90_response].build(attributes: { cornea: true })
310
+ elsif @application_status == 'Unapproved'
311
+ FM[:organ_donor_d90_response].build(attributes: { heart: true })
312
+ else
313
+ {}
314
+ end
315
+ end
316
+
317
+ def process_application(app)
318
+ unless @processable
319
+
320
+ if @application_status == 'Cancelled' && @update_reason.nil?
321
+ @update_reason = 'Timed out'
322
+ end
323
+
324
+ DVLA::Application::ApplicationStatusProcessor.process_to(app.application_id, @application_status, update_reason: @update_reason)
325
+ end
326
+ end
327
+ end
328
+ end
329
+ end
@@ -0,0 +1,357 @@
1
+ module DVLA
2
+ module Application
3
+ class BaseUODLV2ApplicationBuilder
4
+ def initialize
5
+ @applicant = nil
6
+ @application_id = SecureRandom::uuid
7
+ @application_status = 'Preparing'
8
+ @bfpo_address = false
9
+ @change_of_address = false
10
+ @customer_id = nil
11
+ @driver_id = nil
12
+ @driving_licence_actions = nil
13
+ @extend_application_deadline = false
14
+ @free_key_address = false
15
+ @identity_confidence_level = 'MEDIUM'
16
+ @organ_donor = nil
17
+ @payments = nil
18
+ @product_type = 'Driving Licence'
19
+ @processable = false
20
+ @phone_number = false
21
+ @transaction_outcome = nil
22
+ @unique_images = false
23
+ @update_reason = nil
24
+ @welsh_language = false
25
+ end
26
+
27
+ # Marks the application as processable, doing this will ensure that real services are used to create the
28
+ # application. For example, the channel api will process the tasks rather than stub data being provided.
29
+ # Whilst this results in a more complete application, this option is more expensive.
30
+ # Avoid excessive use in QA tests.
31
+ # @return [Builder]
32
+ def processable
33
+ @processable = true
34
+ self
35
+ end
36
+
37
+ # Marks the application as non-processable. This will result in the application being created using the test application endpoint.
38
+ # These applications cannot be actioned via the task service.
39
+ # This is typically the default option to be used.
40
+ # @return [Builder]
41
+ def non_processable
42
+ @processable = false
43
+ self
44
+ end
45
+
46
+ # APE uses very specific generated uuid to test with, the inspectable hooks filter the last 12 integers to return specific responses
47
+ # @param application_id [UUID]
48
+ def with_application_id(application_id)
49
+ @application_id = application_id
50
+ self
51
+ end
52
+
53
+ # The application will be made for the given customer
54
+ # @param customer_id [String] The customer ID to use
55
+ # @return [Builder]
56
+ def with_customer_id(customer_id)
57
+ @customer_id = customer_id
58
+ self
59
+ end
60
+
61
+ # The application will be made for the given driver
62
+ # @param driver_id [String] The driver ID to use
63
+ # @return [Builder]
64
+ def with_driver_id(driver_id)
65
+ @driver_id = driver_id
66
+ self
67
+ end
68
+
69
+ # The application will contain a specific application status.
70
+ # How this state is reached will depend on if the application has been marked as processable or not.
71
+ # If processable is used here, we will also contain all actions.
72
+ # @param application_status [String] The application status the application should be in.
73
+ # @param update_reason [String] The reason for the change in status.
74
+ # @return [Builder].
75
+ def with_application_status(application_status, update_reason = nil)
76
+ @application_status = application_status
77
+ @update_reason = update_reason
78
+ self
79
+ end
80
+
81
+ # The application will be updated with a call to action field which is used to extend an application
82
+ def extend_application_deadline
83
+ @extend_application_deadline = true
84
+ self
85
+ end
86
+
87
+ # The application will contain the provided payments.
88
+ # @param payments [PaymentObject] Payment status.
89
+ # @return [Builder]
90
+ def with_payments(payments)
91
+ @payments = payments
92
+ self
93
+ end
94
+
95
+ def with_driving_licence_actions(action)
96
+ @driving_licence_actions = action
97
+ self
98
+ end
99
+
100
+ # The application will contain the provided applicant data.
101
+ # @param applicant [ApplicantObject] Application data.
102
+ # @return [Builder]
103
+ def with_applicant(applicant)
104
+ @applicant = applicant
105
+ self
106
+ end
107
+
108
+ # The application will contain a bfpo address.
109
+ # @return [Builder]
110
+ def with_bfpo_address
111
+ @bfpo_address = true
112
+ self
113
+ end
114
+
115
+ # The application will contain a free key address.
116
+ # @return [Builder]
117
+ def with_free_key_address
118
+ @free_key_address = true
119
+ self
120
+ end
121
+
122
+ # The application will contain a change of address.
123
+ # @return [Builder]
124
+ def with_change_of_address
125
+ @change_of_address = true
126
+ self
127
+ end
128
+
129
+ # Sets the organ donor status of the application.
130
+ # By default, no organ donation is made
131
+ # Passing true will cause all_organs to be selected.
132
+ # Passing false will ensure no organs are selected.
133
+ # @param donor [boolean] Organ donor status.
134
+ # @return [Builder]
135
+ def is_organ_donor(donor)
136
+ @organ_donor = donor
137
+ self
138
+ end
139
+
140
+ def is_welsh_language
141
+ @welsh_language = true
142
+ self
143
+ end
144
+
145
+ # The application will contain a phone number.
146
+ # @return [Builder]
147
+ def has_phone_number
148
+ @phone_number = true
149
+ self
150
+ end
151
+
152
+ def with_low_confidence_level
153
+ @identity_confidence_level = 'LOW'
154
+ self
155
+ end
156
+
157
+ # Allows specific product type to be passed in
158
+ # Used during APE testing for inspectable hooks
159
+ # @param product [Enum] one of: [Vehicles,Driving Licence,Test]
160
+ # @return [Builder]
161
+ def with_product_type(product)
162
+ if !Settings.test.product_type.include?(product)
163
+ raise "Unknown Product_type: #{product}, must be one of: #{Settings.test.product_type}"
164
+ end
165
+ @product_type = product
166
+ self
167
+ end
168
+
169
+ # The application will contain unique imageIds
170
+ # Allows images to be interacted with during test, e.g. deleted
171
+ def unique_images
172
+ @unique_images = true
173
+ self
174
+ end
175
+
176
+ def with_transaction_outcome(outcome)
177
+ @transaction_outcome = outcome
178
+ self
179
+ end
180
+
181
+ def build
182
+ # Sense check to ensure AWS credentials are present.
183
+ DVLA::Application.check_aws_credentials
184
+
185
+ check_application_validity
186
+
187
+ factory = if @processable
188
+ FM[:uodl_v2_processable_application]
189
+ else
190
+ non_processable_application_factory
191
+ end
192
+
193
+ # pass in uodl_v2 FM factory to build data attribute
194
+ app = factory.build(attributes: { data: FM[:uodl_v2_application_data].build }) do |b|
195
+ @driver_id = default_application_driver_id if @driver_id.nil?
196
+ update_driver_id!(b)
197
+
198
+ update_main_properties!(b)
199
+
200
+ update_driving_licence_actions!(b, application_driving_licence_actions)
201
+
202
+ b.data.customer_context = application_customer_context
203
+ update_customer_context!(b)
204
+
205
+ update_applicant!(b)
206
+ update_organ_donor!(b)
207
+
208
+ update_payments!(b)
209
+
210
+ update_no_fee!(b) unless @no_fee_application.nil?
211
+
212
+ b.images = application_images
213
+
214
+ calculate_default_update_reason
215
+
216
+ set_application_specific_fields!(b)
217
+ end
218
+
219
+ process_application_tasks(app)
220
+ process_application(app)
221
+
222
+ extend_deadline(app) if @extend_application_deadline
223
+
224
+ DVLA::Application::ApplicationDomain.retrieve_application_by_app_id(application_id: app.application_id)
225
+ end
226
+
227
+ # -- Overridable methods used by sub-types --
228
+
229
+ def check_application_validity
230
+ # Allows a sub-type to optionally run checks on the flags of the application before building any resourcses
231
+ end
232
+
233
+ def non_processable_application_factory
234
+ raise 'The specific application type builder should override this method and return the factory specific to the application type'
235
+ end
236
+
237
+ def default_application_driver_id
238
+ raise 'The specific application type builder should override this method and return the driver id specific for the application type, this usually is hardcoded in channel-api-stub'
239
+ end
240
+
241
+ # Allows a sub-type to specify any driving licence action specific to that application
242
+ def application_driving_licence_actions
243
+ {}
244
+ end
245
+
246
+ def application_images
247
+ raise 'The specific application type builder should override this method and return the images needed for the specific application type'
248
+ end
249
+
250
+ def application_customer_context
251
+ raise 'The specific application type builder should override this method and return the customer context of the specific application type'
252
+ end
253
+
254
+ def set_application_specific_fields!(app)
255
+ # Allows a sub-type to populate or override specific fields of an application
256
+ end
257
+
258
+ def process_application_tasks(app)
259
+ # Allows a sub-type to advance any tasks specific of the application type
260
+ end
261
+
262
+ private
263
+ # -- Methods allowing specific actions that occur during the application build process --
264
+ def update_main_properties!(app)
265
+ app.application_id = @application_id
266
+ app.customer_id = @customer_id if @customer_id
267
+ unless @processable
268
+ app.data_schema = Settings.application.v2_schema
269
+ app.product_type = @product_type
270
+ end
271
+ end
272
+
273
+ def update_driver_id!(app)
274
+ if @processable && @driver_id
275
+ app.driver_id = @driver_id
276
+ elsif @driver_id
277
+ app.product_id = @driver_id
278
+ app.product_key = @driver_id
279
+ end
280
+ end
281
+
282
+ def update_driving_licence_actions!(app, application_actions)
283
+ new_address = if @change_of_address || @free_key_address
284
+ { unstructuredAddress: FM[:application_unstructured_address].build }
285
+ elsif @bfpo_address
286
+ { bfpoAddress: FM[:bfpo_address].build }
287
+ end
288
+ unless new_address.nil?
289
+ app.data.driving_licence_actions[:updateAddress] = { newAddress: new_address }
290
+ end
291
+
292
+ app.data.driving_licence_actions.merge!(application_actions)
293
+
294
+ unless @driving_licence_actions.nil?
295
+ app.data.driving_licence_actions.merge!(@driving_licence_actions)
296
+ end
297
+ end
298
+
299
+ def update_customer_context!(app)
300
+ if !@processable && !@transaction_outcome.nil?
301
+ app.data.customer_context[:transactionOutcome] = @transaction_outcome
302
+ app.data.customer_context[:customerIntent] = @transaction_outcome
303
+ end
304
+ end
305
+
306
+ def update_applicant!(app)
307
+ app.data.applicant = @applicant if @applicant
308
+ app.data.applicant[:phoneNumber] = Faker::PhoneNumber.phone_number if @phone_number
309
+ app.data.applicant[:languagePreference] = 'Welsh' if @welsh_language
310
+ app.data.applicant[:identityTokenData][:confidenceLevel] = @identity_confidence_level
311
+ end
312
+
313
+ def update_organ_donor!(app)
314
+ app.data.organ_donor = if @organ_donor
315
+ set_any_organs(any_organs_bool: @organ_donor)
316
+ elsif @application_status == 'Rejected'
317
+ FM[:organ_donor_d90_response].build(attributes: { kidneys: true })
318
+ elsif @application_status == 'Returned'
319
+ FM[:organ_donor_d90_response].build(attributes: { cornea: true })
320
+ elsif @application_status == 'Unapproved'
321
+ FM[:organ_donor_d90_response].build(attributes: { heart: true })
322
+ else
323
+ {}
324
+ end
325
+ end
326
+
327
+ def update_payments!(app)
328
+ if !@processable && !@payments.nil?
329
+ app.payments = @payments
330
+ end
331
+ end
332
+
333
+ def update_no_fee!(app)
334
+ app.no_fee_application = true if @no_fee_application
335
+ end
336
+
337
+ def calculate_default_update_reason
338
+ if !@processable && !@application_status.nil? && @application_status == 'Cancelled'
339
+ @update_reason = @update_reason || 'Timed out'
340
+ end
341
+ end
342
+
343
+ def process_application(app)
344
+ if !@processable
345
+ DVLA::Application::ApplicationStatusProcessor.process_to(app.application_id, @application_status, update_reason: @update_reason)
346
+ end
347
+ end
348
+
349
+ # updates call to action date on domain
350
+ def extend_deadline(app)
351
+ extend_date = Time.now + 21.days
352
+ DVLA::Application.logger.info("Updating application call to action deadline date to: #{extend_date}".blue)
353
+ DVLA::Application::ApplicationDomain.update_call_to_action_deadline_date(application_id: app.application_id, call_to_action_deadline_date: extend_date.utc.iso8601)
354
+ end
355
+ end
356
+ end
357
+ end