BrandVariationsHandlerTests.coffee 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. expect = require("chai").expect
  2. SandboxedModule = require("sandboxed-module")
  3. assert = require("assert")
  4. path = require("path")
  5. sinon = require("sinon")
  6. expect = require("chai").expect
  7. modulePath = path.join __dirname, "../../../../app/js/Features/BrandVariations/BrandVariationsHandler"
  8. describe "BrandVariationsHandler", ->
  9. beforeEach ->
  10. @logger =
  11. err: ->
  12. log: ->
  13. @V1Api =
  14. request: sinon.stub()
  15. @BrandVariationsHandler = SandboxedModule.require modulePath, requires:
  16. "settings-sharelatex": @settings
  17. "logger-sharelatex": @logger
  18. "../V1/V1Api": @V1Api
  19. @mockedBrandVariationDetails =
  20. id: "12"
  21. active: true
  22. brand_name: "The journal"
  23. home_url: "http://www.thejournal.com/"
  24. publish_menu_link_html: "Submit your paper to the <em>The Journal</em>"
  25. describe "getBrandVariationById", ->
  26. it "should call the callback with an error when the branding variation id is not provided", (done) ->
  27. @BrandVariationsHandler.getBrandVariationById null, (err, brandVariationDetails) =>
  28. expect(err).to.be.instanceof Error
  29. done()
  30. it "should call the callback with an error when the request errors", (done) ->
  31. @V1Api.request.callsArgWith 1, new Error()
  32. @BrandVariationsHandler.getBrandVariationById "12", (err, brandVariationDetails) =>
  33. expect(err).to.be.instanceof Error
  34. done()
  35. it "should call the callback with branding details when request succeeds", (done) ->
  36. @V1Api.request.callsArgWith 1, null, { statusCode: 200 }, @mockedBrandVariationDetails
  37. @BrandVariationsHandler.getBrandVariationById "12", (err, brandVariationDetails) =>
  38. expect(err).to.not.exist
  39. expect(brandVariationDetails).to.deep.equal @mockedBrandVariationDetails
  40. done()