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,59 @@
1
+ require_relative('../photo_signature_builder_mixin.rb')
2
+
3
+ module DVLA
4
+ module Application
5
+ class COPV2ApplicationBuilder < BaseUODLV2ApplicationBuilder
6
+ # Including all properties and methods needed to support photos
7
+ include DVLA::Application::PhotoBuilderMixin
8
+
9
+ def initialize
10
+ init_photo_properties
11
+ super
12
+ end
13
+
14
+ # Some builder methods are automatically included from PhotoBuilderMixin
15
+
16
+ # -- Overridden methods --
17
+
18
+ # Defining the non-processable application factory that the BaseUODLV2ApplicationBuilder will use
19
+ def non_processable_application_factory
20
+ FM[:cop_application]
21
+ end
22
+
23
+ # Defining the default driver_id, used to pass the validation in channel-api-stub
24
+ def default_application_driver_id
25
+ Settings.test.driver_id.optional_cop
26
+ end
27
+
28
+ def application_driving_licence_actions
29
+ { renewLicence: { reason: 'Update Photo' } }
30
+ end
31
+
32
+ # Defining the data to put in customer_context
33
+ def application_customer_context
34
+ {
35
+ customerIntent: 'Change of photo',
36
+ transactionOutcome: 'Change of photo',
37
+ applicationsEligibilityResponse: [{
38
+ applicationType: 'update-ordinary-licence',
39
+ isRequired: true,
40
+ availableActions: [
41
+ actionType: 'update-photo',
42
+ isRequired: true,
43
+ ],
44
+ }],
45
+ }
46
+ end
47
+
48
+ # Creating the images that the BaseUODLV2ApplicationBuilder will include in the app
49
+ def application_images
50
+ generate_photo_images(@processable, @unique_images)
51
+ end
52
+
53
+ # Advance and submits the tasks based on the photo review state specified
54
+ def process_application_tasks(app)
55
+ process_photo_tasks(app) if @processable
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,84 @@
1
+ require_relative('../photo_signature_builder_mixin.rb')
2
+ require_relative('../dup_rep_builder_mixin.rb')
3
+
4
+ module DVLA
5
+ module Application
6
+ class DUPV2ApplicationBuilder < BaseUODLV2ApplicationBuilder
7
+ # Including all properties and methods needed to support photos and signatures in the case of a Paper DUP
8
+ include DVLA::Application::PhotoSignatureBuilderMixin
9
+ include DVLA::Application::DupRepBuilderMixin
10
+
11
+ def initialize
12
+ dup_rep_init_properties
13
+ init_photo_signature_properties
14
+ super
15
+ end
16
+
17
+ # -- Builder methods --
18
+
19
+ # Some builder methods are automatically included from PhotoSignatureBuilderMixin and DupRepBuilderMixin
20
+
21
+ # Acts as if the licence owner has a paper licence.
22
+ # The application will be eligible to be changed from a paper licence to a plastic one
23
+ # It will also upload a photo and a signature with the application, and enable the flags to control these images and their tasks
24
+ # Sets the driver id to the specific id required for channel api stub to recognise
25
+ # @return [DUPV2ApplicationBuilder]
26
+ def with_paper_to_plastic_driver_id
27
+ @eligibility_paper_to_plastic = true
28
+ @driver_id = Settings.test.driver_id.paper_duplicate
29
+ self
30
+ end
31
+
32
+ # -- Overridden methods --
33
+
34
+ # Defining the non-processable application factory that the BaseUODLV2ApplicationBuilder will use
35
+ def non_processable_application_factory
36
+ FM[:dup_application]
37
+ end
38
+
39
+ # Defining the default driver_id, used to pass the validation in channel-api-stub
40
+ def default_application_driver_id
41
+ Settings.test.driver_id.always_duplicate
42
+ end
43
+
44
+ def application_driving_licence_actions
45
+ # Set a change of address action for all DUP applications
46
+ { updateAddress: { newAddress: { unstructuredAddress: FM[:application_unstructured_address].build } } }
47
+ end
48
+
49
+ # Defining the data to put in customer_context
50
+ def application_customer_context
51
+ {
52
+ customerIntent: 'Duplicate licence',
53
+ transactionOutcome: 'Duplicate licence',
54
+ applicationsEligibilityResponse: [{
55
+ applicationType: 'update-ordinary-licence',
56
+ isRequired: true,
57
+ availableActions: [
58
+ actionType: 'update-photo',
59
+ isRequired: false,
60
+ ],
61
+ }],
62
+ }
63
+ end
64
+
65
+ def set_application_specific_fields!(app)
66
+ # Only set unable_to_prove_licence_possession_reason for non-EXCHANGE-PAPER-LICENCE cases
67
+ unless @driver_id == '21b6e437-8f0c-42ae-8b61-62d53f377841'
68
+ app.data.unable_to_prove_licence_possession_reason = 'LOST_OR_STOLEN'
69
+ end
70
+
71
+ unless @unable_to_prove_licence_possession_reason.nil?
72
+ app.data.unable_to_prove_licence_possession_reason = @unable_to_prove_licence_possession_reason
73
+ end
74
+
75
+ if @eligibility_paper_to_plastic
76
+ app.data.customer_context[:applicationsEligibilityResponse][0][:availableActions].push({
77
+ actionType: 'inform-paper-to-plastic',
78
+ isRequired: true,
79
+ })
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,55 @@
1
+ require_relative('../photo_signature_builder_mixin.rb')
2
+
3
+ module DVLA
4
+ module Application
5
+ class EXCV2ApplicationBuilder < BaseUODLV2ApplicationBuilder
6
+ # Including all properties and methods needed to support photos and signatures
7
+ include DVLA::Application::PhotoSignatureBuilderMixin
8
+
9
+ def initialize
10
+ init_photo_signature_properties
11
+ super
12
+ end
13
+
14
+ # Some builder methods are automatically included from PhotoSignatureBuilderMixin
15
+
16
+ # -- Overridden methods --
17
+
18
+ # Defining the non-processable application factory that the BaseUODLV2ApplicationBuilder will use
19
+ def non_processable_application_factory
20
+ FM[:exc_application]
21
+ end
22
+
23
+ # Defining the default driver_id, used to pass the validation in channel-api-stub
24
+ def default_application_driver_id
25
+ Settings.test.driver_id.always_exchange
26
+ end
27
+
28
+ # Defining the data to put in customer_context
29
+ def application_customer_context
30
+ {
31
+ customerIntent: 'Paper to photocard',
32
+ transactionOutcome: 'Paper to photocard',
33
+ applicationsEligibilityResponse: [{
34
+ applicationType: 'update-ordinary-licence',
35
+ isRequired: true,
36
+ availableActions: [
37
+ actionType: 'inform-paper-to-plastic',
38
+ isRequired: true,
39
+ ],
40
+ }],
41
+ }
42
+ end
43
+
44
+ # Creating the images that the BaseUODLV2ApplicationBuilder will include in the app
45
+ def application_images
46
+ generate_photo_signature_images(@processable, @unique_images)
47
+ end
48
+
49
+ # Advance and submits the tasks based on the photo and signature review state specified
50
+ def process_application_tasks(app)
51
+ process_photo_signature_tasks(app) if @processable
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,84 @@
1
+ require_relative('../photo_signature_builder_mixin.rb')
2
+ require_relative('../dup_rep_builder_mixin.rb')
3
+
4
+ module DVLA
5
+ module Application
6
+ class REPV2ApplicationBuilder < BaseUODLV2ApplicationBuilder
7
+ # Including all properties and methods needed to support photos and signatures in the case of a Paper DUP
8
+ include DVLA::Application::PhotoSignatureBuilderMixin
9
+ include DVLA::Application::DupRepBuilderMixin
10
+
11
+
12
+ def initialize
13
+ @unable_to_prove_licence_possession_reason = nil
14
+ @eligibility_paper_to_plastic = false
15
+ init_photo_signature_properties
16
+ super
17
+ end
18
+
19
+ # -- Builder methods --
20
+
21
+ # Some builder methods are automatically included from PhotoSignatureBuilderMixin
22
+
23
+
24
+ # Acts as if the licence owner has a paper licence.
25
+ # The application will be eligible to be changed from a paper licence to a plastic one and therefore have a normal fee
26
+ # It will also upload a photo and a signature with the application, and enable the flags to control these images and their tasks
27
+ # Sets the driver id to the specific id required for channel api stub to recognise
28
+ # @return [REPV2ApplicationBuilder]
29
+ def with_paper_to_plastic_driver_id
30
+ @eligibility_paper_to_plastic = true
31
+ @driver_id = Settings.test.driver_id.paper_replacement
32
+ self
33
+ end
34
+
35
+ # -- Overridden methods --
36
+
37
+ # Defining the non-processable application factory that the BaseUODLV2ApplicationBuilder will use
38
+ def non_processable_application_factory
39
+ FM[:rep_application]
40
+ end
41
+
42
+ # Defining the default driver_id, used to pass the validation in channel-api-stub
43
+ def default_application_driver_id
44
+ Settings.test.driver_id.always_replacement
45
+ end
46
+
47
+ def application_driving_licence_actions
48
+ # Set a change of address action for all REP applications
49
+ { updateAddress: { newAddress: { unstructuredAddress: FM[:application_unstructured_address].build } } }
50
+ end
51
+
52
+ # Defining the data to put in customer_context
53
+ def application_customer_context
54
+ {
55
+ customerIntent: 'Change of details',
56
+ transactionOutcome: 'Change of details',
57
+ applicationsEligibilityResponse: [{
58
+ applicationType: 'update-ordinary-licence',
59
+ isRequired: true,
60
+ availableActions: [
61
+ actionType: 'update-address',
62
+ isRequired: true,
63
+ ],
64
+ }],
65
+ }
66
+ end
67
+
68
+ def set_application_specific_fields!(app)
69
+ unless @unable_to_prove_licence_possession_reason.nil?
70
+ app.data.unable_to_prove_licence_possession_reason = @unable_to_prove_licence_possession_reason
71
+ end
72
+
73
+ app.no_fee_application = true
74
+
75
+ if @eligibility_paper_to_plastic
76
+ app.data.customer_context[:applicationsEligibilityResponse][0][:availableActions].push({
77
+ actionType: 'inform-paper-to-plastic',
78
+ isRequired: true,
79
+ })
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,62 @@
1
+ require_relative('../photo_signature_builder_mixin.rb')
2
+
3
+ module DVLA
4
+ module Application
5
+ class TYRV2ApplicationBuilder < BaseUODLV2ApplicationBuilder
6
+ # Including all properties and methods needed to support photos
7
+ include DVLA::Application::PhotoBuilderMixin
8
+
9
+ def initialize
10
+ @no_fee_application = false
11
+ init_photo_properties
12
+ super
13
+ end
14
+
15
+ # The application will be a no fee application
16
+ # @param no_fee [Boolean] If the application should be no-fee. Defaults to true.
17
+ # @return [TYRV2ApplicationBuilder]
18
+ def set_no_fee_application(no_fee: true)
19
+ @no_fee_application = no_fee
20
+ self
21
+ end
22
+
23
+ # -- Overridden methods --
24
+
25
+ def application_images
26
+ generate_photo_images(@processable, @unique_images)
27
+ end
28
+
29
+ def application_customer_context
30
+ {
31
+ customerIntent: 'Ten year renewal',
32
+ transactionOutcome: 'Ten year renewal',
33
+ applicationsEligibilityResponse: [{
34
+ applicationType: 'update-ordinary-licence',
35
+ isRequired: true,
36
+ availableActions: [
37
+ actionType: 'update-photo',
38
+ isRequired: true,
39
+ ],
40
+ }],
41
+ }
42
+ end
43
+
44
+ def non_processable_application_factory
45
+ FM[:tyr_application]
46
+ end
47
+
48
+ def default_application_driver_id
49
+ Settings.test.driver_id.mandatory_tyr
50
+ end
51
+
52
+ def application_driving_licence_actions
53
+ { renewLicence: { reason: 'Photo Expiry' } }
54
+ end
55
+
56
+ def process_application_tasks(app)
57
+ process_photo_tasks(app) if @processable
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,278 @@
1
+ module DVLA
2
+ module Application
3
+ class UODLV2ApplicationBuilder < ApplicationBuilder
4
+ def initialize
5
+ @change_of_photo = false
6
+ @duplicate = false
7
+ @driving_licence_actions = nil
8
+ @eligibility_paper_to_plastic = false
9
+ @surrender_entitlement = false
10
+ @replacement_licence = false
11
+ @transaction_outcome = nil
12
+ @unable_to_prove_licence_possession_reason = nil
13
+ super
14
+ end
15
+
16
+ def change_of_photo
17
+ @change_of_photo = true
18
+ @eligible_for_photo_renew = false
19
+ if @no_fee_application
20
+ DVLA::Application.logger.info('A Change if photo application must have a FEE'.blue)
21
+ @no_fee_application = false
22
+ end
23
+ self
24
+ end
25
+
26
+ def duplicate_licence
27
+ @duplicate = true
28
+ @eligible_for_photo_renew = false
29
+ if @no_fee_application
30
+ DVLA::Application.logger.info('A Duplicate application must have a FEE'.blue)
31
+ @no_fee_application = false
32
+ end
33
+ self
34
+ end
35
+
36
+ def eligible_paper_to_plastic
37
+ @eligibility_paper_to_plastic = true
38
+ self
39
+ end
40
+
41
+ def replacement_licence
42
+ @replacement_licence = true
43
+ @eligible_for_photo_renew = false
44
+ # a rep application is a free application, so i will ensure this here
45
+ unless @no_fee_application
46
+ DVLA::Application.logger.info('A Replacement application must be NO-FEE, no_fee flag will be added'.blue)
47
+ @no_fee_application = true
48
+ end
49
+ self
50
+ end
51
+
52
+ # Adds the customer provided reason for not being able to prove licence possession to the application
53
+ # @param reason [DVLA::Application::UnableToProveLicencePossessionReasons] the reason for not being able to prove licence possession
54
+ # @return [UODLV2ApplicationBuilder]
55
+ def with_unable_to_prove_licence_possession_reason(reason)
56
+ @unable_to_prove_licence_possession_reason = reason
57
+ self
58
+ end
59
+
60
+ def with_transaction_outcome(outcome)
61
+ @transaction_outcome = outcome
62
+ self
63
+ end
64
+
65
+ def with_driving_licence_actions(action)
66
+ @driving_licence_actions = action
67
+ self
68
+ end
69
+
70
+ def build
71
+ # Sense check to ensure AWS credentials are present.
72
+ DVLA::Application.check_aws_credentials
73
+
74
+ factory = if @processable
75
+ FM[:uodl_v2_processable_application]
76
+ elsif @replacement_licence && @no_fee_application
77
+ FM[:rep_application]
78
+ elsif @duplicate
79
+ FM[:dup_application]
80
+ elsif @change_of_photo
81
+ FM[:cop_application]
82
+ else
83
+ FM[:application]
84
+ end
85
+
86
+ # this conditional has been added to handle REP (replacement licence)
87
+ if @replacement_licence || @duplicate
88
+ images = []
89
+ else
90
+ images = generate_photo_images(@processable, @unique_images)
91
+ end
92
+
93
+ # pass in uodl_v2 FM factory to build data attribute
94
+ app = factory.build(attributes: { data: FM[:uodl_v2_application_data].build, no_fee_application: @no_fee_application }) do |b|
95
+ b.application_id = @application_id
96
+ b.customer_id = @customer_id if @customer_id
97
+ b.data.applicant = @applicant if @applicant
98
+ b.data.applicant[:phoneNumber] = Faker::PhoneNumber.phone_number if @phone_number
99
+
100
+ # if eligible for photo renew, update action accordingly
101
+ b.data.driving_licence_actions[:renewLicence] = { reason: 'Photo Expiry' } if @eligible_for_photo_renew
102
+
103
+ # Adds in updatephoto action for eligible for TYR and change of photo app types
104
+ # b.data.driving_licence_actions[:updatePhoto] = { photographImageId: '617d6689-e03e-44e7-962d-ceb6e158e031' } if @eligible_for_photo_renew || @change_of_photo
105
+ b.data.driving_licence_actions[:renewLicence] = { reason: 'Update Photo' } if @change_of_photo
106
+
107
+ # changes @driverId to an always cop static id if not eligible for TYR or Replacement_licence flags set
108
+ if @driver_id.nil?
109
+ @driver_id = if @duplicate
110
+ Settings.test.driver_id.always_duplicate
111
+ elsif @replacement_licence
112
+ Settings.test.driver_id.always_replacement
113
+ elsif !@eligible_for_photo_renew
114
+ Settings.test.driver_id.optional_cop
115
+ else
116
+ Settings.test.driver_id.mandatory_tyr
117
+ end
118
+ end
119
+
120
+ if @processable && @driver_id
121
+ b.driver_id = @driver_id
122
+ elsif !@processable && @driver_id
123
+ b.product_id = @driver_id
124
+ b.product_key = @driver_id
125
+ end
126
+
127
+ unless @processable
128
+ b.data_schema = Settings.application.v2_schema
129
+ b.product_type = @product_type
130
+ if !@processable && !@transaction_outcome.nil?
131
+ b.data.customer_context[:transactionOutcome] = @transaction_outcome
132
+ b.data.customer_context[:customerIntent] = @transaction_outcome
133
+ end
134
+ end
135
+
136
+ unless @driving_licence_actions.nil?
137
+ b.data.driving_licence_actions = @driving_licence_actions
138
+ end
139
+
140
+ # updates driving licence actions
141
+ if @change_of_address || @free_key_address || @replacement_licence || @duplicate
142
+ b.data.driving_licence_actions[:updateAddress] = {
143
+ newAddress: {
144
+ unstructuredAddress: FM[:application_unstructured_address].build,
145
+ },
146
+ }
147
+ elsif @bfpo_address
148
+ b.data.driving_licence_actions[:updateAddress] = {
149
+ newAddress: {
150
+ bfpoAddress: FM[:bfpo_address].build,
151
+ },
152
+ }
153
+ end
154
+
155
+ # Ensure DUP has a licence possession reason
156
+ if @duplicate && @unable_to_prove_licence_possession_reason.nil?
157
+ b.data.unable_to_prove_licence_possession_reason = 'LOST_OR_STOLEN'
158
+ end
159
+
160
+ # builds customer context for rep licence
161
+ if @replacement_licence
162
+ b.data.customer_context = {
163
+ customerIntent: 'Change of details',
164
+ applicationsEligibilityResponse: [{
165
+ applicationType: 'update-ordinary-licence',
166
+ isRequired: true,
167
+ availableActions: [
168
+ actionType: 'update-address',
169
+ isRequired: true,
170
+ ],
171
+ }],
172
+ transactionOutcome: 'Change of details',
173
+ }
174
+ end
175
+
176
+ # builds customer context for dup licence
177
+ if @duplicate
178
+ b.data.customer_context = {
179
+ customerIntent: 'Duplicate licence',
180
+ applicationsEligibilityResponse: [{
181
+ applicationType: 'update-ordinary-licence',
182
+ isRequired: true,
183
+ availableActions: [
184
+ actionType: 'update-photo',
185
+ isRequired: false,
186
+ ],
187
+ }],
188
+ transactionOutcome: 'Duplicate licence',
189
+ }
190
+ end
191
+
192
+ # builds customer context for change of photo
193
+ if @change_of_photo
194
+ b.data.customer_context = {
195
+ customerIntent: 'Change of photo',
196
+ applicationsEligibilityResponse: [{
197
+ applicationType: 'update-ordinary-licence',
198
+ isRequired: true,
199
+ availableActions: [
200
+ actionType: 'update-photo',
201
+ isRequired: true,
202
+ ],
203
+ }],
204
+ transactionOutcome: 'Change of photo',
205
+ }
206
+ end
207
+
208
+ if @eligibility_paper_to_plastic
209
+ if !@duplicate && !@replacement_licence
210
+ raise 'Not possible to have a paper-to-plastic for applications that are not REP/DUP'
211
+ end
212
+
213
+ b.data.customer_context[:applicationsEligibilityResponse][0][:availableActions].push({
214
+ actionType: 'inform-paper-to-plastic',
215
+ isRequired: true,
216
+ })
217
+ end
218
+
219
+ b.data.applicant = @applicant if @applicant
220
+ b.data.applicant[:phoneNumber] = Faker::PhoneNumber.phone_number if @phone_number
221
+
222
+ if @welsh_language
223
+ b.data.applicant[:languagePreference] = 'Welsh'
224
+ end
225
+
226
+ unless @unable_to_prove_licence_possession_reason.nil?
227
+ b.data.unable_to_prove_licence_possession_reason = @unable_to_prove_licence_possession_reason
228
+ end
229
+
230
+ if !@processable && !@payments.nil?
231
+ b.payments = @payments
232
+ end
233
+
234
+ b.images = images
235
+
236
+ if !@processable && !@application_status.nil?
237
+ @update_reason = if @application_status == 'Cancelled'
238
+ @update_reason || 'Timed out'
239
+ elsif @application_status == 'Rejected'
240
+ b.data.organ_donor = FM[:organ_donor_d90_response].build(attributes: { kidneys: true })
241
+ elsif @application_status == 'Returned'
242
+ b.data.organ_donor = FM[:organ_donor_d90_response].build(attributes: { cornea: true })
243
+ elsif @application_status == 'Unapproved'
244
+ b.data.organ_donor = FM[:organ_donor_d90_response].build(attributes: { heart: true })
245
+ elsif !@organ_donor.nil? && @organ_donor
246
+ # do we want an extra flag to decide any_organs seperate from if they are a donor?
247
+ b.data.organ_donor = set_any_organs(any_organs_bool: @organ_donor)
248
+ else
249
+ b.data.organ_donor = {}
250
+ end
251
+ elsif @processable && !@organ_donor.nil? && @organ_donor
252
+ b.data.organ_donor = set_any_organs(any_organs_bool: @organ_donor)
253
+ else
254
+ b.data.organ_donor = {}
255
+ end
256
+ end
257
+
258
+ if @processable
259
+ process_photo_tasks(app)
260
+ else
261
+ DVLA::Application::ApplicationStatusProcessor.process_to(app.application_id, @application_status, update_reason: @update_reason)
262
+ end
263
+
264
+ # updates call to action date on domain
265
+ if @extend_application_deadline
266
+ extend_date = Time.now + 21.days
267
+ DVLA::Application.logger.info("Updating application call to action deadline date to: #{extend_date}".blue)
268
+ DVLA::Application::ApplicationDomain.update_call_to_action_deadline_date(application_id: app.application_id, call_to_action_deadline_date: extend_date.utc.iso8601)
269
+ end
270
+
271
+ DVLA::Application::ApplicationDomain.retrieve_application_by_app_id(application_id: app.application_id)
272
+ end
273
+
274
+ extend Gem::Deprecate
275
+ deprecate(:build, 'TYRV2ApplicationBuilder#build', 2025, 12)
276
+ end
277
+ end
278
+ end