# frozen_string_literal: true require 'faker' module Iwoca # This class can be used to generate fake customers for test purposes. # It is based on the minimum data requirements described here: # https://iwoca.stoplight.io/docs/lapi-uk/branches/2.1.0/2c44db4bf20fb-meeting-minimum-data-requirements class CustomerGenerator attr_accessor :id, :first_name, :last_name, :email, :phone, :address, :date_of_birth, :city attr_accessor :postcode DEFAULTS = { id: SecureRandom.hex(4), first_name: Faker::Name.first_name, last_name: Faker::Name.last_name, email: Faker::Internet.email, phone: Faker::PhoneNumber.cell_phone_in_e164, address: Faker::Address.street_address, date_of_birth: Faker::Date.birthday(min_age: 23, max_age: 65), city: Faker::Address.city, postcode: Faker::Address.postcode }.freeze def self.generate(params = {}) new(DEFAULTS.merge(params)).generate end def initialize(params = {}) Faker::Config.locale = 'en-GB' DEFAULTS.each do |key, default_value| send("#{key}=", params[key] || default_value) end end def generate { data: { company: company_information, people: [user_information] } } end def company_information { company_number: '09525857', last_12_months_turnover: { amount: 70_000, valid_from: "2019-08-24T14:15:22Z" }, registered_company_name: 'HOKO LTD', trading_from_date: '2015-05-22', type: 'limited_liability_company', industry: 'B | Mining and Quarrying', vat_status: { is_vat_registered: true, registered_over_3_months: true, }, registered_address: { postcode: 'W1T 3NF', street_line_1: 'Berners House', street_line_2: '47-48 Berners Street', town: 'London', country: 'GB' } } end def user_information { date_of_birth: date_of_birth, emails: emails, uid: SecureRandom.uuid, first_name: first_name, last_name: last_name, phones: phones, roles: %w[applicant shareholder guarantor director], residential_addresses: residential_addresses, privacy_policy: { agreed: true, valid_from: DateTime.now - 1 } } end def phones [ { number: phone, type: 'primary' } ] end def emails [ { email: email, marketing_opt_in: { agreed: true, valid_from: DateTime.now }, type: 'primary' } ] end def residential_addresses [ { country: 'GB', residential_status: 'owner_no_mortgage', street_line_1: address, street_line_2: '', town: city, postcode: postcode } ] end end end