2014-11-07 11:21:48 -04:00
|
|
|
expect = require('chai').expect
|
2014-11-26 14:22:01 -04:00
|
|
|
mock = require('../../../../tests/utils/mock')
|
2014-11-07 11:21:48 -04:00
|
|
|
fsUtils = require('./fs-utils')
|
2014-12-03 12:03:54 -04:00
|
|
|
settings = require('../../settings')
|
2014-11-26 14:22:01 -04:00
|
|
|
data = require('../../data/data')
|
2014-11-07 11:21:48 -04:00
|
|
|
|
2014-11-07 12:43:10 -04:00
|
|
|
describe 'FsUtils:', ->
|
2014-11-07 11:21:48 -04:00
|
|
|
|
|
|
|
describe '#isValidPath()', ->
|
|
|
|
|
|
|
|
it 'should return false for invalid paths', ->
|
|
|
|
|
|
|
|
for invalidPath in [
|
|
|
|
{ hello: 'world' }
|
|
|
|
1234
|
|
|
|
[ 1, 2, 3 ]
|
|
|
|
undefined
|
|
|
|
null
|
|
|
|
]
|
|
|
|
expect(fsUtils.isValidPath(invalidPath)).to.be.false
|
|
|
|
|
|
|
|
it 'should return true for valid paths', ->
|
|
|
|
|
|
|
|
for validPath in [
|
2014-12-05 10:53:59 -04:00
|
|
|
settings.get('dataPrefix')
|
2014-11-07 11:21:48 -04:00
|
|
|
'/Users/johndoe'
|
|
|
|
'../parent'
|
|
|
|
'./file/../file2'
|
|
|
|
]
|
|
|
|
expect(fsUtils.isValidPath(validPath)).to.be.true
|
2014-11-14 12:58:05 -04:00
|
|
|
|
|
|
|
describe '#isDirectory()', ->
|
|
|
|
|
2014-12-05 12:52:31 -04:00
|
|
|
FILESYSTEM =
|
|
|
|
text:
|
|
|
|
name: '/tmp/text'
|
|
|
|
contents: 'Hello World'
|
|
|
|
directory:
|
|
|
|
name: '/tmp/directory'
|
|
|
|
contents: {}
|
|
|
|
|
2014-11-17 15:20:19 -04:00
|
|
|
beforeEach (done) ->
|
2014-11-14 15:48:37 -04:00
|
|
|
mock.fs.init(FILESYSTEM)
|
2014-12-05 10:53:59 -04:00
|
|
|
data.prefix.set(settings.get('dataPrefix'), done)
|
2014-11-14 12:58:05 -04:00
|
|
|
|
|
|
|
afterEach ->
|
2014-11-14 15:48:37 -04:00
|
|
|
mock.fs.restore()
|