mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-03 14:19:01 +02:00
Test and fix _mongoDocToS3Doc
This commit is contained in:
@@ -98,6 +98,8 @@ module.exports = DocArchive =
|
||||
return callback null, mongo_doc
|
||||
|
||||
_mongoDocToS3Doc: (doc, callback = (error, s3_doc) ->) ->
|
||||
if !doc.lines?
|
||||
return callback(new Error("doc has no lines"))
|
||||
json = JSON.stringify({
|
||||
lines: doc.lines
|
||||
ranges: doc.ranges
|
||||
@@ -105,7 +107,7 @@ module.exports = DocArchive =
|
||||
})
|
||||
if json.indexOf("\u0000") != -1
|
||||
error = new Error("null bytes detected")
|
||||
logger.error {err: error, project_id, doc_id}, error.message
|
||||
logger.err {err: error, doc, json}, error.message
|
||||
return callback(error)
|
||||
return callback null, json
|
||||
|
||||
|
||||
@@ -75,11 +75,13 @@ describe "DocArchiveManager", ->
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
@globals =
|
||||
JSON: JSON
|
||||
|
||||
@error = "my errror"
|
||||
@project_id = ObjectId().toString()
|
||||
@stubbedError = new Errors.NotFoundError("Error in S3 request")
|
||||
@DocArchiveManager = SandboxedModule.require modulePath, requires: @requires
|
||||
@DocArchiveManager = SandboxedModule.require modulePath, requires: @requires, globals: @globals
|
||||
|
||||
describe "archiveDoc", ->
|
||||
|
||||
@@ -253,4 +255,41 @@ describe "DocArchiveManager", ->
|
||||
}, (error, doc) ->
|
||||
expect(error).to.exist
|
||||
done()
|
||||
|
||||
describe "_mongoDocToS3Doc", ->
|
||||
describe "with a valid doc", ->
|
||||
it "should return the json version", (done) ->
|
||||
@DocArchiveManager._mongoDocToS3Doc doc = {
|
||||
lines: ["doc", "lines"]
|
||||
ranges: { "mock": "ranges" }
|
||||
}, (err, s3_doc) ->
|
||||
expect(s3_doc).to.equal JSON.stringify({
|
||||
lines: ["doc", "lines"]
|
||||
ranges: { "mock": "ranges" }
|
||||
schema_v: 1
|
||||
})
|
||||
done()
|
||||
|
||||
describe "with null bytes in the result", ->
|
||||
beforeEach ->
|
||||
@_stringify = JSON.stringify
|
||||
JSON.stringify = sinon.stub().returns '{"bad": "\u0000"}'
|
||||
|
||||
afterEach ->
|
||||
JSON.stringify = @_stringify
|
||||
|
||||
it "should return an error", (done) ->
|
||||
@DocArchiveManager._mongoDocToS3Doc {
|
||||
lines: ["doc", "lines"]
|
||||
ranges: { "mock": "ranges" }
|
||||
}, (err, s3_doc) ->
|
||||
expect(err).to.exist
|
||||
done()
|
||||
|
||||
describe "without doc lines", ->
|
||||
it "should return an error", (done) ->
|
||||
@DocArchiveManager._mongoDocToS3Doc {}, (err, s3_doc) ->
|
||||
expect(err).to.exist
|
||||
done()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user