11'use strict'
22const proxyquire = require ( 'proxyquire' )
3- const chai = require ( 'chai' )
4- const { assert } = chai
5- const dirtyChai = require ( 'dirty-chai' )
6- chai . use ( dirtyChai )
7- const sinonChai = require ( 'sinon-chai' )
8- chai . use ( sinonChai )
9- chai . should ( )
103const debug = require ( '../../lib/debug' ) . ACL
4+ const chai = require ( 'chai' )
5+ const { expect } = chai
6+ chai . use ( require ( 'chai-as-promised' ) )
117
128class PermissionSetAlwaysGrant {
139 checkAccess ( ) {
@@ -26,46 +22,37 @@ class PermissionSetAlwaysError {
2622}
2723
2824describe ( 'ACLChecker unit test' , ( ) => {
29- it ( 'should callback with null on grant success' , done => {
25+ it ( 'should callback with null on grant success' , ( ) => {
3026 let ACLChecker = proxyquire ( '../../lib/acl-checker' , {
3127 'solid-permissions' : { PermissionSet : PermissionSetAlwaysGrant }
3228 } )
3329 let graph = { }
3430 let accessType = ''
3531 let user , mode , resource , aclUrl
3632 let acl = new ACLChecker ( { debug } )
37- acl . checkAccess ( graph , user , mode , resource , accessType , aclUrl , ( err ) => {
38- assert . isUndefined ( err ,
39- 'Granted permission should result in an empty callback!' )
40- done ( )
41- } )
33+ return expect ( acl . checkAccess ( graph , user , mode , resource , accessType , aclUrl ) )
34+ . to . eventually . be . true
4235 } )
43- it ( 'should callback with error on grant failure' , done => {
36+ it ( 'should callback with error on grant failure' , ( ) => {
4437 let ACLChecker = proxyquire ( '../../lib/acl-checker' , {
4538 'solid-permissions' : { PermissionSet : PermissionSetNeverGrant }
4639 } )
4740 let graph = { }
4841 let accessType = ''
4942 let user , mode , resource , aclUrl
5043 let acl = new ACLChecker ( { debug } )
51- acl . checkAccess ( graph , user , mode , resource , accessType , aclUrl , ( err ) => {
52- assert . ok ( err instanceof Error ,
53- 'Denied permission should result in an error callback!' )
54- done ( )
55- } )
44+ return expect ( acl . checkAccess ( graph , user , mode , resource , accessType , aclUrl ) )
45+ . to . be . rejectedWith ( 'ACL file found but no matching policy found' )
5646 } )
57- it ( 'should callback with error on grant error' , done => {
47+ it ( 'should callback with error on grant error' , ( ) => {
5848 let ACLChecker = proxyquire ( '../../lib/acl-checker' , {
5949 'solid-permissions' : { PermissionSet : PermissionSetAlwaysError }
6050 } )
6151 let graph = { }
6252 let accessType = ''
6353 let user , mode , resource , aclUrl
6454 let acl = new ACLChecker ( { debug } )
65- acl . checkAccess ( graph , user , mode , resource , accessType , aclUrl , ( err ) => {
66- assert . ok ( err instanceof Error ,
67- 'Error during checkAccess should result in an error callback!' )
68- done ( )
69- } )
55+ return expect ( acl . checkAccess ( graph , user , mode , resource , accessType , aclUrl ) )
56+ . to . be . rejectedWith ( 'Error thrown during checkAccess()' )
7057 } )
7158} )
0 commit comments