-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
58 lines (54 loc) · 1.53 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
const SmartIDAuth = require('./index.js');
const smartauth = new SmartIDAuth({
host: 'https://sid.demo.sk.ee/smart-id-rp/v1',
requestParams: {
relyingPartyUUID: '00000000-0000-0000-0000-000000000000',
relyingPartyName: 'DEMO',
certificateLevel: 'QUALIFIED',
},
});
async function _test(country, idNumber, expectedResult) {
const fail = result => {
console.log(
'FAIL',
JSON.stringify({ country, idNumber, result, expectedResult })
);
throw new Error({ country, idNumber, result, expectedResult });
};
const done = result => {
console.log('PASS', JSON.stringify({ country, idNumber, result }));
return { country, idNumber, result };
};
console.log(
`Running test for: ${country} - ${idNumber}. Expected result: ${expectedResult}`
);
try {
const session = await smartauth.authenticate(
country,
idNumber,
'Hello World'
);
if (!session.verificationCode) return fail('Did not get verificationCode');
const response = await session.getResponse();
if (response.result === expectedResult) {
return done(response.result);
} else {
return fail(response.result);
}
} catch (err) {
fail(err.message);
}
}
Promise.all([
_test('EE', '10101010005', 'OK'),
_test('LV', '010101-10006', 'OK'),
_test('LT', '10101010005', 'OK'),
_test('EE', '10101010016', 'USER_REFUSED'),
_test('LT', '10101010016', 'USER_REFUSED'),
])
.then(results => {
console.log('Tests OK! :)');
})
.catch(e => {
console.log('Tests failed :(');
});