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,156 @@
1
+ require_relative('photo_image.rb')
2
+
3
+ module DVLA
4
+ module Application
5
+ class CSUDLPhotoSignatureImageFactory < PhotoImageFactory
6
+ def build(type)
7
+ case type
8
+ when :csudl_photo
9
+ build_csudl_photo
10
+ when :csudl_passport_photo
11
+ build_csudl_passport_photo
12
+ when :photocard_front
13
+ build_photocard_front
14
+ when :photocard_back
15
+ build_photocard_back
16
+ when :csudl_signature
17
+ build_csudl_signature
18
+ when :csudl_passport_signature
19
+ build_csudl_passport_signature
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ CSUDL_COMPARISON_IMAGE_ID = '54f7d36d-1ac0-4737-95b7-a10d22926500'.freeze
28
+ CSUDL_USER_IMAGE_ID = '617d6689-e03e-44e7-962d-ceb6e158e031'.freeze
29
+ CSUDL_PASSPORT_IMAGE_ID = '74dbf8d0-bf86-48d7-8731-22b15d3dc396'.freeze
30
+ CSUDL_SIGNATURE_IMAGE_ID = '22b0342e-62d5-42e1-8f40-93f08f885938'.freeze
31
+ CSUDL_PASSPORT_SIGNATURE_IMAGE_ID = 'c4eb8971-b575-497a-8f50-12909e39849a'.freeze
32
+ PHOTOCARD_FRONT_IMAGE_ID = 'a13d9db6-6662-483b-98fe-d89b0e9733ed'.freeze
33
+ PHOTOCARD_BACK_IMAGE_ID = '698a897d-9366-490f-9304-63b034337e6d'.freeze
34
+
35
+ # Overridden from base class
36
+ def build_comparison
37
+ image_id = @unique_images == false ? CSUDL_COMPARISON_IMAGE_ID : Random.uuid
38
+
39
+ DVLA::Application::ImageUtility.store_local_image_in_image_utility(image_id:, image_purpose: 'Application', image_origin: 'Driving Licence', image_path: '../fixtures/photo/comparison_image.jpeg')
40
+
41
+ {
42
+ imageId: image_id,
43
+ imageType: 'Photo',
44
+ imageSource: 'image-utility',
45
+ imageOriginType: 'Driving Licence',
46
+ imageStatus: 'Active',
47
+ imagePurpose: 'Comparison',
48
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
49
+ reviewHistory: [],
50
+ }
51
+ end
52
+
53
+ def build_csudl_photo
54
+ image_id = @unique_images == false ? CSUDL_USER_IMAGE_ID : Random.uuid
55
+
56
+ DVLA::Application::ImageUtility.store_local_image_in_image_utility(image_id:, image_purpose: 'Application', image_origin: 'User', image_path: '../fixtures/photo/user_uploaded_image.jpg')
57
+
58
+ {
59
+ imageId: image_id,
60
+ imageType: 'Photo',
61
+ imageSource: 'image-utility',
62
+ imageOriginType: 'Counter Service',
63
+ imageStatus: 'Active',
64
+ imagePurpose: 'Application',
65
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
66
+ reviewHistory: [],
67
+ }
68
+ end
69
+
70
+ def build_csudl_passport_photo
71
+ image_id = @unique_images == false ? CSUDL_PASSPORT_IMAGE_ID : Random.uuid
72
+
73
+ DVLA::Application::ImageUtility.store_local_image_in_image_utility(image_id:, image_purpose: 'Application', image_origin: 'Passport', image_path: '../fixtures/photo/user_uploaded_image.jpg')
74
+
75
+ {
76
+ imageId: image_id,
77
+ imageType: 'Photo',
78
+ imageSource: 'image-utility',
79
+ imageOriginType: 'Passport',
80
+ imageStatus: 'Active',
81
+ imagePurpose: 'Application',
82
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
83
+ reviewHistory: [],
84
+ }
85
+ end
86
+
87
+ def build_photocard_front
88
+ image_id = @unique_images == false ? PHOTOCARD_FRONT_IMAGE_ID : Random.uuid
89
+
90
+ DVLA::Application::ImageUtility.store_local_image_in_image_utility(image_id:, image_purpose: 'Photocard front', image_origin: 'Counter Service', image_path: '../fixtures/photo/photocard_front.jpg')
91
+
92
+ {
93
+ imageId: image_id,
94
+ imageType: 'Photocard front',
95
+ imageSource: 'image-utility',
96
+ imageOriginType: 'Counter Service',
97
+ imageStatus: 'Active',
98
+ imagePurpose: 'Application',
99
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
100
+ reviewHistory: [],
101
+ }
102
+ end
103
+
104
+ def build_photocard_back
105
+ image_id = @unique_images == false ? PHOTOCARD_BACK_IMAGE_ID : Random.uuid
106
+
107
+ DVLA::Application::ImageUtility.store_local_image_in_image_utility(image_id:, image_purpose: 'Photocard back', image_origin: 'Counter Service', image_path: '../fixtures/photo/photocard_back.jpg')
108
+
109
+ {
110
+ imageId: image_id,
111
+ imageType: 'Photocard back',
112
+ imageSource: 'image-utility',
113
+ imageOriginType: 'Counter Service',
114
+ imageStatus: 'Active',
115
+ imagePurpose: 'Application',
116
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
117
+ reviewHistory: [],
118
+ }
119
+ end
120
+
121
+ def build_csudl_signature
122
+ image_id = @unique_images == false ? CSUDL_SIGNATURE_IMAGE_ID : Random.uuid
123
+
124
+ DVLA::Application::ImageUtility.store_local_image_in_image_utility(image_id:, image_type: 'Signature', image_purpose: 'Application', image_origin: 'User', image_file_type: 'image/tiff', image_path: '../fixtures/signature/csudl_signature_image.tiff')
125
+
126
+ {
127
+ imageId: image_id,
128
+ imageType: 'Signature',
129
+ imageSource: 'image-utility',
130
+ imageOriginType: 'Counter Service',
131
+ imageStatus: 'Active',
132
+ imagePurpose: 'Application',
133
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
134
+ reviewHistory: [],
135
+ }
136
+ end
137
+
138
+ def build_csudl_passport_signature
139
+ image_id = @unique_images == false ? CSUDL_PASSPORT_SIGNATURE_IMAGE_ID : Random.uuid
140
+
141
+ DVLA::Application::ImageUtility.store_local_image_in_image_utility(image_id:, image_type: 'Signature', image_purpose: 'Application', image_origin: 'Passport', image_file_type: 'image/tiff', image_path: '../fixtures/signature/csudl_signature_image.tiff')
142
+
143
+ {
144
+ imageId: image_id,
145
+ imageType: 'Signature',
146
+ imageSource: 'image-utility',
147
+ imageOriginType: 'Passport',
148
+ imageStatus: 'Active',
149
+ imagePurpose: 'Application',
150
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
151
+ reviewHistory: [],
152
+ }
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,85 @@
1
+ require_relative('photo_images.rb')
2
+
3
+ module DVLA
4
+ module Application
5
+ class CSUDLPhotoSignatureImagesFactory < PhotoImagesFactory
6
+ def initialize(photo_review_state, signature_review_state, unique_images, use_passport_images:, passport_images_preprocessed:)
7
+ @use_signature_passport_images = use_passport_images
8
+ @signature_review_state = signature_review_state
9
+ image_factory = DVLA::Application::CSUDLPhotoSignatureImageFactory.new(unique_images:)
10
+ super(photo_review_state, unique_images, use_passport_images:, passport_images_preprocessed:, additional_passport_image_available: false, image_factory:)
11
+ end
12
+
13
+ def build
14
+ photo_images = super
15
+
16
+ signature_images = build_signature_images
17
+
18
+ images = photo_images + signature_images
19
+ images += build_csudl_images
20
+ images.select { |i| !i.nil? }
21
+ end
22
+
23
+ def build_signature_images
24
+ if(@use_signature_passport_images)
25
+ return build_passport_signatures
26
+ end
27
+
28
+ case @signature_review_state
29
+ when DVLA::Application::SignatureReviewState::CLERK_IN_PROGRESS, nil
30
+ build_clerk_signature
31
+ when DVLA::Application::SignatureReviewState::CLERK_REJECTED
32
+ build_clerk_signature_rejected
33
+ when DVLA::Application::SignatureReviewState::CLERK_APPROVED
34
+ build_clerk_signature_approved
35
+ else
36
+ raise 'Invalid review state passed to the Images factory'
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ # Overridden from base class
43
+
44
+ def build_clerk
45
+ [build_user, @image_factory.build(:csudl_photo)].flatten
46
+ end
47
+
48
+ def build_passport_images
49
+ [@image_factory.build(:comparison), @image_factory.build(:csudl_passport_photo)]
50
+ end
51
+
52
+ def build_passport_signatures
53
+ [@image_factory.build(:csudl_passport_signature)]
54
+ end
55
+
56
+ def build_clerk_signature
57
+ [@image_factory.build(:csudl_signature)].flatten
58
+ end
59
+
60
+ def build_csudl_images
61
+ [
62
+ @image_factory.build(:photocard_front),
63
+ @image_factory.build(:photocard_back),
64
+ ]
65
+ end
66
+
67
+ def build_clerk_signature_rejected
68
+ add_review(build_clerk_signature, create_review('Clerk', 'Rejection on standards', ['Signature is not clear']))
69
+ end
70
+
71
+ def build_clerk_signature_approved
72
+ add_review(build_clerk_signature, create_review('Clerk', 'Success'))
73
+ end
74
+
75
+ def add_review(images, *reviews, target_origin_type: 'Counter Service', target_image_type: 'Application')
76
+ images.map do |image|
77
+ if image[:imageOriginType] == target_origin_type && image[:imagePurpose] == target_image_type
78
+ reviews.each { |review| image[:reviewHistory].push(review) }
79
+ end
80
+ image
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,32 @@
1
+ def set_any_organs(any_organs_bool:)
2
+ # any_organs true means individual organs are all false
3
+ # any_organs false means individual organs are all true
4
+ individual_organs = !any_organs_bool
5
+ FM[:organ_donor].build(attributes: { any_organs: any_organs_bool,
6
+ kidneys: individual_organs,
7
+ liver: individual_organs,
8
+ heart: individual_organs,
9
+ cornea: individual_organs,
10
+ pancreas: individual_organs,
11
+ lungs: individual_organs })
12
+ end
13
+
14
+ FM.factory :organ_donor, naming: :json do
15
+ any_organs { Faker::Boolean.boolean }
16
+ kidneys { any_organs ? false : Faker::Boolean.boolean }
17
+ liver { any_organs ? false : Faker::Boolean.boolean }
18
+ heart { any_organs ? false : Faker::Boolean.boolean }
19
+ cornea { any_organs ? false : Faker::Boolean.boolean }
20
+ pancreas { any_organs ? false : Faker::Boolean.boolean }
21
+ lungs { any_organs ? false : true }
22
+ end
23
+
24
+ FM.factory :organ_donor_d90_response, naming: :json do
25
+ any_organs { false }
26
+ kidneys { false }
27
+ liver { false }
28
+ heart { false }
29
+ cornea { false }
30
+ pancreas { true }
31
+ lungs { false }
32
+ end
@@ -0,0 +1,73 @@
1
+ module DVLA
2
+ module Application
3
+ class PersonFactory
4
+ def build
5
+ # https://bitbucket.tooling.dvla.gov.uk/projects/AP/repos/drivers-application-external-ui/browse/functional-tests/lib/seeders/driver_seeders.rb#37
6
+ identity_builder = DVLA::Poirot.create_identity_builder
7
+
8
+ identity_builder = identity_builder.gbr_citizen
9
+ .hmpo_pass
10
+ .dwp_pass
11
+ .experian_fail
12
+ .home_office_fail
13
+ .alive
14
+
15
+ build_person_using_identity(identity_builder.build)
16
+ end
17
+
18
+ def build_person_using_identity(identity)
19
+ person = Person.new
20
+ person.identity = identity
21
+ person.identity.email = person.convert_email_address(email_address: person.identity.email,
22
+ prefix: Settings.application_helper.applicant_email.email_prefix,
23
+ domain: Settings.application_helper.applicant_email.email_domain)
24
+ person.language = 'English'
25
+ person.address = FM[:application_unstructured_address].build
26
+ person
27
+ end
28
+ end
29
+
30
+ class Person
31
+ attr_accessor :identity
32
+ attr_accessor :language
33
+ attr_accessor :address
34
+
35
+ def to_applicant
36
+ {
37
+ title: @identity.title,
38
+ firstNames: @identity.first_names,
39
+ lastName: @identity.last_name,
40
+ dateOfBirth: @identity.date_of_birth,
41
+ sex: @identity.gender.capitalize,
42
+ countryOfBirth: @identity.country_of_birth.tr('_', ' ').titleize,
43
+ emailAddress: @identity.email,
44
+ languagePreference: @language,
45
+ passportNumber: '492392652',
46
+ address: {
47
+ unstructuredAddress: @address,
48
+ },
49
+ identityTokenData: {
50
+ confidenceLevel: 'MEDIUM',
51
+ verificationResult: 'PASSED',
52
+ verificationDetail: 'DVLA, HMPO',
53
+ passportNumber: '492392652',
54
+ hasProvidedANationalInsuranceNumber: true,
55
+ },
56
+ }
57
+ end
58
+
59
+ # convert email address to allow a new prefix and domain
60
+ # @param email_address [String] email address generated by Poirot.
61
+ # @param prefix [String] Used to prepend project name to start of email address provided by `Settings.application_helper.applicant_email.email_prefix` - an empty string by default
62
+ # @param domain [String] To overwrite @mailsac.com domain set by Poirot provided by `Settings.application_helper.applicant_email.email_domain` is 'dvla.msdc.co' by default
63
+ # @return [String]
64
+ def convert_email_address(email_address:, prefix:, domain:)
65
+ if domain.include? 'mailsac.com'
66
+ "#{prefix}#{email_address}"
67
+ else
68
+ "#{prefix}#{email_address}".gsub(Regexp.new('(?<=@)[^.]+(?=\.).*'), domain)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,147 @@
1
+ module DVLA
2
+ module Application
3
+ class PhotoImageFactory
4
+ def initialize(unique_images:)
5
+ @unique_images = unique_images
6
+ end
7
+
8
+ def build(type)
9
+ case type
10
+ when :user
11
+ build_user
12
+ when :comparison
13
+ build_comparison
14
+ when :passport_available
15
+ build_passport_available
16
+ when :passport_moved
17
+ build_passport_moved
18
+ when :passport_active
19
+ build_passport_active_utility
20
+ when :passport_active_service
21
+ build_passport_active_service
22
+ else
23
+ raise 'Unknown image type'
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ USER_IMAGE_ID = '617d6689-e03e-44e7-962d-ceb6e158e031'.freeze
30
+ COMPARISON_IMAGE_ID = '311cdbb5-bd58-4c3e-ad6d-0d188f3756bb'.freeze
31
+ PASSPORT_IMAGE_SERVICE_ID = '846a05d7-259b-4b25-a780-33f9e871847b'.freeze
32
+ PASSPORT_IMAGE_UTILITY_ID = '685200b4-4217-4892-b193-da45c6daf984'.freeze
33
+
34
+ def build_user
35
+ image_id = @unique_images == false ? USER_IMAGE_ID : Random.uuid
36
+ DVLA::Application::ImageService.put_user_uploaded_image_in_service(image_id:)
37
+ # This next step ensure image has seeded and D90 transformed image exists
38
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_origin: 'User')
39
+
40
+ {
41
+ imageId: image_id,
42
+ imageType: 'Photo',
43
+ imageSource: 'driving-licence-image-service',
44
+ imageOriginType: 'User',
45
+ imageStatus: 'Active',
46
+ imagePurpose: 'Application',
47
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
48
+ reviewHistory: [],
49
+ }
50
+ end
51
+
52
+ def build_comparison
53
+ image_id = @unique_images == false ? COMPARISON_IMAGE_ID : Random.uuid
54
+ DVLA::Application::ImageService.put_comparison_image_in_service(image_id:)
55
+ # This next step ensure image has seeded and D90 transformed image exists
56
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_origin: 'User')
57
+
58
+ DVLA::Application::ImageUtility.store_image_in_image_utility(image_id:)
59
+
60
+ {
61
+ imageId: image_id,
62
+ imageType: 'Photo',
63
+ imageSource: 'image-utility',
64
+ imageOriginType: 'Driving Licence',
65
+ imageStatus: 'Active',
66
+ imagePurpose: 'Comparison',
67
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
68
+ reviewHistory: [],
69
+ }
70
+ end
71
+
72
+ def build_passport_available
73
+ image_id = @unique_images == false ? PASSPORT_IMAGE_SERVICE_ID : Random.uuid
74
+ DVLA::Application::ImageService.put_passport_image_in_service(image_id:)
75
+ # This next step ensure image has seeded and D90 transformed image exists
76
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_origin: 'Passport')
77
+
78
+ {
79
+ imageId: image_id,
80
+ imageType: 'Photo',
81
+ imageSource: 'driving-licence-image-service',
82
+ imageOriginType: 'Passport',
83
+ imageStatus: 'Replaced',
84
+ imagePurpose: 'Application',
85
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
86
+ reviewHistory: [],
87
+ }
88
+ end
89
+
90
+ def build_passport_moved
91
+ image_id = @unique_images == false ? PASSPORT_IMAGE_SERVICE_ID : Random.uuid
92
+ DVLA::Application::ImageService.put_passport_image_in_service(image_id:)
93
+ # This next step ensure image has seeded and D90 transformed image exists
94
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_origin: 'Passport')
95
+
96
+ {
97
+ imageId: image_id,
98
+ imageType: 'Photo',
99
+ imageSource: 'driving-licence-image-service',
100
+ imageOriginType: 'Passport',
101
+ imageStatus: 'Moved',
102
+ imagePurpose: 'Application',
103
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
104
+ reviewHistory: [],
105
+ }
106
+ end
107
+
108
+ def build_passport_active_service
109
+ image_id = @unique_images == false ? PASSPORT_IMAGE_SERVICE_ID : Random.uuid
110
+ DVLA::Application::ImageService.put_passport_image_in_service(image_id:)
111
+ # This next step ensure image has seeded and D90 transformed image exists
112
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_origin: 'Passport')
113
+
114
+ {
115
+ imageId: image_id,
116
+ imageType: 'Photo',
117
+ imageSource: 'driving-licence-image-service',
118
+ imageOriginType: 'Passport',
119
+ imageStatus: 'Active',
120
+ imagePurpose: 'Application',
121
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
122
+ reviewHistory: [],
123
+ }
124
+ end
125
+
126
+ def build_passport_active_utility
127
+ image_id = @unique_images == false ? PASSPORT_IMAGE_UTILITY_ID : Random.uuid
128
+ DVLA::Application::ImageService.put_passport_image_in_service(image_id:)
129
+ # This next step ensure image has seeded and D90 transformed image exists
130
+ DVLA::Application::ImageService.get_base64_image_data(image_id:, image_origin: 'Passport')
131
+
132
+ DVLA::Application::ImageUtility.store_image_in_image_utility(image_id:, image_purpose: 'Application', image_origin: 'Passport')
133
+
134
+ {
135
+ imageId: image_id,
136
+ imageType: 'Photo',
137
+ imageSource: 'image-utility',
138
+ imageOriginType: 'Passport',
139
+ imageStatus: 'Active',
140
+ imagePurpose: 'Application',
141
+ timeCreated: Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
142
+ reviewHistory: [],
143
+ }
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,183 @@
1
+ module DVLA
2
+ module Application
3
+ class PhotoImagesFactory
4
+ def initialize(review_state, unique_images, use_passport_images:, passport_images_preprocessed:, additional_passport_image_available:, image_factory: nil)
5
+ @use_photo_passport_images = use_passport_images
6
+ @passport_images_preprocessed = passport_images_preprocessed
7
+ @additional_passport_image_available = additional_passport_image_available
8
+ @time = Time.now - 3600
9
+ @review_state = review_state
10
+
11
+ @image_factory = image_factory || DVLA::Application::PhotoImageFactory.new(unique_images:)
12
+ end
13
+
14
+ def build
15
+ if @use_photo_passport_images
16
+ return build_passport_images.select { |i| !i.nil? }
17
+ end
18
+
19
+ images = case @review_state
20
+ when DVLA::Application::ReviewState::CLERK_IN_PROGRESS, nil
21
+ build_clerk
22
+ when DVLA::Application::ReviewState::CLERK_REJECTED
23
+ build_clerk_rejected
24
+ when DVLA::Application::ReviewState::CLERK_REJECT_COMPARISON_PHOTO
25
+ build_clerk_comparison_rejected
26
+ when DVLA::Application::ReviewState::FRAUD_REJECT_COMPARISON_PHOTO
27
+ build_fraud_comparison_rejected
28
+ when DVLA::Application::ReviewState::SUPERVISOR_REJECT_COMPARISON_PHOTO
29
+ build_supervisor_comparison_rejected
30
+ when DVLA::Application::ReviewState::CLERK_REFER_TO_SUPERVISOR_STANDARDS
31
+ build_clerk_refer_to_supervisor_standards
32
+ when DVLA::Application::ReviewState::CLERK_REFER_TO_SUPERVISOR_COMPARE
33
+ build_clerk_refer_to_supervisor_compare
34
+ when DVLA::Application::ReviewState::CLERK_APPROVED
35
+ build_clerk_approved
36
+ when DVLA::Application::ReviewState::SUPERVISOR_REJECTED
37
+ build_supervisor_rejected
38
+ when DVLA::Application::ReviewState::SUPERVISOR_REFER_TO_FRAUD
39
+ build_supervisor_refer_to_fraud
40
+ when DVLA::Application::ReviewState::SUPERVISOR_APPROVED
41
+ build_supervisor_approved
42
+ when DVLA::Application::ReviewState::FRAUD_BEGIN_INVESTIGATION
43
+ build_fraud_begin_investigation
44
+ when DVLA::Application::ReviewState::FRAUD_REVIEW_REJECTION_WITH_REFUND
45
+ build_fraud_review_rejection_with_refund
46
+ when DVLA::Application::ReviewState::FRAUD_REVIEW_REJECTION_WITHOUT_REFUND
47
+ build_fraud_review_rejection_without_refund
48
+ when DVLA::Application::ReviewState::FRAUD_REVIEW_APPROVED
49
+ build_fraud_review_approved
50
+ when DVLA::Application::ReviewState::FRAUD_APPROVED
51
+ build_fraud_approved
52
+ when DVLA::Application::ReviewState::FRAUD_REJECTED
53
+ build_fraud_rejected
54
+ else
55
+ raise 'Invalid review state passed to the Images factory'
56
+ end
57
+
58
+ images += passport_available_image if @additional_passport_image_available
59
+ images.select { |i| !i.nil? }
60
+ end
61
+
62
+ private
63
+
64
+ def time
65
+ @time = @time + 60
66
+ end
67
+
68
+ def add_review(images, *reviews, target_origin_type: 'User', target_image_type: 'Application')
69
+ images.map do |image|
70
+ if image[:imageSource] == 'driving-licence-image-service' && image[:imageOriginType] == target_origin_type && image[:imagePurpose] == target_image_type
71
+ reviews.each { |review| image[:reviewHistory].push(review) }
72
+ end
73
+ image
74
+ end
75
+ end
76
+
77
+ def create_review(review_level, outcome, outcome_reasons = nil)
78
+ {
79
+ reviewLevel: review_level,
80
+ outcome:,
81
+ outcomeReasons: outcome_reasons == nil ? nil : outcome_reasons,
82
+ timeCompleted: time.utc.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'),
83
+ taskId: SecureRandom.uuid,
84
+ }.compact
85
+ end
86
+
87
+ def build_user
88
+ [@image_factory.build(:comparison)]
89
+ end
90
+
91
+ def build_clerk
92
+ [build_user, @image_factory.build(:user)].flatten
93
+ end
94
+
95
+ def build_passport_images
96
+ if @passport_images_preprocessed
97
+ [@image_factory.build(:passport_moved),
98
+ @image_factory.build(:passport_active)]
99
+ else
100
+ [@image_factory.build(:comparison),
101
+ @image_factory.build(:passport_active_service)]
102
+ end
103
+ end
104
+
105
+ def passport_available_image
106
+ [@image_factory.build(:passport_available)]
107
+ end
108
+
109
+ def build_clerk_rejected
110
+ add_review(build_clerk, create_review('Clerk', 'Rejection on standards', [
111
+ 'Full head not visible',
112
+ 'Background is not plain',
113
+ ]))
114
+ end
115
+
116
+ def build_clerk_comparison_rejected
117
+ add_review(build_clerk, create_review('Clerk', 'Reject comparison photo'), target_origin_type: 'Home Office', target_image_type: 'Comparison')
118
+ end
119
+
120
+ def build_fraud_comparison_rejected
121
+ add_review(build_supervisor_refer_to_fraud, create_review('Fraud', 'Reject comparison photo'), target_origin_type: 'Home Office', target_image_type: 'Comparison')
122
+ end
123
+
124
+ def build_supervisor_comparison_rejected
125
+ add_review(build_clerk_refer_to_supervisor_standards, create_review('Supervisor', 'Reject comparison photo'), target_origin_type: 'Home Office', target_image_type: 'Comparison')
126
+ end
127
+
128
+ def build_clerk_refer_to_supervisor_standards
129
+ add_review(build_clerk, create_review('Clerk', 'Referral at standards'))
130
+ end
131
+
132
+ def build_clerk_refer_to_supervisor_compare
133
+ add_review(build_clerk, create_review('Clerk', 'Referral at compare'))
134
+ end
135
+
136
+ def build_clerk_approved
137
+ add_review(build_clerk, create_review('Clerk', 'Success'))
138
+ end
139
+
140
+ def build_supervisor_rejected
141
+ add_review(build_clerk_refer_to_supervisor_standards, create_review('Supervisor', 'Rejection on standards', [
142
+ 'Full head not visible',
143
+ 'Background is not plain',
144
+ ]))
145
+ end
146
+
147
+ def build_supervisor_refer_to_fraud
148
+ add_review(build_clerk_refer_to_supervisor_standards, create_review('Supervisor', 'Referral at compare'))
149
+ end
150
+
151
+ def build_supervisor_approved
152
+ add_review(build_clerk_refer_to_supervisor_standards, create_review('Supervisor', 'Success'))
153
+ end
154
+
155
+ def build_fraud_begin_investigation
156
+ add_review(build_supervisor_refer_to_fraud, create_review('Fraud', 'Begin investigation', %w[ABcd567-]))
157
+ end
158
+
159
+ def build_fraud_review_rejection_with_refund
160
+ add_review(build_fraud_begin_investigation, create_review('Fraud review', 'Rejection with refund'))
161
+ end
162
+
163
+ def build_fraud_review_rejection_without_refund
164
+ add_review(build_fraud_begin_investigation, create_review('Fraud review', 'Rejection no refund'))
165
+ end
166
+
167
+ def build_fraud_review_approved
168
+ add_review(build_fraud_begin_investigation, create_review('Fraud review', 'Success'))
169
+ end
170
+
171
+ def build_fraud_approved
172
+ add_review(build_clerk, create_review('Clerk', 'Referral at standards'), create_review('Clerk', 'Referral at compare'))
173
+ end
174
+
175
+ def build_fraud_rejected
176
+ add_review(build_clerk, create_review('Clerk', 'Referral at standards'), create_review('Clerk', 'Referral at compare'), create_review('Clerk', 'Rejection on standards', [
177
+ 'Full head not visible',
178
+ 'Background is not plain',
179
+ ]))
180
+ end
181
+ end
182
+ end
183
+ end