Module: Musoni::TestHelper

Defined in:
lib/musoni_ruby/support/test_helper.rb

Instance Method Summary collapse

Instance Method Details

#account_attributes(n = :first) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/musoni_ruby/support/test_helper.rb', line 33

def (n= :first)
	client = create_musoni_client(n)
	{
		clientId: client.id,
		productId: "1",
		submittedOnDate:  Time.zone.now,
		fieldOfficerId: "1",
		charges: [],
		allowOverdraft: false
	}
end

#borrower_dataObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/musoni_ruby/support/test_helper.rb', line 142

def borrower_data
	{
		gender: "Male",
		birthdate: "19-08-2009",
		marital_status: "Married",
		has_children: "Yes",
		household_size: 1,
		dependants_no: 4,
		language_use: "Kiswahili",
		occupation: "Market Vendor",
		mobile_use: "Ignore",
		phones_owned: 2,
		active_savings_devices: "Commercial Bank",
		savings_emergency: 900,
		savings_school: 2200,
		savings_asset: 9500,
		savings_entertainment: 3100,
		savings_medical: 2100,
		savings_business: 2400,
		savings_other: 6200,
		credit_limit_mshwari: 1700,
		saving_frequency: "Weekly",
		remittance_amount: 4900,
		remittance_location: "Armenia",
		remittance_frequency: "Other",
		income_weekly: 2700,
		household_assets: '["Television or computer", "Clock/Watch"]',
		monthly_expense_food: 7800,
		monthly_expense_housing: 7000,
		monthly_expense_school: 5400,
		monthly_expense_medical: 900,
		monthly_expense_health: 5100,
		monthly_expense_tranport: 6200,
		manages_business: "Yes",
		biz_experience: 4900,
		ledger_book: 6000,
		stock_spend: 900,
		stock_value: 8400,
		last_mmoney_out: "1,000-5,000",
		last_mmoney_in: "100-500",
		data_mpesa: "234,343",
		survey_id: 123,
		dateFormat: "DD-MM-YYYY",
		locale: "en_GB"
	}
end

#client_attributesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/musoni_ruby/support/test_helper.rb', line 10

def client_attributes
	{
		officeId: "2",
		firstname:  Faker::Name.first_name,
		staffId: "1",
		lastname:  Faker::Name.last_name,
		middlename:  Faker::Name.first_name,
		externalId: rand(100000),
		mobileNo: "07234#{rand(10000)}",
		submittedOnDate: Time.zone.now,
		active: "true",
		activationDate:  Time.zone.now
	}
end

#create_borrower_datatableObject



103
104
105
106
# File 'lib/musoni_ruby/support/test_helper.rb', line 103

def create_borrower_datatable
	client = create_musoni_client
	@@musoni_borrower_datatable ||= Musoni::Datatable.create(:cct_Borrower_Details,client.id,borrower_data)
end

#create_client_datatableObject



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/musoni_ruby/support/test_helper.rb', line 91

def create_client_datatable
	client = create_musoni_client
	datatable_attributes = {
     email:  Faker::Internet.email,
     Client_Type: %w(Borrower Lender).sample,
     dateFormat: "DD-MM-YYYY",
     locale: "en_GB"
   }

	@@musoni_client_datatable ||= Musoni::Datatable.create(:ml_client_details,client.id,datatable_attributes)
end

#create_firstaccess_datatableObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/musoni_ruby/support/test_helper.rb', line 127

def create_firstaccess_datatable
	client = create_musoni_client
	datatable_attributes = {
		Status: "Approved",
		Risk_Bucket: "Very Low",
		Loan_Size: "10000",
		Interest_Rate: "10.05",
		dateFormat: "dd-MM-yyyy",
		locale: "en_GB",
		submittedon_date: Time.zone.now,
		submittedon_userid: 1
	}
	@@musoni_firstaccess_datatable ||= Musoni::Datatable.create(:cct_First_Access_Score,client.id,datatable_attributes)
end

#create_musoni_client(n = :first) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/musoni_ruby/support/test_helper.rb', line 2

def create_musoni_client(n= :first)
	@@musoni_client ||={}
	@@musoni_client[:third] ||= Musoni::Client.create(client_attributes) #if n == :third
	@@musoni_client[:second] ||= Musoni::Client.create(client_attributes) #if n == :second
	@@musoni_client[:first] ||= Musoni::Client.create(client_attributes) #if n == :first
	@@musoni_client[n]
end

#create_musoni_loanObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/musoni_ruby/support/test_helper.rb', line 45

def create_musoni_loan
	client = create_musoni_client
	now = Time.zone.now
	tomorrow = (Time.zone.now + 86400)
	loan_options = {
     submittedOnDate:  now, 
     clientId:  client.id,
     productId: "1",
     loanOfficerId: "1",
     loanPurposeId: "1" , #### category []
     principal:  "10000", ###
     loanTermFrequency: "1", ### 
     loanTermFrequencyType: "2",# weekly  [1,2,3]>[Daily, weekly, monthly]
     numberOfRepayments: "1", ###
     repaymentEvery: "1",
     repaymentFrequencyType: "2",
     transactionProcessingStrategyId: "1",
     interestRatePerPeriod:  '5', ###
     expectedDisbursementDate:  now, ###
     amortizationType: "1", #?? Equal payments. what else is there
     interestType: "1",
     interestCalculationPeriodType: "1",
     inArrearsTolerance: "0",
     interestChargedFromDate:  now, # Interest is fixed?
     repaymentsStartingFromDate:  tomorrow,
     charges: [], # Might put here charges
     loanType: "individual", #Default
     linkAccountId: "",
     graceOnPrincipalPayment: "0",
     graceOnInterestCharged: "0",
     graceOnInterestPayment: "0",
     fundId: "1",
     createStandingInstructionAtDisbursement: false
   }

	@@musoni_loan ||= Musoni::Loan.create(loan_options)
end

#create_musoni_savings_account(n = :first) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/musoni_ruby/support/test_helper.rb', line 25

def (n= :first)
	@@musoni_savings_account ||={}
	@@musoni_savings_account[:third] ||= Musoni::SavingsAccount.create((:third)) #if n == :third
	@@musoni_savings_account[:second] ||= Musoni::SavingsAccount.create((:second)) #if n == :second
	@@musoni_savings_account[:first]  ||= Musoni::SavingsAccount.create((:first)) #if n == :first
	@@musoni_savings_account[n]
end

#create_transunion_datatableObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/musoni_ruby/support/test_helper.rb', line 108

def create_transunion_datatable
	client = create_musoni_client
	datatable_attributes =  {
		Credit_History: "24",
		NPA_Accounts: "1",
		NPA_Closed_Accounts: "1",
		NPA_Open_Accounts: "0",
		PA_Accounts: "11",
		PA_Closed_Accounts: "10",
		PA_Open_Accounts: "1",
		Response_Statuscode: "300",
		dateFormat: "dd-MM-yyyy",
		locale: "en_GB",
		submittedon_date: Time.zone.now,
		submittedon_userid: 1
	}
	@@musoni_transunion_datatable ||= Musoni::Datatable.create(:cct_TransUnion,client.id,datatable_attributes)
end