mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 01:23:59 +00:00
Update FileStoreHandlerTests
This commit is contained in:
parent
eae82a2b20
commit
78e52d8c96
1 changed files with 33 additions and 6 deletions
|
@ -111,29 +111,56 @@ describe "FileStoreHandler", ->
|
|||
|
||||
describe "getFileStream", ->
|
||||
beforeEach ->
|
||||
@query = {}
|
||||
@request.returns(@readStream)
|
||||
|
||||
it "should get the stream with the correct params", (done)->
|
||||
@handler.getFileStream @project_id, @file_id, {}, (err, stream)=>
|
||||
@handler.getFileStream @project_id, @file_id, @query, (err, stream)=>
|
||||
@request.args[0][0].method.should.equal "get"
|
||||
@request.args[0][0].uri.should.equal @handler._buildUrl()
|
||||
done()
|
||||
|
||||
it "should get stream from request", (done)->
|
||||
@handler.getFileStream @project_id, @file_id, {}, (err, stream)=>
|
||||
@handler.getFileStream @project_id, @file_id, @query, (err, stream)=>
|
||||
stream.should.equal @readStream
|
||||
done()
|
||||
|
||||
it "builds the correct url", (done)->
|
||||
@handler.getFileStream @project_id, @file_id, {}, (err, stream)=>
|
||||
@handler.getFileStream @project_id, @file_id, @query, (err, stream)=>
|
||||
@handler._buildUrl.calledWith(@project_id, @file_id).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
it "should add an error handler", (done) ->
|
||||
@handler.getFileStream @project_id, @file_id, {}, (err, stream)=>
|
||||
@handler.getFileStream @project_id, @file_id, @query, (err, stream)=>
|
||||
stream.on.calledWith("error").should.equal true
|
||||
done()
|
||||
|
||||
|
||||
describe 'when range is specified in query', ->
|
||||
|
||||
beforeEach ->
|
||||
@query = {'range': '0-10'}
|
||||
|
||||
it 'should add a range header', (done) ->
|
||||
@handler.getFileStream @project_id, @file_id, @query, (err, stream)=>
|
||||
@request.callCount.should.equal 1
|
||||
headers = @request.firstCall.args[0].headers
|
||||
expect(headers).to.have.keys('range')
|
||||
expect(headers['range']).to.equal 'bytes=0-10'
|
||||
done()
|
||||
|
||||
describe 'when range is invalid', ->
|
||||
|
||||
['0-', '-100', 'one-two', 'nonsense'].forEach (r) =>
|
||||
|
||||
beforeEach ->
|
||||
@query = {'range': "#{r}"}
|
||||
|
||||
it "should not add a range header for '#{r}'", (done) ->
|
||||
@handler.getFileStream @project_id, @file_id, @query, (err, stream)=>
|
||||
@request.callCount.should.equal 1
|
||||
headers = @request.firstCall.args[0].headers
|
||||
expect(headers).to.not.have.keys('range')
|
||||
done()
|
||||
|
||||
describe "copyFile", ->
|
||||
|
||||
|
|
Loading…
Reference in a new issue