-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
338 lines (281 loc) · 8.39 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
"use strict";
const rootPrefix = ".",
chai = require("chai"),
assert = chai.assert,
RequestKlass = require(rootPrefix + "/lib/request"),
qs = require("qs"),
fs = require("fs"),
configObj = JSON.parse(fs.readFileSync(rootPrefix + '/configuration.json', 'utf8')),
testObjForSignature = configObj["testObjForSignature"],
credentialObject = {
apiKey: process.env.OST_KYC_API_KEY,
secret: process.env.OST_KYC_API_SECRET
},
credentialObjectForSignatureTest = {
secret: configObj['api_secret_for_testing_signature']
},
apiEndpont = process.env.OST_KYC_API_ENDPOINT,
KYCSDK = require(rootPrefix + "/index"),
//config is optional param, timeout should be given in seconds
kycSdk = new KYCSDK({apiKey: credentialObject.apiKey, apiSecret: credentialObject.secret, apiEndpoint: apiEndpont, config:{timeout:15}}),
userService = kycSdk.services.users,
usersKycService = kycSdk.services.usersKyc,
usersKycDetailsService = kycSdk.services.usersKycDetails,
validateService = kycSdk.services.validators
;
function testSignature() {
it("Signature should match with given one", function () {
const requestObj = new RequestKlass({apiKey: '12121', apiSecret: 'dsdsd', apiEndpoint: "endpoint"}),
queryString = requestObj.formatQueryParams(testObjForSignature);
var fullQueryString = requestObj.signQueryParamsTest(configObj["testResource"], queryString, credentialObjectForSignatureTest),
queryStringObj = qs.parse(fullQueryString);
assert.equal(queryStringObj.signature, configObj["signatureExpected"]);
});
}
function testGetUsers() {
it('Testing get user',
async function () {
var userId = process.env.USER_ID
const response = await
userService.get({id: userId}).catch(function (err) {
assert.fail('GET User testcase is failed');
});
assert.equal(response.success, true);
}
)
;
}
function testGetUsersIdZero() {
it('Testing get user with 0 id',
async function () {
var userId = process.env.USER_ID
const response = await
userService.get({id: 0}).then(function(res){
assert.fail('Resource is not present. This should fail');
}).catch(function (err) {
//console.log(err)
});
}
);
}
function testGetUsersGarbageId() {
it('Testing get user with garbage id',
async function () {
try{
const response = await
userService.get({id: "&#@%#@#^#6"}).then(function(res){
assert.fail('Id is garbage. This should fail');
});
assert.fail('Id is garbage. This should fail');
}
catch (error){
const message = "missing or invalid id in request params";
if (error.message != message)
assert.fail('Id is garbage or invalid');
}
}
);
}
function testGetUsersBlanckId() {
it('Testing get user with blank id',
async function () {
try{
const response = await
userService.get({id: ""}).then(function(res){
assert.fail('Id is garbage. This should fail');
});
assert.fail('Id is garbage. This should fail');
}
catch (error){
const message = "missing or invalid id in request params";
if (error.message != message)
assert.fail('Id is garbage or invalid');
}
}
);
}
function testGetUsersList() {
it('Testing list user',
async function () {
var userId = process.env.USER_ID
const response = await
userService.list({id: userId}).catch(function (err) {
assert.fail('GET User list testcase is failed');
});
}
)
;
}
function testCreateUser() {
it('response.success should be true for testing create request',
async function () {
var email = 'alice+' + Date.now() + '_' + process.version + '@ost.com';
const response = await
userService.create({email: email}).catch(function (err) {
assert.fail('Create User testcase is failed');
});
assert.equal(response.success, true);
}
)
;
}
function testGetUserKyc() {
it("Get user's KYC",
async function () {
var userId = process.env.USER_ID
const response = await
usersKycService.get({user_id: userId}).catch(function (err) {
assert.fail('Get Users KYC testcase is failed');
});
assert.equal(response.success, true);
}
)
;
}
function testGetUserKycList() {
it("Get user's KYC",
async function () {
var userId = process.env.USER_ID
const response = await
usersKycService.get({user_id: userId}).catch(function (err) {
assert.fail('Get Users KYC testcase is failed');
});
assert.equal(response.success, true);
}
)
;
}
function testSubmitKyc() {
it("Submit KYC",
async function () {
var obj = {
'user_id': 11035,
'first_name': 'aniket',
'last_name': 'ayachit',
'birthdate': '21/12/1991',
'country': 'india',
'nationality': 'indian',
'document_id_number': 'arqpa7659a',
'document_id_file_path': '2/i/016be96da275031de2787b57c99f1471',
'selfie_file_path': '2/i/9e8d3a5a7a58f0f1be50b7876521aebc',
'residence_proof_file_path': '2/i/4ed790b2d525f4c7b30fbff5cb7bbbdb',
'ethereum_address': '0xdfbc84ccac430f2c0455c437adf417095d7ad68e',
'estimated_participation_amount': '2',
'street_address': 'afawfveav ',
'city': 'afawfveav',
'state': 'afawfveav',
'postal_code': 'afawfveav',
'investor_proof_files_path': ['2/i/9ff6374909897ca507ba3077ee8587da', '2/i/4872730399670c6d554ab3821d63ebce']
}
const response = await
usersKycService.submitKyc(obj).then(function (res) {
assert.fail('Get Users KYC testcase should pass error in response');
}).catch(function (err) {
});
}
)
;
}
function testGetPresignedUrlForPut() {
it("Get PresignedUrl for PUT",
async function () {
var userId = process.env.USER_ID
const response = await
usersKycService.getPresignedUrlPut(configObj["getPreSignedUrlObj"]).catch(function (err) {
assert.fail('Get Presigned Url For Put testcase is failed');
});
assert.equal(response.success, true);
}
)
;
}
function testGetPresignedUrlForPost() {
it("Get PresignedUrl for POST",
async function () {
var userId = process.env.USER_ID
const response = await
usersKycService.getPresignedUrlPost(configObj["getPreSignedUrlObj"]).catch(function (err) {
assert.fail('Get Presigned Url For POST testcase is failed');
});
assert.equal(response.success, true);
}
)
;
}
function testGetUserKycDetails() {
it("Get PresignedUrl for POST",
async function () {
var userId = process.env.USER_ID
const response = await
usersKycDetailsService.get({user_id: process.env.USER_ID}).catch(function (err) {
console.log("this is error", err['success']);
assert.fail('Get User KYC details testcase is failed');
});
}
)
;
}
function testValidateEthereumAddress() {
it('Verify Ethereum address',
async function () {
const response = await
validateService.verifyEthereumAddress({ethereum_address: '0x32be343b94f860124dc4fee278fdcbd38c102d88'}).then(function (r) {
console.log('response', r);
}).catch(function (err) {
console.log(err);
assert.fail('Verify eth adress failed');
});
}
)
;
}
function testemailApprove() {
it("test email approve",
async function () {
var userId = process.env.USER_ID;
const response = await
usersKycService.emailApprove({user_id: userId}).catch(function (err) {
assert.equal(err.err.code,'UNPROCESSABLE_ENTITY');
});
});
}
function testEmailDeny() {
it("test email deny",
async function () {
var userId = process.env.USER_ID;
const response = await
usersKycService.emailDeny({user_id: userId}).catch(function (err) {
assert.equal(err.err.code,'UNPROCESSABLE_ENTITY');
});
});
}
function testEmailReportIssue() {
it("test email report issue",
async function () {
var userId = process.env.USER_ID;
const response = await
usersKycService.emailReportIssue({user_id: userId}).catch(function (err) {
assert.equal(err.err.code,'UNPROCESSABLE_ENTITY');
});
});
}
function main() {
testSignature();
testGetUsers();
testGetUsersList();
testCreateUser();
testGetUserKyc();
testGetUserKycList();
testSubmitKyc();
testGetPresignedUrlForPut();
testGetPresignedUrlForPost();
testemailApprove();
testEmailDeny();
testEmailReportIssue();
testGetUserKycDetails();
testValidateEthereumAddress();
testGetUsersIdZero();
testGetUsersGarbageId();
testGetUsersBlanckId();
}
main();