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,71 @@
1
+ module DVLA
2
+ module Application
3
+ module DupRepBuilderMixin
4
+ def dup_rep_init_properties
5
+ @unable_to_prove_licence_possession_reason = nil
6
+ @eligibility_paper_to_plastic = false
7
+ end
8
+
9
+ # Adds the customer provided reason for not being able to prove licence possession to the application
10
+ # @param reason [DVLA::Application::UnableToProveLicencePossessionReasons] the reason for not being able to prove licence possession
11
+ # @return [BuilderUsingMixin]
12
+ def with_unable_to_prove_licence_possession_reason(reason)
13
+ @unable_to_prove_licence_possession_reason = reason
14
+ self
15
+ end
16
+
17
+ # Acts as if the licence owner has a paper licence.
18
+ # The application will be eligible to be changed from a paper licence to a plastic one
19
+ # It will also upload a photo and a signature with the application, and enable the flags to control these images and their tasks
20
+ # @return [BuilderUsingMixin]
21
+ def eligible_paper_to_plastic
22
+ @eligibility_paper_to_plastic = true
23
+ self
24
+ end
25
+
26
+ # Get the boolean associated with paper to plastic applications
27
+ # @return [Boolean]
28
+ def get_eligible_paper_to_plastic
29
+ @eligibility_paper_to_plastic
30
+ end
31
+
32
+ # Checking if the combination of builder methods used are valid
33
+ def check_application_validity
34
+ unless @eligibility_paper_to_plastic
35
+ error_message = "because a normal DUP application that doesn't convert from paper to photocard doesn't have images"
36
+ if @photo_review_state != DVLA::Application::ReviewState::CLERK_IN_PROGRESS || @signature_review_state != DVLA::Application::SignatureReviewState::CLERK_IN_PROGRESS
37
+ raise 'Cannot specify a photo or signature review state ' + error_message
38
+ end
39
+ if @with_passport_images
40
+ raise 'Cannot specify to use passport images ' + error_message
41
+ end
42
+ if @home_office_comparison_photo
43
+ raise 'Cannot specify to use home office image ' + error_message
44
+ end
45
+ if @unique_images
46
+ raise 'Cannot specify to use unique images ' + error_message
47
+ end
48
+ end
49
+ end
50
+
51
+ # Set a change of address action for all DUP and REP applications
52
+ def application_driving_licence_actions
53
+ { updateAddress: { newAddress: { unstructuredAddress: FM[:unstructured_address].build } } }
54
+ end
55
+
56
+ # Creating the images that the BaseUODLV2ApplicationBuilder will include in the app
57
+ def application_images
58
+ if @eligibility_paper_to_plastic
59
+ generate_photo_signature_images(@processable, @unique_images)
60
+ else
61
+ []
62
+ end
63
+ end
64
+
65
+ #ensure photo and signature task are correctly processed if the processable flag is used in BaseUODLV2ApplicationBuilder
66
+ def process_application_tasks(app)
67
+ process_photo_signature_tasks(app) if @processable
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,49 @@
1
+ module DVLA
2
+ module Application
3
+ module PhotoBuilderMixin
4
+ def init_photo_properties
5
+ @review_state = DVLA::Application::ReviewState::CLERK_IN_PROGRESS
6
+ @with_passport_image = false
7
+ @passport_available = true
8
+ end
9
+
10
+ # The application contains a passport image to the applicant to be submitted. Disables user photo.
11
+ # @return [BuilderUsingMixin]
12
+ def with_passport_image
13
+ @with_passport_image = true
14
+ @passport_available = false
15
+ self
16
+ end
17
+
18
+ # The application will contain a user image. If stated, a fallback passport option will also be provided.
19
+ # @param passport_available [boolean] Whether to provide a passport available for fallback.
20
+ # @return [BuilderUsingMixin]
21
+ def with_user_image(passport_available)
22
+ @with_passport_image = false
23
+ @passport_available = passport_available
24
+ self
25
+ end
26
+
27
+ # The application will be progressed in the provided review state.
28
+ # How this state is reached will depend on if the application has been marked as processable or not.
29
+ # @param review_state [DVLA::Application::ReviewState] The review state to be in.
30
+ # @return [BuilderUsingMixin]
31
+ def with_review_state(review_state)
32
+ @review_state = review_state
33
+ self
34
+ end
35
+
36
+ def generate_photo_images(processable, unique_images = false)
37
+ required_review_state = processable ? nil : @review_state
38
+ preprocess_passport_images = !processable
39
+ DVLA::Application::PhotoImagesFactory.new(required_review_state, unique_images, use_passport_images: @with_passport_image, passport_images_preprocessed: preprocess_passport_images, additional_passport_image_available: @passport_available).build
40
+ end
41
+
42
+ def process_photo_tasks(app)
43
+ if @review_state != :clerk_in_progress
44
+ DVLA::Application::ApplicationTaskProcessor.process_to(app.application_id, @review_state)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,68 @@
1
+ module DVLA
2
+ module Application
3
+ module PhotoSignatureBuilderMixin
4
+ def init_photo_signature_properties
5
+ @home_office_comparison_photo = false
6
+ @photo_review_state = DVLA::Application::ReviewState::CLERK_IN_PROGRESS
7
+ @signature_review_state = DVLA::Application::SignatureReviewState::CLERK_IN_PROGRESS
8
+ @with_passport_images = false
9
+ end
10
+
11
+ # The application will be progressed in the provided review state for a photo.
12
+ # How this state is reached will depend on if the application has been marked as processable or not.
13
+ # @param photo_review_state [DVLA::Application::ReviewState] The review state to be in.
14
+ # @return [BuilderUsingMixin]
15
+ def with_photo_review_state(photo_review_state)
16
+ @photo_review_state = photo_review_state
17
+ self
18
+ end
19
+
20
+ # The application will be progressed in the provided review state for a signature.
21
+ # How this state is reached will depend on if the application has been marked as processable or not.
22
+ # @param signature_review_state [DVLA::Application::SignatureReviewState] The review state to be in.
23
+ # @return [BuilderUsingMixin]
24
+ def with_signature_review_state(signature_review_state)
25
+ @signature_review_state = signature_review_state
26
+ self
27
+ end
28
+
29
+ # The application contains passport photo and signature to the applicant to be submitted. Disables user photo and user signature.
30
+ # @return [BuilderUsingMixin]
31
+ def with_passport_images
32
+ @with_passport_images = true
33
+ self
34
+ end
35
+
36
+ # The comparison photo used for the application will be coming from Home Office.
37
+ def with_home_office_comparison_photo
38
+ @home_office_comparison_photo = true
39
+ self
40
+ end
41
+
42
+ def generate_photo_signature_images(processable, unique_images = false)
43
+ required_photo_review_state = processable ? nil : @photo_review_state
44
+ required_signature_review_state = processable ? nil : @signature_review_state
45
+ preprocess_passport_images = !processable
46
+
47
+ DVLA::Application::PhotoSignatureImagesFactory.new(required_photo_review_state, required_signature_review_state, unique_images, use_passport_images: @with_passport_images, passport_images_preprocessed: preprocess_passport_images, home_office_comparison_photo: @home_office_comparison_photo).build
48
+ end
49
+
50
+ def generate_csudl_photo_signature_images(processable, unique_images = false)
51
+ required_photo_review_state = processable ? nil : @photo_review_state
52
+ required_signature_review_state = processable ? nil : @signature_review_state
53
+ preprocess_passport_images = !processable
54
+
55
+ DVLA::Application::CSUDLPhotoSignatureImagesFactory.new(required_photo_review_state, required_signature_review_state, unique_images, use_passport_images: @with_passport_images, passport_images_preprocessed: preprocess_passport_images).build
56
+ end
57
+
58
+ def process_photo_signature_tasks(app)
59
+ if @photo_review_state != :clerk_in_progress
60
+ DVLA::Application::ApplicationTaskProcessor.process_to(app.application_id, @photo_review_state, task_type: 'Photo review')
61
+ end
62
+ if @signature_review_state != :clerk_signature_in_progress
63
+ DVLA::Application::ApplicationTaskProcessor.process_to(app.application_id, @signature_review_state, task_type: 'Signature review')
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,37 @@
1
+ module DVLA
2
+ module Application
3
+ class Configuration
4
+ attr_reader :environment, :logger
5
+
6
+ def initialize
7
+ @logger = DVLA::Herodotus.logger('application-helper')
8
+ end
9
+
10
+ def environment=(config)
11
+ @environment = config
12
+
13
+ # NOTE: Has the test-pack using the customer-helper gem already defined Settings?
14
+ if defined?(Settings)
15
+ DVLA::Application.logger.warn("Config not found: 'dvla-application-helper/config/settings/#{@environment}.yml'") unless File.exist?("#{CONFIG}/settings/#{@environment}.yml")
16
+
17
+ # NOTE: Add our settings to the start - will be overwritten by calling test-pack if desired
18
+ Settings.prepend_source!("#{CONFIG}/settings/#{@environment}.yml")
19
+ Settings.prepend_source!("#{CONFIG}/settings.yml")
20
+
21
+ # NOTE: Refreshes the config
22
+ Settings.reload!
23
+ else
24
+ Config.load_and_set_settings(Config.setting_files(CONFIG, @environment))
25
+ end
26
+ end
27
+
28
+ def logger=(new_logger)
29
+ if new_logger.is_a?(Logger)
30
+ @logger = new_logger
31
+ else
32
+ @logger.warn('Custom logger is not an instance of Logger')
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ # Ive added these in to utilise the constants module (most likely will be changing some of them and adding more which are specific to the project)
2
+ module InternalUser
3
+ NAME = 'Tom Collins'.freeze
4
+ EMAIL_ADDRESS = 'tom.collins@dvla.gov.uk'.freeze
5
+ end
6
+
7
+ module RequestHeaders
8
+ CONTENT_TYPE = 'application/json'.freeze
9
+ DVLA_ORIGIN_RESOURCE = 'dvla:resource:osl:application:application-process-engine:1.0.0'.freeze # String | Identifies the origin requesting service. Must match the following pattern: /^(dvla:resource)(\\:[^:\\n]+){4}$/ (JSON escaped, 'dvla:resource' is case sensitive)
10
+ DVLA_RESOURCE = 'dvla:resource:osl:application:drivers-application-process-engine:1.0.0'.freeze # String | Identifies requesting service. Must match the following pattern: /^(dvla:resource)(\\:[^:\\n]+){4}$/ (JSON escaped, 'dvla:resource' is case sensitive)
11
+ DVLA_SESSION_ID = 'b5d9b2bd-6e8f-4275-bdd3-c8086fe09c52'.freeze # String | Link log messages to a specific application session. Set to UUID4 if header is omitted and header value is empty
12
+ DVLA_USER = "dvla:user:azure-ad:Sja0hZ8YsMi0_:WuJf0SoU4QOSrQe8K9OZIYtmprn7qc:#{InternalUser::EMAIL_ADDRESS}".freeze # String | Identifies the user invoking the service. Must match the following pattern: /^(dvla:user)(\\:[^:\\n]+){4}$/ (JSON escaped, 'dvla:user' is case sensitive)
13
+ ORIGIN_TIMESTAMP = 'origin_timestamp_example'.freeze # String | For informational / support purposes only, handy to identify network delays between source and destination.
14
+ X_CORRELATION_ID = 'b5d9b2bd-6e8f-4275-bdd3-c8086fe09c52'.freeze # String | Link log messages to a specific application request. Set to UUID4 if header is omitted and header value is empty
15
+ X_IMAGE_USE_APP_PHOTO = 'driving-licence-application-photo'.freeze
16
+ X_IMAGE_USE_DRIVER_PHOTO = 'driver-photo'.freeze
17
+ X_IMAGE_USE_APP_SIGNATURE = 'driving-licence-application-signature'.freeze
18
+ X_IMAGE_USE_PHOTOCARD_FRONT = 'driving-licence-application-photocard-front'.freeze
19
+ X_IMAGE_USE_PHOTOCARD_BACK = 'driving-licence-application-photocard-back'.freeze
20
+ DISABLE_PAYMENT_PROCESSING = 'true'.freeze
21
+ end
@@ -0,0 +1,30 @@
1
+ module DVLA
2
+ module Application
3
+ # TODO DL-12812 consider renaming this to PhotoReviewState
4
+ module ReviewState
5
+ CLERK_IN_PROGRESS = :clerk_in_progress
6
+ CLERK_REJECTED = :clerk_rejected
7
+ CLERK_REFER_TO_SUPERVISOR_STANDARDS = :clerk_refer_to_supervisor_standards
8
+ CLERK_REFER_TO_SUPERVISOR_COMPARE = :clerk_refer_to_supervisor_compare
9
+ CLERK_APPROVED = :clerk_approved
10
+ SUPERVISOR_REJECTED = :supervisor_rejected
11
+ SUPERVISOR_REFER_TO_FRAUD = :supervisor_refer_to_fraud
12
+ SUPERVISOR_APPROVED = :supervisor_approved
13
+ FRAUD_BEGIN_INVESTIGATION = :fraud_begin_investigation
14
+ FRAUD_APPROVED = :fraud_approved
15
+ FRAUD_REJECTED = :fraud_rejected
16
+ FRAUD_REVIEW_REJECTION_WITH_REFUND = :fraud_review_rejection_with_refund
17
+ FRAUD_REVIEW_REJECTION_WITHOUT_REFUND = :fraud_review_rejection_without_refund
18
+ FRAUD_REVIEW_APPROVED = :fraud_review_approved
19
+ CLERK_REJECT_COMPARISON_PHOTO = :clerk_reject_comparison_photo
20
+ FRAUD_REJECT_COMPARISON_PHOTO = :fraud_reject_comparison_photo
21
+ SUPERVISOR_REJECT_COMPARISON_PHOTO = :supervisor_reject_comparison_photo
22
+ end
23
+
24
+ module SignatureReviewState
25
+ CLERK_IN_PROGRESS = :clerk_signature_in_progress
26
+ CLERK_REJECTED = :clerk_signature_rejected
27
+ CLERK_APPROVED = :clerk_signature_approved
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,8 @@
1
+ module DVLA
2
+ module Application
3
+ module UnableToProveLicencePossessionReasons
4
+ LOST_OR_STOLEN = 'LOST_OR_STOLEN'.freeze
5
+ DEFACED_OR_DESTROYED = 'DEFACED_OR_DESTROYED'.freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ FM.factory :application_unstructured_address, naming: :json do
2
+ line1 { Faker::Address.street_address }
3
+ line5 { Faker::Address.city }
4
+ postcode { 'SA3 1AD' }
5
+ end
6
+
7
+ FM.factory :international_address, naming: :json do
8
+ line1 { "Flat #{Faker::Number.number(digits: 1)}" }
9
+ line2 { "Building #{Faker::Number.number(digits: 1)}" }
10
+ line3 { "Section #{Faker::Number.number(digits: 1)}" }
11
+ line4 { Faker::Address.community }
12
+ line5 { Faker::Address.city }
13
+ country { Faker::Address.country }
14
+ end
15
+
16
+ FM.factory :bfpo_address, naming: :json do
17
+ line1 { "Unit #{Faker::Number.number(digits: 1)}" }
18
+ line2 { Faker::Address.community }
19
+ line3 { Faker::Address.city }
20
+ bfpoNumber { Faker::Number.number(digits: 2) }
21
+ end
@@ -0,0 +1,353 @@
1
+ FM.factory :medical_declaration, naming: :json do
2
+ {
3
+ diabetes: false,
4
+ epilepsy: false,
5
+ eyeCondition: false,
6
+ eyeConditionDescription: '',
7
+ visualField: false,
8
+ stroke: false,
9
+ seizureOrBlackouts: false,
10
+ brainInjury: false,
11
+ brainTumour: false,
12
+ cardiacPacemaker: false,
13
+ cardiacDefibrillator: false,
14
+ dizziness: false,
15
+ chronicNeurologicalCondition: false,
16
+ seriousMemoryProblems: false,
17
+ parkinsonsDisease: false,
18
+ narcolepsy: false,
19
+ excessiveSleepiness: false,
20
+ persistingLimbProblem: false,
21
+ severeLearningDisability: false,
22
+ toldBefore: false,
23
+ conditionWorse: false,
24
+ }
25
+ end
26
+
27
+ # TODO DL-12812 rename title to be specific for UODL
28
+ FM.factory :application_data, naming: :json do
29
+ applicant { DVLA::Application::PersonFactory.new.build.to_applicant }
30
+ was_required_at_time_of_submission { true }
31
+ organ_donor { FM[:organ_donor].build }
32
+ driving_licence_actions { {} }
33
+ end
34
+
35
+ FM.factory :uodl_v2_application_data, naming: :json do
36
+ applicant { DVLA::Application::PersonFactory.new.build.to_applicant }
37
+ customer_context {
38
+ {
39
+ customerIntent: 'Ten year renewal',
40
+ applicationsEligibilityResponse: [{
41
+ applicationType: 'update-ordinary-licence',
42
+ isRequired: true,
43
+ availableActions: [
44
+ actionType: 'update-photo',
45
+ isRequired: true,
46
+ ],
47
+ }],
48
+ transactionOutcome: 'Ten year renewal',
49
+ }
50
+ }
51
+ eyesight_declaration { 'No' }
52
+ medical_declaration { FM[:medical_declaration].build }
53
+ organ_donor { FM[:organ_donor].build }
54
+ driving_licence_actions { {} }
55
+ unable_to_prove_licence_possession_reason { nil }
56
+ surrender_entitlements {
57
+ {
58
+ surrenderLorry: true,
59
+ surrenderBus: true,
60
+ }
61
+ }
62
+ end
63
+
64
+ FM.factory :uodl_v3_application_data, naming: :json do
65
+ schema_version { '3' }
66
+ applicant { DVLA::Application::PersonFactory.new.build.to_applicant }
67
+ customer_context {
68
+ {
69
+ customerIntent: 'Ten year renewal',
70
+ applicationsEligibilityResponse: [{
71
+ applicationType: 'update-ordinary-licence',
72
+ isRequired: true,
73
+ availableActions: [
74
+ actionType: 'update-photo',
75
+ isRequired: true,
76
+ ],
77
+ }],
78
+ transactionOutcome: 'Ten year renewal',
79
+ }
80
+ }
81
+ eyesight_declaration { 'No' }
82
+ medical_declaration { FM[:medical_declaration].build }
83
+ organ_donor { FM[:organ_donor].build }
84
+ unable_to_prove_licence_possession_reason { nil }
85
+ surrender_entitlements { {} }
86
+ end
87
+
88
+
89
+ FM.factory :csudl_application_data, naming: :json do
90
+ applicant { DVLA::Application::PersonFactory.new.build.to_applicant }
91
+ update_address { nil }
92
+ unable_to_prove_licence_possession_reason { nil }
93
+ organ_donor { FM[:organ_donor].build }
94
+ photo_compliance_checks { {} }
95
+ investigation_required { false }
96
+ reminder_barcode_contents { '' }
97
+ licence_data { {} }
98
+ counter_service_metadata {
99
+ {
100
+ originatorId: 'POL',
101
+ transactionID: '123456789012345678901234',
102
+ userId: 'john-smith',
103
+ branchId: 'a123',
104
+ terminalId: '123456',
105
+ localDateTime: '2025-01-01T12:00:00Z',
106
+ }
107
+ }
108
+ customer_context {
109
+ {
110
+ customerIntent: 'Ten year renewal',
111
+ }
112
+ }
113
+ payment_amount { '21.50' }
114
+ end
115
+
116
+ def base_application_details
117
+ application_id { '' }
118
+ application_state {
119
+ {
120
+ status: 'Started',
121
+ timeUpdated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
122
+ }
123
+ }
124
+ application_type { 'Update Ordinary Driving Licence' }
125
+ product_type { '' }
126
+ product_id { '' }
127
+ product_key { '' }
128
+ customer_id { SecureRandom::uuid }
129
+ data_schema { '' }
130
+ data { FM[:application_data].build }
131
+ payments { [] }
132
+ images { [] }
133
+ no_fee_application { false }
134
+
135
+ after_build do |instance|
136
+ DVLA::Application::ApplicationDomain.create_test_application(application: instance)
137
+ end
138
+ end
139
+
140
+ # TODO DL-12812 refactor to either be fully generic or to be renamed with specific name for UODL
141
+ FM.factory :application, naming: :json do
142
+ application_reference_number { Faker::Base.regexify(/TY[BCDFGHJKLMNPQRSTVWXYZ]{2}-[BCDFGHJKLMNPQRSTVWXYZ]{4}-[BCDFGHJKLMNPQRSTVWXYZ]{4}/) }
143
+ base_application_details
144
+ end
145
+
146
+ #added to cover the generation of tyr application alongside base uodl v2, may be able to deprecate above application
147
+ FM.factory :tyr_application, naming: :json do
148
+ application_reference_number { Faker::Base.regexify(/TY[BCDFGHJKLMNPQRSTVWXYZ]{2}-[BCDFGHJKLMNPQRSTVWXYZ]{4}-[BCDFGHJKLMNPQRSTVWXYZ]{4}/) }
149
+ base_application_details
150
+ end
151
+
152
+ FM.factory :cop_application, naming: :json do
153
+ application_reference_number { Faker::Base.regexify(/CP[BCDFGHJKLMNPQRSTVWXYZ]{2}-[BCDFGHJKLMNPQRSTVWXYZ]{4}-[BCDFGHJKLMNPQRSTVWXYZ]{4}/) }
154
+ base_application_details
155
+ end
156
+
157
+ FM.factory :rep_application, naming: :json do
158
+ application_reference_number { Faker::Base.regexify(/CD[BCDFGHJKLMNPQRSTVWXYZ]{2}-[BCDFGHJKLMNPQRSTVWXYZ]{4}-[BCDFGHJKLMNPQRSTVWXYZ]{4}/) }
159
+ base_application_details
160
+ end
161
+
162
+ FM.factory :dup_application, naming: :json do
163
+ application_reference_number { Faker::Base.regexify(/DU[BCDFGHJKLMNPQRSTVWXYZ]{2}-[BCDFGHJKLMNPQRSTVWXYZ]{4}-[BCDFGHJKLMNPQRSTVWXYZ]{4}/) }
164
+ base_application_details
165
+ end
166
+
167
+ FM.factory :exc_application, naming: :json do
168
+ application_reference_number { Faker::Base.regexify(/EX[BCDFGHJKLMNPQRSTVWXYZ]{2}-[BCDFGHJKLMNPQRSTVWXYZ]{4}-[BCDFGHJKLMNPQRSTVWXYZ]{4}/) }
169
+ base_application_details
170
+ end
171
+
172
+ FM.factory :csudl_application, naming: :json do
173
+ application_reference_number { Faker::Base.regexify(/CTTY-[BCDFGHJKLMNPQRSTVWXYZ]{4}-[BCDFGHJKLMNPQRSTVWXYZ]{4}/) }
174
+ application_id { '' }
175
+ application_state {
176
+ {
177
+ status: 'Started',
178
+ timeUpdated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
179
+ }
180
+ }
181
+ application_type { 'Update Ordinary Driving Licence' }
182
+ product_type { '' }
183
+ product_id { '' }
184
+ product_key { '' }
185
+ customer_id(omit: :nil) { SecureRandom::uuid }
186
+ data_schema { '' }
187
+ data { FM[:csudl_application_data].build }
188
+ payments { [] }
189
+ images { [] }
190
+ application_type { 'Counter Service Update Driving Licence' }
191
+ product_id { 'd22e3cbe-7309-4bee-91eb-2069bdc3f9b1' }
192
+ product_key { 'GUSIK720813IG909' }
193
+ fee_settlement_type { 'Third Party Settlement' }
194
+
195
+ after_build do |instance|
196
+ DVLA::Application::ApplicationDomain.create_test_application(application: instance)
197
+ end
198
+ end
199
+
200
+
201
+ FM.factory :uodl_processable_application, naming: :json do
202
+ application_id { SecureRandom::uuid }
203
+ customer_id { SecureRandom::uuid }
204
+ driver_id { Settings.test.driver_id.mandatory_tyr }
205
+ driving_licence_number { Faker::DrivingLicence.british_driving_licence }
206
+ data { FM[:application_data].build }
207
+ images { [] }
208
+ no_fee_application { false }
209
+
210
+ after_build do |instance|
211
+ submit_processable_app(
212
+ application: instance,
213
+ skip_payment: instance.no_fee_application,
214
+ start_endpoint: :start_update_photo_application_v2,
215
+ submit_endpoint: :submit_update_photo_application,
216
+ submit_request_class: DVLADrivingLicenceChannelApiOpenAPIClient::SubmitUpdatePhotoApplicationRequest)
217
+ end
218
+ end
219
+
220
+
221
+ FM.factory :uodl_v2_processable_application, naming: :json do
222
+ application_id { SecureRandom::uuid }
223
+ customer_id { SecureRandom::uuid }
224
+ driver_id { Settings.test.driver_id.mandatory_tyr }
225
+ driving_licence_number { Faker::DrivingLicence.british_driving_licence }
226
+ data { FM[:application_data].build }
227
+ images { [] }
228
+ no_fee_application { false }
229
+
230
+ after_build do |instance|
231
+ submit_processable_app(
232
+ application: instance,
233
+ skip_payment: instance.no_fee_application,
234
+ start_endpoint: :start_update_photo_application_v3,
235
+ submit_endpoint: :submit_update_photo_application,
236
+ submit_request_class: DVLADrivingLicenceChannelApiOpenAPIClient::SubmitUpdatePhotoApplicationRequest)
237
+ end
238
+ end
239
+
240
+ FM.factory :uodl_v3_processable_application, naming: :json do
241
+ application_id { SecureRandom::uuid }
242
+ customer_id { SecureRandom::uuid }
243
+ driver_id { Settings.test.driver_id.mandatory_tyr }
244
+ driving_licence_number { Faker::DrivingLicence.british_driving_licence }
245
+ data { FM[:application_data].build }
246
+ images { [] }
247
+ no_fee_application { false }
248
+
249
+ after_build do |instance|
250
+ submit_processable_app(
251
+ application: instance,
252
+ skip_payment: instance.no_fee_application,
253
+ start_endpoint: :start_update_photo_application_v3,
254
+ submit_endpoint: :submit_update_photo_application,
255
+ submit_request_class: DVLADrivingLicenceChannelApiOpenAPIClient::SubmitUpdatePhotoApplicationRequest)
256
+ end
257
+ end
258
+
259
+ FM.factory :codl_application_data, naming: :json do
260
+ applicant { DVLA::Application::PersonFactory.new.build.to_applicant }
261
+ hasMedicalCondition { false }
262
+ organ_donor { FM[:organ_donor].build }
263
+ receivingBenefits { { mobility: true } }
264
+ eyesightDeclaration { 'Yes, without glasses or corrective lenses' }
265
+ disqualifications { [] }
266
+ end
267
+
268
+ FM.factory :codl_application, parent: :application, naming: :json do
269
+ application_id { SecureRandom::uuid }
270
+ application_type { 'Create Ordinary Driving Licence' }
271
+ product_type { 'Driving Licence' }
272
+ application_reference_number { Faker::Base.regexify(/FP[BCDFGHJKLMNPQRSTVWXYZ]{2}-[BCDFGHJKLMNPQRSTVWXYZ]{4}-[BCDFGHJKLMNPQRSTVWXYZ]{4}/) }
273
+ data_schema { 'https://osl-data-dictionary-schemas.engineering.dvla.gov.uk/driving-licence-application/applications/v1/create-ordinary-driving-licence-application.json' }
274
+ data { FM[:codl_application_data].build }
275
+ no_fee_application { false }
276
+
277
+ after_build do |instance|
278
+ DVLA::Application::ApplicationDomain.create_test_application(application: instance)
279
+ end
280
+ end
281
+
282
+ FM.factory :codl_processable_application, naming: :json do
283
+ application_id { SecureRandom::uuid }
284
+ customer_id { 'a1f7165c-42c8-4ee0-84dd-927a34087b24' }
285
+ data { FM[:codl_application_data].build }
286
+ images { [] }
287
+
288
+ after_build do |instance|
289
+ submit_processable_app(
290
+ application: instance,
291
+ skip_payment: false,
292
+ start_endpoint: :start_codl_application,
293
+ submit_endpoint: :submit_codl_application,
294
+ submit_request_class: DVLADrivingLicenceChannelApiOpenAPIClient::SubmitCodlApplicationRequest)
295
+ end
296
+ end
297
+
298
+ def submit_processable_app(application:, skip_payment:, start_endpoint:, submit_endpoint:, submit_request_class:)
299
+ channel_api = DVLA::Application::ChannelAPI.initialize_channel_api_instance
300
+
301
+ DVLA::Application.logger.info("applicationID = #{application.application_id.green}")
302
+ DVLA::Application.logger.info("customerID = #{application.customer_id.green}")
303
+ DVLA::Application.logger.info("driverID = #{application.driver_id.green}") if application.respond_to?(:driver_id)
304
+ DVLA::Application.logger.info("Calling #{start_endpoint}")
305
+
306
+
307
+ app_encoded = application.as_json
308
+ app_encoded = app_encoded.except('noFeeApplication')
309
+
310
+ if application.data.respond_to?(:unable_to_prove_licence_possession_reason) && application.data.unable_to_prove_licence_possession_reason.nil?
311
+ DVLA::Application.logger.info('No Possession Reason Present, removing from request')
312
+ app_encoded['data'].delete('unableToProveLicencePossessionReason')
313
+ end
314
+
315
+ res = channel_api.send(start_endpoint,
316
+ RequestHeaders::DVLA_RESOURCE,
317
+ RequestHeaders::DVLA_ORIGIN_RESOURCE,
318
+ app_encoded,
319
+ DVLA::Application::ChannelAPI.driving_licence_channel_api_test_headers_including_user,
320
+ )
321
+
322
+ unless skip_payment
323
+ payment_req = DVLADrivingLicenceChannelApiOpenAPIClient::InitiatePaymentRequest.new(
324
+ application_id: application.application_id,
325
+ result_page_url: 'http://localhost',
326
+ payment_amount: res.payment_amount.to_s,
327
+ application_reference_number: res.application_reference_number,
328
+ language: 'EN',
329
+ )
330
+
331
+ DVLA::Application.logger.info('Calling initiate-payment')
332
+ payment_res = channel_api.initiate_payment(
333
+ RequestHeaders::DVLA_RESOURCE,
334
+ RequestHeaders::DVLA_ORIGIN_RESOURCE,
335
+ payment_req,
336
+ DVLA::Application::ChannelAPI.driving_licence_channel_api_test_headers,
337
+ )
338
+ end
339
+
340
+ req = submit_request_class.new(
341
+ application_id: application.application_id,
342
+ payment_id: (payment_res.payment_id unless skip_payment),
343
+ )
344
+
345
+ DVLA::Application.logger.info("Calling #{submit_endpoint}")
346
+ headers = skip_payment ? DVLA::Application::ChannelAPI.driving_licence_channel_api_test_headers_disable_payment_processing : DVLA::Application::ChannelAPI.driving_licence_channel_api_test_headers
347
+ channel_api.send(submit_endpoint,
348
+ RequestHeaders::DVLA_RESOURCE,
349
+ RequestHeaders::DVLA_ORIGIN_RESOURCE,
350
+ req,
351
+ headers,
352
+ )
353
+ end
@@ -0,0 +1,7 @@
1
+ module DVLA
2
+ module Application
3
+ def self.generate_case_number
4
+ Faker::Base.regexify(/[A-Za-z0-9-]{8,17}/)
5
+ end
6
+ end
7
+ end