mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add unit tests
This commit is contained in:
parent
0bb12f32fa
commit
ffaac4c81b
5 changed files with 67 additions and 13 deletions
|
@ -251,7 +251,22 @@ describe "AWSSDKPersistorManager", ->
|
|||
describe "directorySize", ->
|
||||
|
||||
it "should list the directory content using s3.listObjects", (done) ->
|
||||
@s3.listObjects.callsArgWith 1, null, Contents: []
|
||||
@AWSSDKPersistorManager.directorySize @bucketName, @key, (err) =>
|
||||
expect(err).to.not.be.ok
|
||||
expect(@s3.listObjects.calledOnce, "called only once").to.be.true
|
||||
expect((@s3.listObjects.calledWith Bucket: @bucketName, Prefix: @key),
|
||||
"called with correct arguments").to.be.true
|
||||
done()
|
||||
|
||||
it "should sum directory files size", (done) ->
|
||||
it "should dispatch the error from s3.listObjects", (done) ->
|
||||
@s3.listObjects.callsArgWith 1, @error
|
||||
@AWSSDKPersistorManager.directorySize @bucketName, @key, (err) =>
|
||||
expect(err).to.equal @error
|
||||
done()
|
||||
|
||||
it "should sum directory files sizes", (done) ->
|
||||
@s3.listObjects.callsArgWith 1, null, Contents: [ { Size: 1024 }, { Size: 2048 }]
|
||||
@AWSSDKPersistorManager.directorySize @bucketName, @key, (err, size) =>
|
||||
expect(size).to.equal 3072
|
||||
done()
|
||||
|
|
|
@ -18,6 +18,10 @@ describe "FSPersistorManagerTests", ->
|
|||
unlink:sinon.stub()
|
||||
rmdir:sinon.stub()
|
||||
exists:sinon.stub()
|
||||
readdir:sinon.stub()
|
||||
openSync:sinon.stub()
|
||||
fstatSync:sinon.stub()
|
||||
closeSync:sinon.stub()
|
||||
@Rimraf = sinon.stub()
|
||||
@LocalFileWriter =
|
||||
writeStream: sinon.stub()
|
||||
|
@ -211,5 +215,15 @@ describe "FSPersistorManagerTests", ->
|
|||
|
||||
describe "directorySize", ->
|
||||
|
||||
it "should sum directory files size", (done) ->
|
||||
it "should propogate the error", (done) ->
|
||||
@Fs.readdir.callsArgWith(1, @error)
|
||||
@FSPersistorManager.directorySize @location, @name1, (err, totalsize) =>
|
||||
err.should.equal @error
|
||||
done()
|
||||
|
||||
it "should sum directory files size", (done) ->
|
||||
@Fs.readdir.callsArgWith(1, null, [ {'file1'}, {'file2'} ])
|
||||
@Fs.fstatSync.returns({size : 1024})
|
||||
@FSPersistorManager.directorySize @location, @name1, (err, totalsize) =>
|
||||
expect(totalsize).to.equal 2048
|
||||
done()
|
|
@ -22,6 +22,7 @@ describe "FileController", ->
|
|||
getFile: sinon.stub()
|
||||
deleteFile: sinon.stub()
|
||||
insertFile: sinon.stub()
|
||||
getDirectorySize: sinon.stub()
|
||||
@LocalFileWriter = {}
|
||||
@controller = SandboxedModule.require modulePath, requires:
|
||||
"./LocalFileWriter":@LocalFileWriter
|
||||
|
@ -155,5 +156,15 @@ describe "FileController", ->
|
|||
|
||||
describe "directorySize", ->
|
||||
|
||||
it "should call the file handler the directory size", (done) ->
|
||||
it "should return total directory size bytes", (done) ->
|
||||
@FileHandler.getDirectorySize.callsArgWith(2, null, 1024)
|
||||
@controller.directorySize @req, json:(result)=>
|
||||
expect(result['total bytes']).to.equal 1024
|
||||
done()
|
||||
|
||||
it "should send a 500 if there was an error", (done)->
|
||||
@FileHandler.getDirectorySize.callsArgWith(2, "error")
|
||||
@res.send = (code)->
|
||||
code.should.equal 500
|
||||
done()
|
||||
@controller.directorySize @req, @res
|
||||
|
|
|
@ -20,6 +20,7 @@ describe "FileHandler", ->
|
|||
deleteDirectory: sinon.stub()
|
||||
sendStream: sinon.stub()
|
||||
insertFile: sinon.stub()
|
||||
directorySize: sinon.stub()
|
||||
@LocalFileWriter =
|
||||
writeStream: sinon.stub()
|
||||
deleteFile: sinon.stub()
|
||||
|
@ -193,7 +194,12 @@ describe "FileHandler", ->
|
|||
@LocalFileWriter.deleteFile.calledWith(@stubbedPath).should.equal true
|
||||
done()
|
||||
|
||||
describe "directorySize", ->
|
||||
describe "getDirectorySize", ->
|
||||
|
||||
it "should call the filestore manager to get directory size", (done) ->
|
||||
beforeEach ->
|
||||
@PersistorManager.directorySize.callsArgWith(2)
|
||||
|
||||
it "should call the filestore manager to get directory size", (done)->
|
||||
@handler.getDirectorySize @bucket, @key, =>
|
||||
@PersistorManager.directorySize.calledWith(@bucket, @key).should.equal true
|
||||
done()
|
||||
|
|
|
@ -259,5 +259,13 @@ describe "S3PersistorManagerTests", ->
|
|||
|
||||
describe "directorySize", ->
|
||||
|
||||
beforeEach ->
|
||||
@S3PersistorManager = SandboxedModule.require modulePath, requires: @requires
|
||||
|
||||
it "should sum directory files size", (done) ->
|
||||
data =
|
||||
Contents: [ {Size: 1024}, {Size: 2048} ]
|
||||
@stubbedKnoxClient.list.callsArgWith(1, null, data)
|
||||
@S3PersistorManager.directorySize @bucketName, @key, (err, totalSize)=>
|
||||
totalSize.should.equal 3072
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue