mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
8c70d680f4
Collabratec create project api GitOrigin-RevId: 5f421625baa5c48f1745a15e15fe3a18fc1a4884
66 lines
2 KiB
CoffeeScript
66 lines
2 KiB
CoffeeScript
SandboxedModule = require('sandboxed-module')
|
|
assert = require('assert')
|
|
chai = require('chai')
|
|
sinon = require('sinon')
|
|
sinonChai = require('sinon-chai')
|
|
|
|
chai.should()
|
|
chai.use(sinonChai)
|
|
expect = chai.expect
|
|
|
|
modulePath = '../../../../app/js/Features/Templates/TemplatesController'
|
|
|
|
describe "TemplatesController", ->
|
|
|
|
beforeEach ->
|
|
@user_id = "user-id"
|
|
@TemplatesController = SandboxedModule.require modulePath, requires:
|
|
"../../../js/Features/Authentication/AuthenticationController": @AuthenticationController = {
|
|
getLoggedInUserId: sinon.stub().returns(@user_id)
|
|
}
|
|
"./TemplatesManager": @TemplatesManager = {
|
|
createProjectFromV1Template: sinon.stub()
|
|
}
|
|
@next = sinon.stub()
|
|
@req =
|
|
body:
|
|
brandVariationId: "brand-variation-id"
|
|
compiler: "compiler"
|
|
mainFile: "main-file"
|
|
templateId: "template-id"
|
|
templateName: "template-name"
|
|
templateVersionId: "template-version-id"
|
|
session:
|
|
templateData: "template-data"
|
|
user: _id: @user_id
|
|
@res =
|
|
redirect: sinon.stub()
|
|
|
|
describe "createProjectFromV1Template", ->
|
|
|
|
describe "on success", ->
|
|
beforeEach ->
|
|
@project =
|
|
_id: "project-id"
|
|
@TemplatesManager.createProjectFromV1Template.yields null, @project
|
|
@TemplatesController.createProjectFromV1Template @req, @res, @next
|
|
|
|
it "should call TemplatesManager", ->
|
|
@TemplatesManager.createProjectFromV1Template.should.have.been.calledWithMatch "brand-variation-id", "compiler", "main-file", "template-id", "template-name", "template-version-id", "user-id"
|
|
|
|
it "should redirect to project", ->
|
|
@res.redirect.should.have.been.calledWith "/project/project-id"
|
|
|
|
it "should delete session", ->
|
|
expect(@req.session.templateData).to.be.undefined
|
|
|
|
describe "on error", ->
|
|
beforeEach ->
|
|
@TemplatesManager.createProjectFromV1Template.yields "error"
|
|
@TemplatesController.createProjectFromV1Template @req, @res, @next
|
|
|
|
it "should call next with error", ->
|
|
@next.should.have.been.calledWith "error"
|
|
|
|
it "should not redirect", ->
|
|
@res.redirect.called.should.equal false
|