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.
- checksums.yaml +7 -0
- data/.drone.yml +481 -0
- data/.env.template +4 -0
- data/.rspec +3 -0
- data/.rubocop.yml +21 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +674 -0
- data/Rakefile +31 -0
- data/config/settings/drone-dev.yml +41 -0
- data/config/settings/drone-ext.yml +35 -0
- data/config/settings/drone-link.yml +35 -0
- data/config/settings/drone-perf.yml +35 -0
- data/config/settings/local-dev.yml +40 -0
- data/config/settings/local-ext.yml +35 -0
- data/config/settings/local-link.yml +35 -0
- data/config/settings/local-perf.yml +35 -0
- data/config/settings.yml +29 -0
- data/config/yarp.yml +6 -0
- data/functional-tests/Rakefile +74 -0
- data/functional-tests/chutney.yml +110 -0
- data/functional-tests/features/codl.feature +170 -0
- data/functional-tests/features/codl_image_review_states.feature +140 -0
- data/functional-tests/features/csudl.feature +54 -0
- data/functional-tests/features/csudl_image_review_states.feature +20 -0
- data/functional-tests/features/step_definitions/app_domain_steps.rb +213 -0
- data/functional-tests/features/step_definitions/application_creation_steps.rb +115 -0
- data/functional-tests/features/step_definitions/image_steps.rb +144 -0
- data/functional-tests/features/step_definitions/state_machine_steps.rb +43 -0
- data/functional-tests/features/support/data/artefacts.rb +27 -0
- data/functional-tests/features/support/data/image_helpers.rb +20 -0
- data/functional-tests/features/support/data/schema_helpers.rb +3 -0
- data/functional-tests/features/support/data/string_manipulation.rb +9 -0
- data/functional-tests/features/support/env.rb +25 -0
- data/functional-tests/features/support/hooks.rb +56 -0
- data/functional-tests/features/support/yarp_integration/yarp_helpers.rb +23 -0
- data/functional-tests/features/uodl_image_review_states.feature +244 -0
- data/functional-tests/features/uodl_non_processable.feature +441 -0
- data/functional-tests/features/uodl_processable.feature +416 -0
- data/lib/dvla/application_helper/builders/V1/application_builder.rb +298 -0
- data/lib/dvla/application_helper/builders/V1/codl_application_builder.rb +205 -0
- data/lib/dvla/application_helper/builders/V1/csudl_application_builder.rb +329 -0
- data/lib/dvla/application_helper/builders/V2/base_uodl_v2_application_builder.rb +357 -0
- data/lib/dvla/application_helper/builders/V2/cop_v2_application_builder.rb +59 -0
- data/lib/dvla/application_helper/builders/V2/dup_v2_application_builder.rb +84 -0
- data/lib/dvla/application_helper/builders/V2/exc_v2_application_builder.rb +55 -0
- data/lib/dvla/application_helper/builders/V2/rep_v2_application_builder.rb +84 -0
- data/lib/dvla/application_helper/builders/V2/tyr_v2_application_builder.rb +62 -0
- data/lib/dvla/application_helper/builders/V2/uodl_v2_application_builder.rb +278 -0
- data/lib/dvla/application_helper/builders/V3/base_uodl_v3_application_builder.rb +342 -0
- data/lib/dvla/application_helper/builders/V3/cop_v3_application_builder.rb +56 -0
- data/lib/dvla/application_helper/builders/V3/dup_v3_application_builder.rb +78 -0
- data/lib/dvla/application_helper/builders/V3/exc_v3_application_builder.rb +56 -0
- data/lib/dvla/application_helper/builders/V3/rep_v3_application_builder.rb +81 -0
- data/lib/dvla/application_helper/builders/V3/tyr_v3_application_builder.rb +59 -0
- data/lib/dvla/application_helper/builders/dup_rep_builder_mixin.rb +71 -0
- data/lib/dvla/application_helper/builders/photo_builder_mixin.rb +49 -0
- data/lib/dvla/application_helper/builders/photo_signature_builder_mixin.rb +68 -0
- data/lib/dvla/application_helper/configuration.rb +37 -0
- data/lib/dvla/application_helper/constants.rb +21 -0
- data/lib/dvla/application_helper/enums/review_state.rb +30 -0
- data/lib/dvla/application_helper/enums/unable_to_prove_licence_possession_reasons.rb +8 -0
- data/lib/dvla/application_helper/factories/address.rb +21 -0
- data/lib/dvla/application_helper/factories/application_details.rb +353 -0
- data/lib/dvla/application_helper/factories/casework.rb +7 -0
- data/lib/dvla/application_helper/factories/csudl_photo_signature_image.rb +156 -0
- data/lib/dvla/application_helper/factories/csudl_photo_signature_images.rb +85 -0
- data/lib/dvla/application_helper/factories/organ_donor.rb +32 -0
- data/lib/dvla/application_helper/factories/person.rb +73 -0
- data/lib/dvla/application_helper/factories/photo_image.rb +147 -0
- data/lib/dvla/application_helper/factories/photo_images.rb +183 -0
- data/lib/dvla/application_helper/factories/photo_signature_image.rb +158 -0
- data/lib/dvla/application_helper/factories/photo_signature_images.rb +64 -0
- data/lib/dvla/application_helper/fixtures/photo/comparison_image.jpeg +0 -0
- data/lib/dvla/application_helper/fixtures/photo/passport_image.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/photo/photocard_back.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/photo/photocard_front.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/photo/rejected_user_uploaded_image.jpeg +0 -0
- data/lib/dvla/application_helper/fixtures/photo/user_uploaded_image.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/signature/csudl_signature_image.tiff +0 -0
- data/lib/dvla/application_helper/fixtures/signature/passport_image.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/signature/rejected_user_uploaded_image.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/signature/user_uploaded_image.jpg +0 -0
- data/lib/dvla/application_helper/processors/application_status.rb +45 -0
- data/lib/dvla/application_helper/processors/application_task.rb +301 -0
- data/lib/dvla/application_helper/services/application_diary.rb +123 -0
- data/lib/dvla/application_helper/services/application_domain.rb +239 -0
- data/lib/dvla/application_helper/services/application_process_engine.rb +120 -0
- data/lib/dvla/application_helper/services/check_aws_credentials.rb +24 -0
- data/lib/dvla/application_helper/services/driving_licence_channel_api.rb +67 -0
- data/lib/dvla/application_helper/services/image_service.rb +116 -0
- data/lib/dvla/application_helper/services/image_utility.rb +82 -0
- data/lib/dvla/application_helper/services/state_machine_helpers.rb +146 -0
- data/lib/dvla/application_helper/version.rb +5 -0
- data/lib/dvla/application_helper.rb +92 -0
- data/renovate.json +4 -0
- data/scripts/application-login.sh +56 -0
- data/scripts/drone-aws-login.sh +18 -0
- data/scripts/seed_application.rb +268 -0
- data/sonar-project.properties +4 -0
- metadata +343 -0
@@ -0,0 +1,298 @@
|
|
1
|
+
require_relative('../photo_builder_mixin.rb')
|
2
|
+
|
3
|
+
module DVLA
|
4
|
+
module Application
|
5
|
+
class ApplicationBuilder
|
6
|
+
# Including all properties and methods needed to support photos
|
7
|
+
include DVLA::Application::PhotoBuilderMixin
|
8
|
+
|
9
|
+
# Creates a new instance of the application builder
|
10
|
+
def initialize
|
11
|
+
@applicant = nil
|
12
|
+
@application_id = SecureRandom::uuid
|
13
|
+
@application_status = 'Preparing'
|
14
|
+
@bfpo_address = false
|
15
|
+
@change_of_address = false
|
16
|
+
@customer_id = nil
|
17
|
+
@driver_id = nil
|
18
|
+
@eligible_for_photo_renew = true
|
19
|
+
@extend_application_deadline = false
|
20
|
+
@free_key_address = false
|
21
|
+
@no_fee_application = false
|
22
|
+
@organ_donor = nil
|
23
|
+
@payments = nil
|
24
|
+
@processable = false
|
25
|
+
@product_type = 'Driving Licence'
|
26
|
+
@phone_number = false
|
27
|
+
@update_reason = nil
|
28
|
+
@unique_images = false
|
29
|
+
@welsh_language = false
|
30
|
+
init_photo_properties
|
31
|
+
end
|
32
|
+
|
33
|
+
# Some builder methods are automatically included from PhotoBuilderMixin
|
34
|
+
|
35
|
+
# Marks the application as processable, doing this will ensure that real services are used to create the
|
36
|
+
# application. For example, the channel api will process the tasks rather than stub data being provided.
|
37
|
+
# Whilst this results in a more complete application, this option is more expensive.
|
38
|
+
# Avoid excessive use in QA tests.
|
39
|
+
# @return [ApplicationBuilder]
|
40
|
+
def processable
|
41
|
+
@processable = true
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
# Marks the application as non-processable. This will result in the application being created using the test application endpoint.
|
46
|
+
# These applications cannot be actioned via the task service.
|
47
|
+
# This is typically the default option to be used.
|
48
|
+
# @return [ApplicationBuilder]
|
49
|
+
def non_processable
|
50
|
+
@processable = false
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
# APE uses very specific generated uuid to test with, the inspectable hooks filter the last 12 integers to return specific responses
|
55
|
+
# @param application_id [UUID]
|
56
|
+
def with_application_id(application_id)
|
57
|
+
@application_id = application_id
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
# The application will contain unique imageIds
|
62
|
+
# Allows images to be interacted with during test, e.g. deleted
|
63
|
+
def unique_images
|
64
|
+
@unique_images = true
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
# The application will contain a specific application status.
|
69
|
+
# How this state is reached will depend on if the application has been marked as processable or not.
|
70
|
+
# If processable is used here, we will also contain all actions.
|
71
|
+
# @param application_status [String] The application status the application should be in.
|
72
|
+
# @param update_reason [String] The reason for the change in status.
|
73
|
+
# @return [ApplicationBuilder]
|
74
|
+
def with_application_status(application_status, update_reason = nil)
|
75
|
+
@application_status = application_status
|
76
|
+
@update_reason = update_reason
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
# The application will contain a change of address.
|
81
|
+
# @return [ApplicationBuilder]
|
82
|
+
def with_change_of_address
|
83
|
+
@change_of_address = true
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
# The application will contain a bfpo address.
|
88
|
+
# @return [ApplicationBuilder]
|
89
|
+
def with_bfpo_address
|
90
|
+
@bfpo_address = true
|
91
|
+
self
|
92
|
+
end
|
93
|
+
|
94
|
+
# Allows specific product type to be passed in
|
95
|
+
# Used during APE testing for inspectable hooks
|
96
|
+
# @param product [Enum] one of: [Vehicles,Driving Licence,Test]
|
97
|
+
# @return [ApplicationBuilder]
|
98
|
+
def with_product_type(product)
|
99
|
+
@product_type = if Settings.test.product_type.include?(product)
|
100
|
+
product
|
101
|
+
else
|
102
|
+
DVLA::Application.logger.info("Unknown Product_type: #{product}, must be one of: #{Settings.test.product_type}\n Reverting product_type to 'Driving Licence'".red)
|
103
|
+
'Driving Licence'
|
104
|
+
end
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
# The application will contain a free key address.
|
109
|
+
# @return [ApplicationBuilder]
|
110
|
+
def with_free_key_address
|
111
|
+
@free_key_address = true
|
112
|
+
self
|
113
|
+
end
|
114
|
+
|
115
|
+
# The application will contain a phone number.
|
116
|
+
# @return [ApplicationBuilder]
|
117
|
+
def has_phone_number
|
118
|
+
@phone_number = true
|
119
|
+
self
|
120
|
+
end
|
121
|
+
|
122
|
+
# Sets the organ donor status of the application.
|
123
|
+
# By default, no organ donation is made
|
124
|
+
# Passing true will cause all_organs to be selected.
|
125
|
+
# Passing false will ensure no organs are selected.
|
126
|
+
# @param donor [boolean] Organ donor status.
|
127
|
+
# @return [ApplicationBuilder]
|
128
|
+
def is_organ_donor(donor)
|
129
|
+
@organ_donor = donor
|
130
|
+
self
|
131
|
+
end
|
132
|
+
|
133
|
+
def is_welsh_language
|
134
|
+
@welsh_language = true
|
135
|
+
self
|
136
|
+
end
|
137
|
+
|
138
|
+
# The application will contain the provided payments.
|
139
|
+
# @param payments [PaymentObject] Payment status.
|
140
|
+
# @return [ApplicationBuilder]
|
141
|
+
def with_payments(payments)
|
142
|
+
@payments = payments
|
143
|
+
self
|
144
|
+
end
|
145
|
+
|
146
|
+
# The application will contain the provided applicant data.
|
147
|
+
# @param applicant [ApplicantObject] Application data.
|
148
|
+
# @return [ApplicationBuilder]
|
149
|
+
def with_applicant(applicant)
|
150
|
+
@applicant = applicant
|
151
|
+
self
|
152
|
+
end
|
153
|
+
|
154
|
+
# The application will be made for the given customer
|
155
|
+
# @param customer_id [String] The customer ID to use
|
156
|
+
# @return [ApplicationBuilder]
|
157
|
+
def with_customer_id(customer_id)
|
158
|
+
@customer_id = customer_id
|
159
|
+
self
|
160
|
+
end
|
161
|
+
|
162
|
+
# The application will be made for the given driver
|
163
|
+
# @param driver_id [String] The driver ID to use
|
164
|
+
# @return [ApplicationBuilder]
|
165
|
+
def with_driver_id(driver_id)
|
166
|
+
@driver_id = driver_id
|
167
|
+
self
|
168
|
+
end
|
169
|
+
|
170
|
+
# The application will be a no fee application
|
171
|
+
# @param no_fee [Boolean] If the application should be no-fee. Defaults to true.
|
172
|
+
# @return [ApplicationBuilder]
|
173
|
+
def set_no_fee_application(no_fee: true)
|
174
|
+
@no_fee_application = no_fee
|
175
|
+
self
|
176
|
+
end
|
177
|
+
|
178
|
+
# The application will be updated with a call to action field which is used to extend an application
|
179
|
+
def extend_application_deadline
|
180
|
+
@extend_application_deadline = true
|
181
|
+
self
|
182
|
+
end
|
183
|
+
|
184
|
+
# Builds the Application base on the current criteria.
|
185
|
+
# @return [RetrieveApplicationResponse]
|
186
|
+
def build
|
187
|
+
# Sense check to ensure AWS credentials are present.
|
188
|
+
DVLA::Application.check_aws_credentials
|
189
|
+
|
190
|
+
factory = if @processable
|
191
|
+
FM[:uodl_processable_application]
|
192
|
+
else
|
193
|
+
FM[:application]
|
194
|
+
end
|
195
|
+
|
196
|
+
images = generate_photo_images(@processable, @unique_images)
|
197
|
+
|
198
|
+
app = factory.build do |b|
|
199
|
+
b.application_id = @application_id
|
200
|
+
b.customer_id = @customer_id if @customer_id
|
201
|
+
b.images = images
|
202
|
+
b.no_fee_application = true if @no_fee_application
|
203
|
+
|
204
|
+
if @eligible_for_photo_renew
|
205
|
+
b.data.driving_licence_actions[:renewLicence] = { reason: 'Photo Expiry' }
|
206
|
+
else
|
207
|
+
# update driverId static uuid if not eligible for TYR for use in next if statement
|
208
|
+
b.data.was_required_at_time_of_submission = false
|
209
|
+
end
|
210
|
+
|
211
|
+
# changes @driverId to an always cop static id if not eligible for TYR or Replacement_licence flags set
|
212
|
+
if @driver_id.nil?
|
213
|
+
@driver_id = if @eligible_for_photo_renew
|
214
|
+
Settings.test.driver_id.mandatory_tyr
|
215
|
+
else
|
216
|
+
Settings.test.driver_id.optional_cop
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
if @processable && @driver_id
|
221
|
+
b.driver_id = @driver_id
|
222
|
+
elsif !@processable
|
223
|
+
b.product_id = @driver_id
|
224
|
+
b.product_key = @driver_id
|
225
|
+
end
|
226
|
+
|
227
|
+
if !@processable
|
228
|
+
b.data_schema = Settings.application.v1_schema
|
229
|
+
b.application_type = 'Photo Renewal'
|
230
|
+
b.product_type = @product_type
|
231
|
+
end
|
232
|
+
|
233
|
+
if @change_of_address || @free_key_address || !@eligible_for_photo_renew
|
234
|
+
b.data.driving_licence_actions[:updateAddress] = {
|
235
|
+
newAddress: {
|
236
|
+
unstructuredAddress: FM[:application_unstructured_address].build,
|
237
|
+
},
|
238
|
+
}
|
239
|
+
elsif @bfpo_address
|
240
|
+
b.data.driving_licence_actions[:updateAddress] = {
|
241
|
+
newAddress: {
|
242
|
+
bfpoAddress: FM[:bfpo_address].build,
|
243
|
+
},
|
244
|
+
}
|
245
|
+
end
|
246
|
+
b.data.applicant = @applicant if @applicant
|
247
|
+
b.data.applicant[:phoneNumber] = Faker::PhoneNumber.phone_number if @phone_number
|
248
|
+
|
249
|
+
if @welsh_language
|
250
|
+
b.data.applicant[:languagePreference] = 'Welsh'
|
251
|
+
end
|
252
|
+
|
253
|
+
if !@processable && !@payments.nil?
|
254
|
+
b.payments = @payments
|
255
|
+
end
|
256
|
+
|
257
|
+
if !@processable && !@application_status.nil?
|
258
|
+
@update_reason = if @application_status == 'Cancelled'
|
259
|
+
@update_reason || 'Timed out'
|
260
|
+
elsif @application_status == 'Rejected'
|
261
|
+
b.data.organ_donor = FM[:organ_donor_d90_response].build(attributes: { kidneys: true })
|
262
|
+
elsif @application_status == 'Returned'
|
263
|
+
b.data.organ_donor = FM[:organ_donor_d90_response].build(attributes: { cornea: true })
|
264
|
+
elsif @application_status == 'Unapproved'
|
265
|
+
b.data.organ_donor = FM[:organ_donor_d90_response].build(attributes: { heart: true })
|
266
|
+
elsif @organ_donor
|
267
|
+
b.data.organ_donor = set_any_organs(any_organs_bool: @organ_donor)
|
268
|
+
else
|
269
|
+
b.data.organ_donor = {}
|
270
|
+
end
|
271
|
+
elsif @processable && @organ_donor
|
272
|
+
b.data.organ_donor = set_any_organs(any_organs_bool: @organ_donor)
|
273
|
+
else
|
274
|
+
b.data.organ_donor = {}
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
if @processable
|
279
|
+
process_photo_tasks(app)
|
280
|
+
else
|
281
|
+
DVLA::Application::ApplicationStatusProcessor.process_to(app.application_id, @application_status, update_reason: @update_reason)
|
282
|
+
end
|
283
|
+
|
284
|
+
# updates call to action date on domain
|
285
|
+
if @extend_application_deadline
|
286
|
+
extend_date = Time.now + 21.days
|
287
|
+
DVLA::Application.logger.info("Updating application call to action deadline date to: #{extend_date}".blue)
|
288
|
+
DVLA::Application::ApplicationDomain.update_call_to_action_deadline_date(application_id: app.application_id, call_to_action_deadline_date: extend_date.utc.iso8601)
|
289
|
+
end
|
290
|
+
|
291
|
+
DVLA::Application::ApplicationDomain.retrieve_application_by_app_id(application_id: app.application_id)
|
292
|
+
end
|
293
|
+
|
294
|
+
extend Gem::Deprecate
|
295
|
+
deprecate(:build, 'TYRApplicationBuilder#build', 2025, 12)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require_relative('../photo_signature_builder_mixin.rb')
|
2
|
+
|
3
|
+
module DVLA
|
4
|
+
module Application
|
5
|
+
class CODLApplicationBuilder
|
6
|
+
# Including all properties and methods needed to support photos and signatures
|
7
|
+
include DVLA::Application::PhotoSignatureBuilderMixin
|
8
|
+
|
9
|
+
# Creates a new instance of the application builder
|
10
|
+
def initialize
|
11
|
+
@applicant = nil
|
12
|
+
@application_status = 'Preparing'
|
13
|
+
@customer_id = nil
|
14
|
+
@extend_application_deadline = false
|
15
|
+
@identity_confidence_level = 'MEDIUM'
|
16
|
+
@organ_donor = nil
|
17
|
+
@payments = nil
|
18
|
+
@processable = false
|
19
|
+
@phone_number = false
|
20
|
+
@unique_images = false
|
21
|
+
@update_reason = nil
|
22
|
+
init_photo_signature_properties
|
23
|
+
end
|
24
|
+
|
25
|
+
# Some builder methods are automatically included from PhotoSignatureBuilderMixin
|
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 [ApplicationBuilder]
|
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 [ApplicationBuilder]
|
41
|
+
def non_processable
|
42
|
+
@processable = false
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def with_low_confidence_level
|
47
|
+
@identity_confidence_level = 'LOW'
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
# The application will contain the provided applicant data.
|
52
|
+
# @param applicant [ApplicantObject] Application data.
|
53
|
+
# @return [ApplicationBuilder]
|
54
|
+
def with_applicant(applicant)
|
55
|
+
@applicant = applicant
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
# The application will contain the provided payments.
|
60
|
+
# @param payments [PaymentObject] Payment status.
|
61
|
+
# @return [ApplicationBuilder]
|
62
|
+
def with_payments(payments)
|
63
|
+
@payments = payments
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
# The application will contain unique imageIds
|
68
|
+
# Allows images to be interacted with during test, e.g. deleted
|
69
|
+
def unique_images
|
70
|
+
@unique_images = true
|
71
|
+
self
|
72
|
+
end
|
73
|
+
|
74
|
+
# The application will contain a specific application status.
|
75
|
+
# How this state is reached will depend on if the application has been marked as processable or not.
|
76
|
+
# If processable is used here, we will also contain all actions.
|
77
|
+
# @param application_status [String] The application status the application should be in.
|
78
|
+
# @param update_reason [String] The reason for the change in status.
|
79
|
+
# @return [ApplicationBuilder]
|
80
|
+
def with_application_status(application_status, update_reason = nil)
|
81
|
+
@application_status = application_status
|
82
|
+
@update_reason = update_reason
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
# The application will be made for the given customer
|
87
|
+
# @param customer_id [String] The customer ID to use
|
88
|
+
# @return [ApplicationBuilder]
|
89
|
+
def with_customer_id(customer_id)
|
90
|
+
@customer_id = customer_id
|
91
|
+
self
|
92
|
+
end
|
93
|
+
|
94
|
+
# The application contains passport photo and signature to the applicant to be submitted. Disables user photo and user signature.
|
95
|
+
# @return [ApplicationBuilder]
|
96
|
+
def with_passport_images
|
97
|
+
@with_passport_images = true
|
98
|
+
self
|
99
|
+
end
|
100
|
+
|
101
|
+
def extend_application_deadline
|
102
|
+
@extend_application_deadline = true
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
# The application will contain a phone number.
|
107
|
+
# @return [ApplicationBuilder]
|
108
|
+
def has_phone_number
|
109
|
+
@phone_number = true
|
110
|
+
self
|
111
|
+
end
|
112
|
+
|
113
|
+
# Sets the organ donor status of the application.
|
114
|
+
# By default, a random selection is made.
|
115
|
+
# Passing true will cause all_organs to be selected.
|
116
|
+
# Passing false will ensure no organs are selected.
|
117
|
+
# @param donor [boolean] Organ donor status.
|
118
|
+
# @return [ApplicationBuilder]
|
119
|
+
def is_organ_donor(donor)
|
120
|
+
@organ_donor = donor
|
121
|
+
self
|
122
|
+
end
|
123
|
+
|
124
|
+
# Builds the Application base on the current criteria.
|
125
|
+
# @return [RetrieveApplicationResponse]
|
126
|
+
def build
|
127
|
+
# Sense check to ensure AWS credentials are present.
|
128
|
+
DVLA::Application.check_aws_credentials
|
129
|
+
|
130
|
+
factory = if @processable
|
131
|
+
FM[:codl_processable_application]
|
132
|
+
else
|
133
|
+
FM[:codl_application]
|
134
|
+
end
|
135
|
+
|
136
|
+
app = factory.build do |b|
|
137
|
+
b.customer_id = @customer_id if @customer_id
|
138
|
+
|
139
|
+
update_applicant!(b)
|
140
|
+
update_organ_donor!(b)
|
141
|
+
|
142
|
+
if !@processable && !@payments.nil?
|
143
|
+
b.payments = @payments
|
144
|
+
end
|
145
|
+
|
146
|
+
calculate_default_update_reason!
|
147
|
+
|
148
|
+
b.images = generate_photo_signature_images(@processable, @unique_images)
|
149
|
+
end
|
150
|
+
|
151
|
+
process_application_and_tasks(app)
|
152
|
+
|
153
|
+
extend_deadline(app) if @extend_application_deadline
|
154
|
+
|
155
|
+
DVLA::Application::ApplicationDomain.retrieve_application_by_app_id(application_id: app.application_id)
|
156
|
+
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
def calculate_default_update_reason!
|
161
|
+
if !@application_status.nil?
|
162
|
+
@update_reason = if @application_status == 'Cancelled'
|
163
|
+
@update_reason || 'Timed out'
|
164
|
+
else
|
165
|
+
nil
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def update_applicant!(app)
|
171
|
+
app.data.applicant = @applicant if @applicant
|
172
|
+
app.data.applicant[:phoneNumber] = Faker::PhoneNumber.phone_number if @phone_number
|
173
|
+
app.data.applicant[:identityTokenData][:confidenceLevel] = @identity_confidence_level
|
174
|
+
end
|
175
|
+
|
176
|
+
def update_organ_donor!(app)
|
177
|
+
app.data.organ_donor = if @organ_donor
|
178
|
+
set_any_organs(any_organs_bool: @organ_donor)
|
179
|
+
elsif @application_status == 'Rejected'
|
180
|
+
FM[:organ_donor_d90_response].build(attributes: { kidneys: true })
|
181
|
+
elsif @application_status == 'Returned'
|
182
|
+
FM[:organ_donor_d90_response].build(attributes: { cornea: true })
|
183
|
+
elsif @application_status == 'Unapproved'
|
184
|
+
FM[:organ_donor_d90_response].build(attributes: { heart: true })
|
185
|
+
else
|
186
|
+
{}
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def process_application_and_tasks(app)
|
191
|
+
if @processable
|
192
|
+
process_photo_signature_tasks(app)
|
193
|
+
elsif !@processable && !@application_status.nil?
|
194
|
+
DVLA::Application::ApplicationStatusProcessor.process_to(app.application_id, @application_status, update_reason: @update_reason)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def extend_deadline(app)
|
199
|
+
extend_date = Time.now + 21.days
|
200
|
+
DVLA::Application.logger.info("Updating application call to action deadline date to: #{extend_date}".blue)
|
201
|
+
DVLA::Application::ApplicationDomain.update_call_to_action_deadline_date(application_id: app.application_id, call_to_action_deadline_date: extend_date.utc.iso8601)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|