2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
no-useless-escape,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const assert = require('assert')
|
2021-03-31 08:20:55 -04:00
|
|
|
const { expect } = require('chai')
|
2019-05-29 05:21:06 -04:00
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../../app/src/Features/Exports/ExportsController.js'
|
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('ExportsController', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
const project_id = '123njdskj9jlk'
|
|
|
|
const user_id = '123nd3ijdks'
|
|
|
|
const brand_variation_id = 22
|
|
|
|
const firstName = 'first'
|
|
|
|
const lastName = 'last'
|
|
|
|
const title = 'title'
|
|
|
|
const description = 'description'
|
|
|
|
const author = 'author'
|
|
|
|
const license = 'other'
|
|
|
|
const show_source = true
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.handler = { getUserNotifications: sinon.stub().callsArgWith(1) }
|
|
|
|
this.req = {
|
|
|
|
params: {
|
|
|
|
project_id,
|
2021-04-27 03:52:58 -04:00
|
|
|
brand_variation_id,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
body: {
|
|
|
|
firstName,
|
2021-04-27 03:52:58 -04:00
|
|
|
lastName,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
session: {
|
|
|
|
user: {
|
2021-04-27 03:52:58 -04:00
|
|
|
_id: user_id,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
i18n: {
|
2021-04-27 03:52:58 -04:00
|
|
|
translate() {},
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.res = {
|
|
|
|
json: sinon.stub(),
|
2021-04-27 03:52:58 -04:00
|
|
|
status: sinon.stub(),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.res.status.returns(this.res)
|
|
|
|
this.next = sinon.stub()
|
|
|
|
this.AuthenticationController = {
|
2021-04-27 03:52:58 -04:00
|
|
|
getLoggedInUserId: sinon.stub().returns(this.req.session.user._id),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
return (this.controller = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'./ExportsHandler': this.handler,
|
|
|
|
'../Authentication/AuthenticationController': this
|
2021-04-27 03:52:58 -04:00
|
|
|
.AuthenticationController,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('without gallery fields', function () {
|
|
|
|
it('should ask the handler to perform the export', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.handler.exportProject = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { iAmAnExport: true, v1_id: 897 })
|
|
|
|
const expected = {
|
|
|
|
project_id,
|
|
|
|
user_id,
|
|
|
|
brand_variation_id,
|
|
|
|
first_name: firstName,
|
2021-04-27 03:52:58 -04:00
|
|
|
last_name: lastName,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
return this.controller.exportProject(this.req, {
|
|
|
|
json: body => {
|
|
|
|
expect(this.handler.exportProject.args[0][0]).to.deep.equal(expected)
|
2019-12-04 05:30:58 -05:00
|
|
|
expect(body).to.deep.equal({ export_v1_id: 897, message: undefined })
|
|
|
|
return done()
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-12-04 05:30:58 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with a message from v1', function () {
|
|
|
|
it('should ask the handler to perform the export', function (done) {
|
2019-12-04 05:30:58 -05:00
|
|
|
this.handler.exportProject = sinon.stub().yields(null, {
|
|
|
|
iAmAnExport: true,
|
|
|
|
v1_id: 897,
|
2021-04-27 03:52:58 -04:00
|
|
|
message: 'RESUBMISSION',
|
2019-12-04 05:30:58 -05:00
|
|
|
})
|
|
|
|
const expected = {
|
|
|
|
project_id,
|
|
|
|
user_id,
|
|
|
|
brand_variation_id,
|
|
|
|
first_name: firstName,
|
2021-04-27 03:52:58 -04:00
|
|
|
last_name: lastName,
|
2019-12-04 05:30:58 -05:00
|
|
|
}
|
|
|
|
return this.controller.exportProject(this.req, {
|
|
|
|
json: body => {
|
|
|
|
expect(this.handler.exportProject.args[0][0]).to.deep.equal(expected)
|
|
|
|
expect(body).to.deep.equal({
|
|
|
|
export_v1_id: 897,
|
2021-04-27 03:52:58 -04:00
|
|
|
message: 'RESUBMISSION',
|
2019-12-04 05:30:58 -05:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
return done()
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2019-08-07 10:04:04 -04:00
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with gallery fields', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.body.title = title
|
|
|
|
this.req.body.description = description
|
|
|
|
this.req.body.author = author
|
|
|
|
this.req.body.license = license
|
|
|
|
return (this.req.body.showSource = true)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should ask the handler to perform the export', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.handler.exportProject = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, { iAmAnExport: true, v1_id: 897 })
|
|
|
|
const expected = {
|
|
|
|
project_id,
|
|
|
|
user_id,
|
|
|
|
brand_variation_id,
|
|
|
|
first_name: firstName,
|
|
|
|
last_name: lastName,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
author,
|
|
|
|
license,
|
2021-04-27 03:52:58 -04:00
|
|
|
show_source,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
return this.controller.exportProject(this.req, {
|
|
|
|
json: body => {
|
|
|
|
expect(this.handler.exportProject.args[0][0]).to.deep.equal(expected)
|
2019-12-04 05:30:58 -05:00
|
|
|
expect(body).to.deep.equal({ export_v1_id: 897, message: undefined })
|
2019-05-29 05:21:06 -04:00
|
|
|
return done()
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with an error return from v1 to forward to the publish modal', function () {
|
|
|
|
it('should forward the response onward', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.error_json = { status: 422, message: 'nope' }
|
|
|
|
this.handler.exportProject = sinon
|
|
|
|
.stub()
|
|
|
|
.yields({ forwardResponse: this.error_json })
|
|
|
|
this.controller.exportProject(this.req, this.res, this.next)
|
|
|
|
expect(this.res.json.args[0][0]).to.deep.equal(this.error_json)
|
|
|
|
expect(this.res.status.args[0][0]).to.equal(this.error_json.status)
|
|
|
|
return done()
|
2019-08-07 10:04:04 -04:00
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should ask the handler to return the status of an export', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.handler.fetchExport = sinon.stub().yields(
|
|
|
|
null,
|
|
|
|
`{ \
|
|
|
|
\"id\":897, \
|
|
|
|
\"status_summary\":\"completed\", \
|
|
|
|
\"status_detail\":\"all done\", \
|
|
|
|
\"partner_submission_id\":\"abc123\", \
|
|
|
|
\"v2_user_email\":\"la@tex.com\", \
|
|
|
|
\"v2_user_first_name\":\"Arthur\", \
|
|
|
|
\"v2_user_last_name\":\"Author\", \
|
|
|
|
\"title\":\"my project\", \
|
|
|
|
\"token\":\"token\" \
|
|
|
|
}`
|
|
|
|
)
|
|
|
|
|
|
|
|
this.req.params = { project_id, export_id: 897 }
|
|
|
|
return this.controller.exportStatus(this.req, {
|
|
|
|
json: body => {
|
|
|
|
expect(body).to.deep.equal({
|
|
|
|
export_json: {
|
|
|
|
status_summary: 'completed',
|
|
|
|
status_detail: 'all done',
|
|
|
|
partner_submission_id: 'abc123',
|
|
|
|
v2_user_email: 'la@tex.com',
|
|
|
|
v2_user_first_name: 'Arthur',
|
|
|
|
v2_user_last_name: 'Author',
|
|
|
|
title: 'my project',
|
2021-04-27 03:52:58 -04:00
|
|
|
token: 'token',
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
return done()
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|