-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d93bc51
commit 6b9a357
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,39 @@ describe('TiAuth', () => { | |
})); | ||
}); | ||
|
||
describe('#loadGrants', () => { | ||
it('makes correct request to API', test(function() { | ||
this.mock(API).expects('get').withArgs('https://api.test/api/v1/grants'); | ||
TiAuth.loadGrants(noop); | ||
})); | ||
|
||
it('resolves with parsed Grants on success', test(function() { | ||
const api_mock = { | ||
grants: [{ | ||
user: '[email protected]', | ||
admin: true, | ||
controls: [{ | ||
oneThing: true | ||
}, { | ||
andAnother: false | ||
}] | ||
}] | ||
}; | ||
const stub = spy(); | ||
this.stub(API, 'get', (url, success) => { success(api_mock); }); | ||
TiAuth.loadGrants(stub); | ||
assert.calledWith(stub, api_mock.grants[0].controls); | ||
})); | ||
|
||
it('unauthorizes if request to API failed', test(function() { | ||
this.stub(API, 'get', (url, _, error) => { error('Nope.'); }); | ||
const stub = spy(); | ||
this.stub(Authentication, 'unauthorize', stub); | ||
TiAuth.loadGrants(); | ||
assert.calledOnce(stub); | ||
})); | ||
}); | ||
|
||
describe('#reauthorize', () => { | ||
it('delegates to Authentication#unauthorize', test(function() { | ||
const stub = spy(); | ||
|