UNPKG

1.47 kBJavaScriptView Raw
1"use strict";
2
3const Auth = require('./Auth');
4const assert = require('assert');
5
6describe(Auth.name, function ()
7{
8 let instance;
9 beforeEach(function ()
10 {
11 instance = new Auth('test', {
12 users: {
13 lookup: {
14 a: {
15 id: 'a'
16 },
17 b: {
18 id: 'b',
19 credentials: [{
20 type: 'test',
21 value: 'a'
22 }]
23 }
24 }
25 }
26 });
27 });
28
29 it(`should have a method`, async function ()
30 {
31 assert.deepEqual(instance.method, 'test')
32 })
33
34 it(`install is abstract`, async function ()
35 {
36 try
37 {
38 instance.install();
39 }
40 catch (e)
41 {
42 return
43 }
44 throw new Error('FAIL');
45 })
46
47 it(`should find users by credential`, async function ()
48 {
49 assert.deepEqual(instance.findUser('b'), false)
50 assert.deepEqual(instance.findUser('a')
51 .id, 'b')
52 })
53
54 it(`should create user from profile`, async function ()
55 {
56 instance.custom.xxx = {
57 derive: () => 'xxx'
58 }
59 instance.custom.yyy = {
60 derive: () => false
61 }
62 instance.custom.zzz = {}
63 const user = instance.createUserFromProfile({
64 id: 'testXX'
65 });
66 assert.deepEqual(user.credentials, [{
67 type: instance.method,
68 value: 'testXX'
69 }])
70 assert.notDeepEqual(user.id, 'testXX')
71 assert.deepEqual(user.xxx, 'xxx')
72 assert.deepEqual(user.yyy, undefined)
73 assert.deepEqual(user.zzz, undefined)
74 })
75});