overleaf/services/web/test/unit/coffee/BrandVariations/BrandVariationsHandlerTests.coffee
Paulo Reis 00a489a000 Fetch brand variation details for branded projects; inject details into the editor page front-end.
Test brand variation details.

Rename BrandVariationsController to BrandVariationsHandler.

Use the V1 API helper.

Do not swallow errors when fetching brand details for project load.

Fix indentation.
2018-10-19 10:47:02 +01:00

46 lines
1.7 KiB
CoffeeScript

expect = require("chai").expect
SandboxedModule = require("sandboxed-module")
assert = require("assert")
path = require("path")
sinon = require("sinon")
expect = require("chai").expect
modulePath = path.join __dirname, "../../../../app/js/Features/BrandVariations/BrandVariationsHandler"
describe "BrandVariationsHandler", ->
beforeEach ->
@logger =
err: ->
log: ->
@V1Api =
request: sinon.stub()
@BrandVariationsHandler = SandboxedModule.require modulePath, requires:
"settings-sharelatex": @settings
"logger-sharelatex": @logger
"../V1/V1Api": @V1Api
@mockedBrandVariationDetails =
id: "12"
active: true
brand_name: "The journal"
home_url: "http://www.thejournal.com/"
publish_menu_link_html: "Submit your paper to the <em>The Journal</em>"
describe "getBrandVariationById", ->
it "should call the callback with an error when the branding variation id is not provided", (done) ->
@BrandVariationsHandler.getBrandVariationById null, (err, brandVariationDetails) =>
expect(err).to.be.instanceof Error
done()
it "should call the callback with an error when the request errors", (done) ->
@V1Api.request.callsArgWith 1, new Error()
@BrandVariationsHandler.getBrandVariationById "12", (err, brandVariationDetails) =>
expect(err).to.be.instanceof Error
done()
it "should call the callback with branding details when request succeeds", (done) ->
@V1Api.request.callsArgWith 1, null, { statusCode: 200 }, @mockedBrandVariationDetails
@BrandVariationsHandler.getBrandVariationById "12", (err, brandVariationDetails) =>
expect(err).to.not.exist
expect(brandVariationDetails).to.deep.equal @mockedBrandVariationDetails
done()