ExportsTests.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 MockProjectHistoryApiClass = require('./mocks/MockProjectHistoryApi')
  21. const MockV1ApiClass = require('./mocks/MockV1Api')
  22. let MockProjectHistoryApi, MockV1Api
  23. before(function() {
  24. MockV1Api = MockV1ApiClass.instance()
  25. MockProjectHistoryApi = MockProjectHistoryApiClass.instance()
  26. })
  27. describe('Exports', function() {
  28. beforeEach(function(done) {
  29. this.brand_variation_id = '18'
  30. this.owner = new User()
  31. return this.owner.login(error => {
  32. if (error != null) {
  33. throw error
  34. }
  35. return this.owner.createProject(
  36. 'example-project',
  37. { template: 'example' },
  38. (error, project_id) => {
  39. this.project_id = project_id
  40. if (error != null) {
  41. throw error
  42. }
  43. return done()
  44. }
  45. )
  46. })
  47. })
  48. describe('exporting a project', function() {
  49. beforeEach(function(done) {
  50. this.version = Math.floor(Math.random() * 10000)
  51. MockProjectHistoryApi.setProjectVersion(this.project_id, this.version)
  52. this.export_id = Math.floor(Math.random() * 10000)
  53. MockV1Api.setExportId(this.export_id)
  54. return this.owner.request(
  55. {
  56. method: 'POST',
  57. url: `/project/${this.project_id}/export/${this.brand_variation_id}`,
  58. json: true,
  59. body: {
  60. title: 'title',
  61. description: 'description',
  62. author: 'author',
  63. license: 'other',
  64. showSource: true
  65. }
  66. },
  67. (error, response, body) => {
  68. if (error != null) {
  69. throw error
  70. }
  71. expect(response.statusCode).to.equal(200)
  72. this.exportResponseBody = body
  73. return done()
  74. }
  75. )
  76. })
  77. it('should have sent correct data to v1', function(done) {
  78. const {
  79. project,
  80. user,
  81. destination,
  82. options
  83. } = MockV1Api.getLastExportParams()
  84. // project details should match
  85. expect(project.id).to.equal(this.project_id)
  86. expect(project.rootDocPath).to.equal('/main.tex')
  87. // gallery details should match
  88. expect(project.metadata.title).to.equal('title')
  89. expect(project.metadata.description).to.equal('description')
  90. expect(project.metadata.author).to.equal('author')
  91. expect(project.metadata.license).to.equal('other')
  92. expect(project.metadata.showSource).to.equal(true)
  93. // version should match what was retrieved from project-history
  94. expect(project.historyVersion).to.equal(this.version)
  95. // user details should match
  96. expect(user.id).to.equal(this.owner.id)
  97. expect(user.email).to.equal(this.owner.email)
  98. // brand-variation should match
  99. expect(destination.brandVariationId).to.equal(this.brand_variation_id)
  100. return done()
  101. })
  102. it('should have returned the export ID provided by v1', function(done) {
  103. expect(this.exportResponseBody.export_v1_id).to.equal(this.export_id)
  104. return done()
  105. })
  106. })
  107. })