mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
added unit test (work in progress)
This commit is contained in:
parent
03564b2138
commit
86505047a3
1 changed files with 100 additions and 0 deletions
100
services/document-updater/test/unit/coffee/Compression.coffee
Normal file
100
services/document-updater/test/unit/coffee/Compression.coffee
Normal file
|
@ -0,0 +1,100 @@
|
|||
sinon = require('sinon')
|
||||
chai = require('chai')
|
||||
should = chai.should()
|
||||
modulePath = "../../../app/js/RedisManager"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe "RedisManager.setDocument and getDocument", ->
|
||||
beforeEach ->
|
||||
@zip_opts =
|
||||
writesEnabled: true
|
||||
minSize: 1000
|
||||
@doc_id = "document-id"
|
||||
@version = 123
|
||||
@RedisManager = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex" :
|
||||
redis:
|
||||
web:
|
||||
host: 'none'
|
||||
port: 'none'
|
||||
zip: @zip_opts
|
||||
"redis-sharelatex" : createClient: () =>
|
||||
@rclient ?=
|
||||
auth:-> # only assign one rclient
|
||||
multi: () => @rclient
|
||||
set: (key, value) => @rclient.store[key] = value
|
||||
get: (key) => @rclient.results.push @rclient.store[key]
|
||||
incr: (key) => @rclient.store[key]++
|
||||
exec: (callback) =>
|
||||
callback.apply(null, [null, @rclient.results])
|
||||
@rclient.results = []
|
||||
store: {}
|
||||
results: []
|
||||
"logger-sharelatex": {}
|
||||
|
||||
@RedisManager.setDocument(@doc_id, @docLines, @version, @callback)
|
||||
|
||||
describe "for a small document (uncompressed)", ->
|
||||
before ->
|
||||
@docLines = ["hello", "world"]
|
||||
@callback = sinon.stub()
|
||||
|
||||
it "should set the document", ->
|
||||
@rclient.store['doclines:document-id']
|
||||
.should.equal JSON.stringify(@docLines)
|
||||
|
||||
it "should return the callback", ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
it "should get the document back again", (done) ->
|
||||
@RedisManager.getDoc @doc_id, (err, lines, version) =>
|
||||
@docLines.should.eql lines
|
||||
done()
|
||||
|
||||
describe "for a large document (with compression enabled)", ->
|
||||
before ->
|
||||
@zip_opts =
|
||||
writesEnabled: true
|
||||
minSize: 1000
|
||||
@docLines = []
|
||||
while @docLines.join('').length <= @zip_opts.minSize
|
||||
@docLines.push "this is a long line in a long document"
|
||||
@callback = sinon.stub()
|
||||
|
||||
it "should set the document as a gzipped blob", ->
|
||||
@rclient.store['doclines:document-id']
|
||||
.should.not.equal JSON.stringify(@docLines)
|
||||
|
||||
it "should return the callback", ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
it "should get the uncompressed document back again", (done) ->
|
||||
@RedisManager.getDoc @doc_id, (err, lines, version) =>
|
||||
@docLines.should.eql lines
|
||||
done()
|
||||
|
||||
describe "for a large document (with compression disabled)", ->
|
||||
before ->
|
||||
@zip_opts =
|
||||
writesEnabled: false
|
||||
minSize: 1000
|
||||
@docLines = []
|
||||
while @docLines.join('').length <= @zip_opts.minSize
|
||||
@docLines.push "this is a long line in a long document"
|
||||
@callback = sinon.stub()
|
||||
|
||||
it "should set the document", ->
|
||||
@rclient.store['doclines:document-id']
|
||||
.should.equal JSON.stringify(@docLines)
|
||||
|
||||
it "should return the callback", ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
it "should get the document back again", (done) ->
|
||||
@RedisManager.getDoc @doc_id, (err, lines, version) =>
|
||||
@docLines.should.eql lines
|
||||
done()
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue