mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-20 17:33:18 +00:00
Decouple permissions from http mocks and fixtures
This commit is contained in:
parent
975e133d5a
commit
043a34cc7c
@ -1,37 +1,21 @@
|
||||
_ = require('lodash')
|
||||
nock = require('nock')
|
||||
sinon = require('sinon')
|
||||
mockFs = require('mock-fs')
|
||||
expect = require('chai').expect
|
||||
resin = require('resin-sdk')
|
||||
permissions = require('./permissions')
|
||||
johnDoeFixture = require('../../tests/fixtures/johndoe')
|
||||
|
||||
describe 'Permissions:', ->
|
||||
|
||||
describe '#user()', ->
|
||||
|
||||
before ->
|
||||
@isOnlineStub = sinon.stub(resin.connection, 'isOnline')
|
||||
@isOnlineStub.yields(null, true)
|
||||
|
||||
after ->
|
||||
@isOnlineStub.restore()
|
||||
|
||||
beforeEach (done) ->
|
||||
mockFsOptions = {}
|
||||
mockFsOptions[resin.settings.get('dataPrefix')] = mockFs.directory()
|
||||
mockFs(mockFsOptions)
|
||||
|
||||
resin.data.prefix.set(resin.settings.get('dataPrefix'), done)
|
||||
|
||||
afterEach ->
|
||||
mockFs.restore()
|
||||
|
||||
describe 'if not logged in', ->
|
||||
|
||||
beforeEach (done) ->
|
||||
resin.auth.logout(done)
|
||||
beforeEach ->
|
||||
@isLoggedInStub = sinon.stub(resin.auth, 'isLoggedIn')
|
||||
@isLoggedInStub.yields(false)
|
||||
|
||||
afterEach ->
|
||||
@isLoggedInStub.restore()
|
||||
|
||||
it 'should not call the function', (done) ->
|
||||
spy = sinon.spy()
|
||||
@ -49,12 +33,12 @@ describe 'Permissions:', ->
|
||||
|
||||
describe 'if logged in', ->
|
||||
|
||||
beforeEach (done) ->
|
||||
nock(resin.settings.get('remoteUrl'))
|
||||
.post('/login_', johnDoeFixture.credentials)
|
||||
.reply(200, johnDoeFixture.token)
|
||||
beforeEach ->
|
||||
@isLoggedInStub = sinon.stub(resin.auth, 'isLoggedIn')
|
||||
@isLoggedInStub.yields(true)
|
||||
|
||||
resin.auth.login(johnDoeFixture.credentials, done)
|
||||
afterEach ->
|
||||
@isLoggedInStub.restore()
|
||||
|
||||
it 'should call the function with the correct arguments', (done) ->
|
||||
args = [ 1, 2, 3, 'foo', 'bar' ]
|
||||
|
@ -39,8 +39,6 @@
|
||||
"gulp-util": "~3.0.1",
|
||||
"mocha": "~2.0.1",
|
||||
"mocha-notifier-reporter": "~0.1.0",
|
||||
"mock-fs": "~2.3.2",
|
||||
"nock": "~0.48.2",
|
||||
"run-sequence": "~1.0.2",
|
||||
"sinon": "~1.12.1",
|
||||
"sinon-chai": "~2.6.0"
|
||||
|
7
tests/fixtures/janedoe.json
vendored
7
tests/fixtures/janedoe.json
vendored
@ -1,7 +0,0 @@
|
||||
{
|
||||
"token": "eyJ0eXAiOiJHS1QiLCJhbGciOiJajkajsiausa98938493jkjacI6Imp2aW90dGkiLCJlbWFpbCI6Imp1YW5jaGl2aW998a98dcISJDKSAVhd897d89asdiasd98a98dcISJDKSAVhd897d89asdiasd98a98dcISJDKSAVhd897d89asdiasd98a98dcISJDKSAVhd897d89asdiasd98a98dcISJDKSAVhd897d89asdiasd98a98dcISJDKSAVhd897d89asdiasd98a98dcISJDKSAVhd897d89asdiasd21lIiwiYWRtaW4ubG9naW5fYXNfdXNlciJdLCJpYXQiOjE0MTQ3NzMyMTN9.j4gMqZlnVohJt8jLpzpJWZS6rFUpNCWDwa13woo58aY",
|
||||
"credentials": {
|
||||
"username": "janedoe",
|
||||
"password": "mysecret"
|
||||
}
|
||||
}
|
7
tests/fixtures/johndoe.json
vendored
7
tests/fixtures/johndoe.json
vendored
@ -1,7 +0,0 @@
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6Imp2aW90dGkiLCJlbWFpbCI6Imp1YW5jaGl2aW90dGlAZ21haWwuY29tIiwiZ2l0bGFiX2lkIjoxNjUsImhhc1Bhc3N3b3JkU2V0Ijp0cnVlLCJwdWJsaWNfa2V5Ijp0cnVlLCJmZWF0dXJlcyI6W10sImlkIjoxNzUsInBlcm1pc3Npb25zIjpbImV3YS5kZXZpY2UuZ2V0IiwiYWRtaW4uY3JlYXRlX2ludml0ZXMiLCJhZG1pbi5ob21lIiwiYWRtaW4ubG9naW5fYXNfdXNlciJdLCJpYXQiOjE0MTQ3NzMyMTN9.j4gMqZlnVohJt8jLpzpJWZS6rFUpNCWDwa13woo58aY",
|
||||
"credentials": {
|
||||
"username": "johndoe",
|
||||
"password": "mysecret"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user