mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
fix url fetcher tests so they exit correctly
This commit is contained in:
parent
3ce5229435
commit
729d29253d
1 changed files with 21 additions and 12 deletions
|
@ -17,8 +17,8 @@ describe "UrlFetcher", ->
|
|||
@defaults.calledWith(jar: false)
|
||||
.should.equal true
|
||||
|
||||
describe "_pipeUrlToFile", ->
|
||||
beforeEach ->
|
||||
describe "pipeUrlToFile", ->
|
||||
beforeEach (done)->
|
||||
@path = "/path/to/file/on/disk"
|
||||
@request.get = sinon.stub().returns(@urlStream = new EventEmitter)
|
||||
@urlStream.pipe = sinon.stub()
|
||||
|
@ -26,21 +26,24 @@ describe "UrlFetcher", ->
|
|||
@urlStream.resume = sinon.stub()
|
||||
@fs.createWriteStream = sinon.stub().returns(@fileStream = new EventEmitter)
|
||||
@fs.unlink = (file, callback) -> callback()
|
||||
@UrlFetcher.pipeUrlToFile(@url, @path, @callback)
|
||||
|
||||
it "should request the URL", ->
|
||||
@request.get
|
||||
.calledWith(sinon.match {"url": @url})
|
||||
.should.equal true
|
||||
|
||||
done()
|
||||
|
||||
describe "successfully", ->
|
||||
beforeEach ->
|
||||
beforeEach (done)->
|
||||
@UrlFetcher.pipeUrlToFile @url, @path, =>
|
||||
@callback()
|
||||
done()
|
||||
@res = statusCode: 200
|
||||
@urlStream.emit "response", @res
|
||||
@urlStream.emit "end"
|
||||
@fileStream.emit "finish"
|
||||
|
||||
|
||||
it "should request the URL", ->
|
||||
@request.get
|
||||
.calledWith(sinon.match {"url": @url})
|
||||
.should.equal true
|
||||
|
||||
it "should open the file for writing", ->
|
||||
@fs.createWriteStream
|
||||
.calledWith(@path)
|
||||
|
@ -55,7 +58,10 @@ describe "UrlFetcher", ->
|
|||
@callback.called.should.equal true
|
||||
|
||||
describe "with non success status code", ->
|
||||
beforeEach ->
|
||||
beforeEach (done)->
|
||||
@UrlFetcher.pipeUrlToFile @url, @path, (err)=>
|
||||
@callback(err)
|
||||
done()
|
||||
@res = statusCode: 404
|
||||
@urlStream.emit "response", @res
|
||||
@urlStream.emit "end"
|
||||
|
@ -66,7 +72,10 @@ describe "UrlFetcher", ->
|
|||
.should.equal true
|
||||
|
||||
describe "with error", ->
|
||||
beforeEach ->
|
||||
beforeEach (done)->
|
||||
@UrlFetcher.pipeUrlToFile @url, @path, (err)=>
|
||||
@callback(err)
|
||||
done()
|
||||
@urlStream.emit "error", @error = new Error("something went wrong")
|
||||
|
||||
it "should call the callback with the error", ->
|
||||
|
|
Loading…
Reference in a new issue