Class: Optimum::CustomerGenerator

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

Overview

This class can be used to generate fake customers for test purposes

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.phone_number,
  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.



27
28
29
30
31
32
33
# File 'lib/optimum/customer_generator.rb', line 27

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.



8
9
10
# File 'lib/optimum/customer_generator.rb', line 8

def address
  @address
end

#cityObject

Returns the value of attribute city.



8
9
10
# File 'lib/optimum/customer_generator.rb', line 8

def city
  @city
end

#date_of_birthObject

Returns the value of attribute date_of_birth.



8
9
10
# File 'lib/optimum/customer_generator.rb', line 8

def date_of_birth
  @date_of_birth
end

#emailObject

Returns the value of attribute email.



8
9
10
# File 'lib/optimum/customer_generator.rb', line 8

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



8
9
10
# File 'lib/optimum/customer_generator.rb', line 8

def first_name
  @first_name
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/optimum/customer_generator.rb', line 8

def id
  @id
end

#last_nameObject

Returns the value of attribute last_name.



8
9
10
# File 'lib/optimum/customer_generator.rb', line 8

def last_name
  @last_name
end

#phoneObject

Returns the value of attribute phone.



8
9
10
# File 'lib/optimum/customer_generator.rb', line 8

def phone
  @phone
end

#postcodeObject

Returns the value of attribute postcode.



9
10
11
# File 'lib/optimum/customer_generator.rb', line 9

def postcode
  @postcode
end

Class Method Details

.generate(params = {}) ⇒ Object



23
24
25
# File 'lib/optimum/customer_generator.rb', line 23

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

Instance Method Details

#company_informationObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/optimum/customer_generator.rb', line 55

def company_information
  {
    last_12_months_turnover: {
      amount: 0.0
    },
    registered_company_name: 'HOKO LTD',
    industry: 'B | Mining and Quarrying',
    company_number: '09525857',
    type: 'limited_liability_company',
    trading_from_date: '2015-05-22',
    registered_address: {
      postcode: 'W1T 3NF',
      street_line_1: 'Berners House',
      street_line_2: '47-48 Berners Street',
      town: 'London',
      country: 'GB'
    },
    vat_status: {
      is_vat_registered: true
    }
  }
end

#emailsObject



105
106
107
108
109
110
111
112
113
# File 'lib/optimum/customer_generator.rb', line 105

def emails
  [
    {
      uid: SecureRandom.uuid,
      email: email,
      type: 'primary'
    }
  ]
end

#generateObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/optimum/customer_generator.rb', line 35

def generate
  {
    data: {
      application: {
        company: company_information,
        people: [user_information],
        requested_products: {
          credit_facility: {
            approval: {
              amount: 123_123,
              duration: 12,
              detailed_purpose: 'business loan'
            }
          }
        }
      }
    }
  }
end

#phonesObject



95
96
97
98
99
100
101
102
103
# File 'lib/optimum/customer_generator.rb', line 95

def phones
  [
    {
      uid: SecureRandom.uuid,
      number: phone,
      type: 'primary'
    }
  ]
end

#residential_addressesObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/optimum/customer_generator.rb', line 115

def residential_addresses
  [
    {
      uid: SecureRandom.uuid,
      town: city,
      street_line_1: address,
      street_line_2: '',
      country: 'GB',
      postcode: postcode,
      house_number: '10',
      residential_status: 'owner_no_mortgage'
    }
  ]
end

#user_informationObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/optimum/customer_generator.rb', line 78

def user_information
  {
    uid: SecureRandom.uuid,
    first_name: first_name,
    last_name: last_name,
    date_of_birth: date_of_birth,
    roles: %w[applicant shareholder guarantor director],
    phones: phones,
    emails: emails,
    residential_addresses: residential_addresses,
    privacy_policy: {
      agreed: true,
      datetime: DateTime.now
    }
  }
end