overleaf/services/web/test/unit/coffee/Blog/BlogControllerTests.coffee

73 lines
1.9 KiB
CoffeeScript
Raw Normal View History

2014-07-10 13:53:53 +00:00
should = require('chai').should()
SandboxedModule = require('sandboxed-module')
assert = require('assert')
path = require('path')
sinon = require('sinon')
modulePath = path.join __dirname, "../../../../app/js/Features/Blog/BlogController"
expect = require("chai").expect
describe "BlogController", ->
beforeEach ->
@settings =
apis:
blog:
url:"http://blog.sharelatex.env"
@request =
get: sinon.stub()
@ErrorController = {}
2014-07-10 13:53:53 +00:00
@BlogController = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings
"logger-sharelatex": log:->
"../Errors/ErrorController": @ErrorController
2014-07-10 13:53:53 +00:00
"request": @request
@req = {}
@res = {}
describe "getPage", ()->
it "should get the data from the blog api", (done)->
@req.url = "/blog/something.html"
body = {"stuff":"here"}
@request.get.callsArgWith(1, null, null, JSON.stringify(body))
@res.render = (view, data)=>
@request.get.calledWith("#{@settings.apis.blog.url}#{@req.url}")
view.should.equal "blog/blog_holder"
assert.deepEqual body, data
done()
@BlogController.getPage @req, @res
it "should send to the error controller if the blog responds 404", (done)->
@req.url = "/blog/something.html"
@request.get.callsArgWith(1, null, {statusCode:404})
@ErrorController.notFound = (req, res)=>
assert.deepEqual req, @req
assert.deepEqual res, @res
done()
@BlogController.getPage @req, @res
2014-07-10 13:53:53 +00:00
it "should proxy the image urls", (done)->
@BlogController._directProxy = sinon.stub()
@req.url = "/something.png"
@BlogController.getPage @req, @res
@BlogController._directProxy.calledWith("#{@settings.apis.blog.url}#{@req.url}", @res).should.equal true
done()
describe "getIndexPage", ->
it "should change the url and send it to getPage", (done)->
@req.url = "/blog"
@BlogController.getPage = (req, res)->
req.url.should.equal "/blog/index.html"
done()
@BlogController.getIndexPage @req, @res