This commit is contained in:
Henry Oswald
2015-06-12 17:11:11 +01:00
10 changed files with 97 additions and 68 deletions

View File

@@ -44,6 +44,7 @@ describe "CompileController", ->
}]
@RequestParser.parse = sinon.stub().callsArgWith(1, null, @request)
@ProjectPersistenceManager.markProjectAsJustAccessed = sinon.stub().callsArg(1)
@res.status = sinon.stub().returnsThis()
@res.send = sinon.stub()
describe "successfully", ->
@@ -67,8 +68,9 @@ describe "CompileController", ->
.should.equal true
it "should return the JSON response", ->
@res.status.calledWith(200).should.equal true
@res.send
.calledWith(200,
.calledWith(
compile:
status: "success"
error: null
@@ -85,8 +87,9 @@ describe "CompileController", ->
@CompileController.compile @req, @res
it "should return the JSON response with the error", ->
@res.status.calledWith(500).should.equal true
@res.send
.calledWith(500,
.calledWith(
compile:
status: "error"
error: @message
@@ -102,8 +105,9 @@ describe "CompileController", ->
@CompileController.compile @req, @res
it "should return the JSON response with the timeout status", ->
@res.status.calledWith(200).should.equal true
@res.send
.calledWith(200,
.calledWith(
compile:
status: "timedout"
error: @message
@@ -117,8 +121,9 @@ describe "CompileController", ->
@CompileController.compile @req, @res
it "should return the JSON response with the failure status", ->
@res.status.calledWith(200).should.equal true
@res.send
.calledWith(200,
.calledWith(
compile:
error: null
status: "failure"

View File

@@ -22,25 +22,29 @@ describe "UrlFetcher", ->
@path = "/path/to/file/on/disk"
@request.get = sinon.stub().returns(@urlStream = new EventEmitter)
@urlStream.pipe = sinon.stub()
@fs.createWriteStream = sinon.stub().returns(@fileStream = { on: () -> })
@urlStream.pause = sinon.stub()
@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(@url)
.calledWith(sinon.match {"url": @url})
.should.equal true
it "should open the file for writing", ->
@fs.createWriteStream
.calledWith(@path)
.should.equal true
describe "successfully", ->
beforeEach ->
@res = statusCode: 200
@urlStream.emit "response", @res
@urlStream.emit "end"
@fileStream.emit "finish"
it "should open the file for writing", ->
@fs.createWriteStream
.calledWith(@path)
.should.equal true
it "should pipe the URL to the file", ->
@urlStream.pipe