Class: Iwoca::CustomerGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/iwoca/customer_generator.rb

Overview

This class can be used to generate fake customers for test purposes. It is based on the minimum data requirements described here: iwoca.stoplight.io/docs/lapi-uk/branches/2.1.0/2c44db4bf20fb-meeting-minimum-data-requirements

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ CustomerGenerator

Returns a new instance of CustomerGenerator.



29
30
31
32
33
34
35
# File 'lib/iwoca/customer_generator.rb', line 29

def initialize(params = {})
  Faker::Config.locale = 'en-GB'

  DEFAULTS.each do |key, default_value|
    send("#{key}=", params[key] || default_value)
  end
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



10
11
12
# File 'lib/iwoca/customer_generator.rb', line 10

def address
  @address
end

#cityObject

Returns the value of attribute city.



10
11
12
# File 'lib/iwoca/customer_generator.rb', line 10

def city
  @city
end

#date_of_birthObject

Returns the value of attribute date_of_birth.



10
11
12
# File 'lib/iwoca/customer_generator.rb', line 10

def date_of_birth
  @date_of_birth
end

#emailObject

Returns the value of attribute email.



10
11
12
# File 'lib/iwoca/customer_generator.rb', line 10

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



10
11
12
# File 'lib/iwoca/customer_generator.rb', line 10

def first_name
  @first_name
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/iwoca/customer_generator.rb', line 10

def id
  @id
end

#last_nameObject

Returns the value of attribute last_name.



10
11
12
# File 'lib/iwoca/customer_generator.rb', line 10

def last_name
  @last_name
end

#phoneObject

Returns the value of attribute phone.



10
11
12
# File 'lib/iwoca/customer_generator.rb', line 10

def phone
  @phone
end

#postcodeObject

Returns the value of attribute postcode.



11
12
13
# File 'lib/iwoca/customer_generator.rb', line 11

def postcode
  @postcode
end

Class Method Details

.generate(params = {}) ⇒ Object



25
26
27
# File 'lib/iwoca/customer_generator.rb', line 25

def self.generate(params = {})
  new(DEFAULTS.merge(params)).generate
end

Instance Method Details

#company_informationObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/iwoca/customer_generator.rb', line 46

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

#emailsObject



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/iwoca/customer_generator.rb', line 97

def emails
  [
    {
      email: email,
      marketing_opt_in: {
        agreed: true,
        valid_from: DateTime.now
      },
      type: 'primary'
    }
  ]
end

#generateObject



37
38
39
40
41
42
43
44
# File 'lib/iwoca/customer_generator.rb', line 37

def generate
  {
    data: {
      company: company_information,
      people: [user_information]
    }
  }
end

#phonesObject



88
89
90
91
92
93
94
95
# File 'lib/iwoca/customer_generator.rb', line 88

def phones
  [
    {
      number: phone,
      type: 'primary'
    }
  ]
end

#residential_addressesObject



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/iwoca/customer_generator.rb', line 110

def residential_addresses
  [
    {
      country: 'GB',
      residential_status: 'owner_no_mortgage',
      street_line_1: address,
      street_line_2: '',
      town: city,
      postcode: postcode
    }
  ]
end

#user_informationObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/iwoca/customer_generator.rb', line 71

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