mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add unit tests for fsWrapper
make other unit tests no longer depend on fsWrapper
This commit is contained in:
parent
c43533b5cb
commit
5f87dfb3bf
6 changed files with 118 additions and 37 deletions
|
@ -1,19 +1,10 @@
|
|||
settings = require("settings-sharelatex")
|
||||
logger = require("logger-sharelatex")
|
||||
s3Wrapper = require("./s3Wrapper")
|
||||
testWrapper = require("./testWrapper")
|
||||
|
||||
module.exports =
|
||||
selectBackend: (backend) ->
|
||||
wrappedFs = switch backend
|
||||
when "s3" then s3Wrapper
|
||||
when "test" then testWrapper
|
||||
else null
|
||||
|
||||
if !wrappedFs
|
||||
throw new Error( "Unknown filestore wrapper #{backend}" )
|
||||
|
||||
module.exports[name] = method for name,method of wrappedFs
|
||||
|
||||
if settings.fileStoreWrapper?
|
||||
module.exports.selectBackend(settings.fileStoreWrapper)
|
||||
logger.log backend:settings.filestoreBackend,"Loading backend"
|
||||
module.exports = switch settings.filestoreBackend
|
||||
when "s3"
|
||||
s3Wrapper
|
||||
else
|
||||
throw new Error( "Unknown filestore backend: #{settings.filestoreBackend}" )
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
sinon = require('sinon')
|
||||
logger = require("logger-sharelatex")
|
||||
|
||||
module.exports =
|
||||
getFileStream: sinon.stub()
|
||||
checkIfFileExists: sinon.stub()
|
||||
deleteFile: sinon.stub()
|
||||
deleteDirectory: sinon.stub()
|
||||
sendStreamToS3: sinon.stub()
|
||||
insertFile: sinon.stub()
|
||||
copyFile: sinon.stub()
|
|
@ -7,7 +7,7 @@ module.exports =
|
|||
# which backend to use
|
||||
# current options are:
|
||||
# "s3" - Amazon S3
|
||||
filestoreWrapper: "s3"
|
||||
filestoreBackend: "s3"
|
||||
|
||||
# ShareLaTeX stores binary files like images in S3.
|
||||
# Fill in your Amazon S3 credentials below.
|
||||
|
|
|
@ -9,8 +9,12 @@ SandboxedModule = require('sandboxed-module')
|
|||
describe "FileController", ->
|
||||
|
||||
beforeEach ->
|
||||
@FsWrapper =
|
||||
sendStreamToS3: sinon.stub()
|
||||
copyFile: sinon.stub()
|
||||
deleteFile:sinon.stub()
|
||||
|
||||
@settings =
|
||||
filestreamWrapper:"test"
|
||||
s3:
|
||||
buckets:
|
||||
user_files:"user_files"
|
||||
|
@ -27,17 +31,15 @@ describe "FileController", ->
|
|||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
@FsWrapper = require("../../../app/js/fsWrapper.js")
|
||||
@FsWrapper.selectBackend("test")
|
||||
@project_id = "project_id"
|
||||
@file_id = "file_id"
|
||||
@bucket = "user_files"
|
||||
@key = "#{@project_id}/#{@file_id}"
|
||||
@req =
|
||||
@req =
|
||||
key:@key
|
||||
bucket:@bucket
|
||||
query:{}
|
||||
params:
|
||||
params:
|
||||
project_id:@project_id
|
||||
file_id:@file_id
|
||||
@res =
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
assert = require("chai").assert
|
||||
sinon = require('sinon')
|
||||
chai = require('chai')
|
||||
|
@ -11,23 +10,27 @@ describe "FileHandler", ->
|
|||
|
||||
beforeEach ->
|
||||
@settings =
|
||||
filestreamWrapper:"test"
|
||||
s3:
|
||||
buckets:
|
||||
user_files:"user_files"
|
||||
@FsWrapper =
|
||||
getFileStream: sinon.stub()
|
||||
checkIfFileExists: sinon.stub()
|
||||
deleteFile: sinon.stub()
|
||||
deleteDirectory: sinon.stub()
|
||||
sendStreamToS3: sinon.stub()
|
||||
insertFile: sinon.stub()
|
||||
@LocalFileWriter =
|
||||
writeStream: sinon.stub()
|
||||
@FileConverter =
|
||||
convert: sinon.stub()
|
||||
thumbnail: sinon.stub()
|
||||
preview: sinon.stub()
|
||||
@keyBuilder =
|
||||
@keyBuilder =
|
||||
addCachingToKey: sinon.stub()
|
||||
getConvertedFolderKey: sinon.stub()
|
||||
@ImageOptimiser =
|
||||
compressPng: sinon.stub()
|
||||
@FsWrapper = require("../../../app/js/fsWrapper.js")
|
||||
@FsWrapper.selectBackend("test")
|
||||
@handler = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex": @settings
|
||||
"./fsWrapper":@FsWrapper
|
||||
|
|
96
services/filestore/test/unit/coffee/fsWrapperTests.coffee
Normal file
96
services/filestore/test/unit/coffee/fsWrapperTests.coffee
Normal file
|
@ -0,0 +1,96 @@
|
|||
logger = require("logger-sharelatex")
|
||||
assert = require("chai").assert
|
||||
sinon = require('sinon')
|
||||
chai = require('chai')
|
||||
should = chai.should()
|
||||
expect = chai.expect
|
||||
modulePath = "../../../app/js/fsWrapper.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
|
||||
|
||||
describe "fsWrapperTests", ->
|
||||
|
||||
beforeEach ->
|
||||
@s3Wrapper =
|
||||
getFileStream: sinon.stub()
|
||||
checkIfFileExists: sinon.stub()
|
||||
deleteFile: sinon.stub()
|
||||
deleteDirectory: sinon.stub()
|
||||
sendStreamToS3: sinon.stub()
|
||||
insertFile: sinon.stub()
|
||||
|
||||
describe "test s3 mixin", ->
|
||||
beforeEach ->
|
||||
@settings =
|
||||
filestoreBackend: "s3"
|
||||
@requires =
|
||||
"./s3Wrapper": @s3Wrapper
|
||||
"settings-sharelatex": @settings
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
@fsWrapper = SandboxedModule.require modulePath, requires: @requires
|
||||
|
||||
it "should load getFileStream", (done) ->
|
||||
@fsWrapper.should.respondTo("getFileStream")
|
||||
@fsWrapper.getFileStream()
|
||||
@s3Wrapper.getFileStream.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
it "should load checkIfFileExists", (done) ->
|
||||
@fsWrapper.checkIfFileExists()
|
||||
@s3Wrapper.checkIfFileExists.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
it "should load deleteFile", (done) ->
|
||||
@fsWrapper.deleteFile()
|
||||
@s3Wrapper.deleteFile.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
it "should load deleteDirectory", (done) ->
|
||||
@fsWrapper.deleteDirectory()
|
||||
@s3Wrapper.deleteDirectory.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
it "should load sendStreamToS3", (done) ->
|
||||
@fsWrapper.sendStreamToS3()
|
||||
@s3Wrapper.sendStreamToS3.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
it "should load insertFile", (done) ->
|
||||
@fsWrapper.insertFile()
|
||||
@s3Wrapper.insertFile.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
describe "test invalid mixins", ->
|
||||
|
||||
it "should not load a null wrapper", (done) ->
|
||||
@settings =
|
||||
@requires =
|
||||
"./s3Wrapper": @s3Wrapper
|
||||
"settings-sharelatex": @settings
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
try
|
||||
@fsWrapper=SandboxedModule.require modulePath, requires: @requires
|
||||
catch error
|
||||
assert.equal("Unknown filestore backend: null",error.message)
|
||||
done()
|
||||
|
||||
it "should not load an invalid wrapper", (done) ->
|
||||
@settings =
|
||||
filestoreBackend:"magic"
|
||||
@requires =
|
||||
"./s3Wrapper": @s3Wrapper
|
||||
"settings-sharelatex": @settings
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
try
|
||||
@fsWrapper=SandboxedModule.require modulePath, requires: @requires
|
||||
catch error
|
||||
assert.equal("Unknown filestore backend: magic",error.message)
|
||||
done()
|
||||
|
||||
|
Loading…
Reference in a new issue