mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-16 22:43:53 +00:00
init unit tests
This commit is contained in:
parent
5c31e80062
commit
6add9a0da7
1 changed files with 70 additions and 0 deletions
70
services/docstore/test/unit/coffee/DocArchiveManager.coffee
Normal file
70
services/docstore/test/unit/coffee/DocArchiveManager.coffee
Normal file
|
@ -0,0 +1,70 @@
|
|||
assert = require("chai").assert
|
||||
sinon = require('sinon')
|
||||
chai = require('chai')
|
||||
should = chai.should()
|
||||
expect = chai.expect
|
||||
modulePath = "../../../app/js/DocArchiveManager.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
ObjectId = require("mongojs").ObjectId
|
||||
Errors = require "../../../app/js/Errors"
|
||||
|
||||
describe "DocArchiveManager", ->
|
||||
|
||||
beforeEach ->
|
||||
|
||||
@settings =
|
||||
filestore:
|
||||
backend: "s3"
|
||||
s3:
|
||||
secret: "secret"
|
||||
key: "this_key"
|
||||
stores:
|
||||
user_files:"sl_user_files"
|
||||
|
||||
@request =
|
||||
put: sinon.stub().callsArgWith(1, null, statusCode:200)
|
||||
|
||||
@MongoManager =
|
||||
markDocAsArchived: sinon.stub().callsArgWith(2, null)
|
||||
upsertIntoDocCollection: sinon.stub()
|
||||
|
||||
@DocArchiveManager = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex": @settings
|
||||
"./MongoManager": @MongoManager
|
||||
"request": @request
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
|
||||
@key = "my/key"
|
||||
@bucketName = "my-bucket"
|
||||
@error = "my errror"
|
||||
|
||||
@docs = [{
|
||||
_id: ObjectId()
|
||||
lines: ["one", "two", "three"]
|
||||
rev: 2
|
||||
}, {
|
||||
_id: ObjectId()
|
||||
lines: ["aaa", "bbb", "ccc"]
|
||||
rev: 4
|
||||
}, {
|
||||
_id: ObjectId()
|
||||
lines: ["111", "222", "333"]
|
||||
rev: 6
|
||||
}]
|
||||
|
||||
@project_id = ObjectId().toString()
|
||||
@callback = sinon.stub()
|
||||
@stubbedError = new Error("blew up")
|
||||
|
||||
describe "archiveDoc", ->
|
||||
|
||||
it "should use correct options", (done)->
|
||||
@DocArchiveManager.archiveDoc @project_id, @docs[0], (err)=>
|
||||
opts = @request.put.args[0][0]
|
||||
assert.deepEqual(opts.aws, {key:@settings.filestore.s3.key, secret:@settings.filestore.s3.secret, bucket:@settings.filestore.stores.user_files})
|
||||
opts.json.should.equal @docs[0].lines
|
||||
opts.timeout.should.equal (30*1000)
|
||||
opts.uri.should.equal "https://#{@settings.filestore.stores.user_files}.s3.amazonaws.com/#{@project_id}/#{@docs[0]._id}"
|
||||
done()
|
Loading…
Reference in a new issue