UNPKG

1.59 kBJavaScriptView Raw
1"use strict";
2
3const access = require('./access');
4const assert = require('assert');
5
6describe(`access.LOGGED_IN`, function ()
7{
8
9 it(`not logged in`, function (done)
10 {
11 access.LOGGEDIN({}, {
12 error: () => done()
13 })
14 });
15
16 it(`logged in`, function (done)
17 {
18 access.LOGGEDIN({
19 user: true
20 }, {}, () => done())
21 });
22
23});
24
25describe(`access.ROLE_ONE_OF`, function ()
26{
27 let audtCalled = false;
28
29 beforeEach(function ()
30 {
31 audtCalled = false;
32 });
33
34 function audit()
35 {
36 audtCalled = true;
37 }
38
39 it(`not logged in`, function (done)
40 {
41 access.ROLE_ONE_OF()({}, {
42 error: () => done()
43 })
44 });
45
46 it(`user no roles`, function (done)
47 {
48 access.ROLE_ONE_OF({})({
49 user: {},
50 audit
51 }, {
52 error: () =>
53 {
54 if (audtCalled)
55 {
56 done()
57 }
58 }
59 })
60 });
61
62 it(`user no roles`, function (done)
63 {
64 access.ROLE_ONE_OF({
65 role: true
66 })({
67 user: {},
68 audit
69 }, {
70 error: () =>
71 {
72 if (audtCalled)
73 {
74 done()
75 }
76 }
77 })
78 });
79
80 it(`config no roles`, function (done)
81 {
82 access.ROLE_ONE_OF({})({
83 user: {
84 roles: {
85 role: true
86 }
87 },
88 audit
89 }, {
90 error: () =>
91 {
92 if (audtCalled)
93 {
94 done()
95 }
96 }
97 })
98 });
99
100 it(`config no roles`, function (done)
101 {
102 access.ROLE_ONE_OF({
103 role: true
104 })({
105 user: {
106 roles: {
107 role: true
108 }
109 },
110 audit
111 }, {}, () => done())
112 });
113
114});