ExportsTests.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* eslint-disable
  2. camelcase,
  3. max-len,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const { expect } = require('chai')
  15. const request = require('./helpers/request')
  16. const _ = require('underscore')
  17. const User = require('./helpers/User')
  18. const ProjectGetter = require('../../../app/src/Features/Project/ProjectGetter.js')
  19. const ExportsHandler = require('../../../app/src/Features/Exports/ExportsHandler.js')
  20. const MockProjectHistoryApi = require('./helpers/MockProjectHistoryApi')
  21. const MockV1Api = require('./helpers/MockV1Api')
  22. describe('Exports', function() {
  23. before(function(done) {
  24. this.brand_variation_id = '18'
  25. this.owner = new User()
  26. return this.owner.login(error => {
  27. if (error != null) {
  28. throw error
  29. }
  30. return this.owner.createProject(
  31. 'example-project',
  32. { template: 'example' },
  33. (error, project_id) => {
  34. this.project_id = project_id
  35. if (error != null) {
  36. throw error
  37. }
  38. return done()
  39. }
  40. )
  41. })
  42. })
  43. describe('exporting a project', function() {
  44. beforeEach(function(done) {
  45. this.version = Math.floor(Math.random() * 10000)
  46. MockProjectHistoryApi.setProjectVersion(this.project_id, this.version)
  47. this.export_id = Math.floor(Math.random() * 10000)
  48. MockV1Api.setExportId(this.export_id)
  49. MockV1Api.clearExportParams()
  50. return this.owner.request(
  51. {
  52. method: 'POST',
  53. url: `/project/${this.project_id}/export/${this.brand_variation_id}`,
  54. json: true,
  55. body: {
  56. title: 'title',
  57. description: 'description',
  58. author: 'author',
  59. license: 'other',
  60. showSource: true
  61. }
  62. },
  63. (error, response, body) => {
  64. if (error != null) {
  65. throw error
  66. }
  67. expect(response.statusCode).to.equal(200)
  68. this.exportResponseBody = body
  69. return done()
  70. }
  71. )
  72. })
  73. it('should have sent correct data to v1', function(done) {
  74. const {
  75. project,
  76. user,
  77. destination,
  78. options
  79. } = MockV1Api.getLastExportParams()
  80. // project details should match
  81. expect(project.id).to.equal(this.project_id)
  82. expect(project.rootDocPath).to.equal('/main.tex')
  83. // gallery details should match
  84. expect(project.metadata.title).to.equal('title')
  85. expect(project.metadata.description).to.equal('description')
  86. expect(project.metadata.author).to.equal('author')
  87. expect(project.metadata.license).to.equal('other')
  88. expect(project.metadata.showSource).to.equal(true)
  89. // version should match what was retrieved from project-history
  90. expect(project.historyVersion).to.equal(this.version)
  91. // user details should match
  92. expect(user.id).to.equal(this.owner.id)
  93. expect(user.email).to.equal(this.owner.email)
  94. // brand-variation should match
  95. expect(destination.brandVariationId).to.equal(this.brand_variation_id)
  96. return done()
  97. })
  98. it('should have returned the export ID provided by v1', function(done) {
  99. expect(this.exportResponseBody.export_v1_id).to.equal(this.export_id)
  100. return done()
  101. })
  102. })
  103. })