| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- /* eslint-disable
- no-undef,
- no-unused-vars,
- */
- // 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
- * DS207: Consider shorter variations of null checks
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
- import sinon from 'sinon'
- import { expect } from 'chai'
- import Settings from '@overleaf/settings'
- import mongodb from 'mongodb-legacy'
- import nock from 'nock'
- import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
- import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
- const { ObjectId } = mongodb
- const MockHistoryStore = () => nock('http://127.0.0.1:3100')
- const MockFileStore = () => nock('http://127.0.0.1:3009')
- const MockWeb = () => nock('http://127.0.0.1:3000')
- const fixture = path => new URL(`../fixtures/${path}`, import.meta.url)
- describe('Labels', function () {
- beforeEach(function (done) {
- return ProjectHistoryApp.ensureRunning(error => {
- if (error != null) {
- throw error
- }
- this.historyId = new ObjectId().toString()
- MockHistoryStore().post('/api/projects').reply(200, {
- projectId: this.historyId,
- })
- return ProjectHistoryClient.initializeProject(
- this.historyId,
- (error, olProject) => {
- if (error != null) {
- throw error
- }
- this.project_id = new ObjectId().toString()
- MockWeb()
- .get(`/project/${this.project_id}/details`)
- .reply(200, {
- name: 'Test Project',
- overleaf: { history: { id: olProject.id } },
- })
- MockHistoryStore()
- .get(`/api/projects/${this.historyId}/latest/history`)
- .replyWithFile(200, fixture('chunks/7-8.json'))
- MockHistoryStore()
- .get(`/api/projects/${this.historyId}/versions/7/history`)
- .replyWithFile(200, fixture('chunks/7-8.json'))
- .persist()
- MockHistoryStore()
- .get(`/api/projects/${this.historyId}/versions/8/history`)
- .replyWithFile(200, fixture('chunks/7-8.json'))
- .persist()
- this.comment = 'a saved version comment'
- this.comment2 = 'another saved version comment'
- this.user_id = new ObjectId().toString()
- this.created_at = new Date(1)
- return done()
- }
- )
- })
- })
- afterEach(function () {
- return nock.cleanAll()
- })
- it('can create and get labels', function (done) {
- return ProjectHistoryClient.createLabel(
- this.project_id,
- this.user_id,
- 7,
- this.comment,
- this.created_at,
- (error, label) => {
- if (error != null) {
- throw error
- }
- return ProjectHistoryClient.getLabels(
- this.project_id,
- (error, labels) => {
- if (error != null) {
- throw error
- }
- expect(labels).to.deep.equal([label])
- return done()
- }
- )
- }
- )
- })
- it('can delete labels', function (done) {
- return ProjectHistoryClient.createLabel(
- this.project_id,
- this.user_id,
- 7,
- this.comment,
- this.created_at,
- (error, label) => {
- if (error != null) {
- throw error
- }
- return ProjectHistoryClient.deleteLabel(
- this.project_id,
- label.id,
- error => {
- if (error != null) {
- throw error
- }
- return ProjectHistoryClient.getLabels(
- this.project_id,
- (error, labels) => {
- if (error != null) {
- throw error
- }
- expect(labels).to.deep.equal([])
- return done()
- }
- )
- }
- )
- }
- )
- })
- it('can delete labels for the current user', function (done) {
- return ProjectHistoryClient.createLabel(
- this.project_id,
- this.user_id,
- 7,
- this.comment,
- this.created_at,
- (error, label) => {
- if (error != null) {
- throw error
- }
- return ProjectHistoryClient.deleteLabelForUser(
- this.project_id,
- this.user_id,
- label.id,
- error => {
- if (error != null) {
- throw error
- }
- return ProjectHistoryClient.getLabels(
- this.project_id,
- (error, labels) => {
- if (error != null) {
- throw error
- }
- expect(labels).to.deep.equal([])
- return done()
- }
- )
- }
- )
- }
- )
- })
- it('can transfer ownership of labels', function (done) {
- const fromUser = new ObjectId().toString()
- const toUser = new ObjectId().toString()
- return ProjectHistoryClient.createLabel(
- this.project_id,
- fromUser,
- 7,
- this.comment,
- this.created_at,
- (error, label) => {
- if (error != null) {
- throw error
- }
- return ProjectHistoryClient.createLabel(
- this.project_id,
- fromUser,
- 7,
- this.comment2,
- this.created_at,
- (error, label2) => {
- if (error != null) {
- throw error
- }
- return ProjectHistoryClient.transferLabelOwnership(
- fromUser,
- toUser,
- error => {
- if (error != null) {
- throw error
- }
- return ProjectHistoryClient.getLabels(
- this.project_id,
- (error, labels) => {
- if (error != null) {
- throw error
- }
- expect(labels).to.deep.equal([
- {
- id: label.id,
- comment: label.comment,
- version: label.version,
- created_at: label.created_at,
- user_id: toUser,
- },
- {
- id: label2.id,
- comment: label2.comment,
- version: label2.version,
- created_at: label2.created_at,
- user_id: toUser,
- },
- ])
- return done()
- }
- )
- }
- )
- }
- )
- }
- )
- })
- return it('should return labels with summarized updates', function (done) {
- return ProjectHistoryClient.createLabel(
- this.project_id,
- this.user_id,
- 8,
- this.comment,
- this.created_at,
- (error, label) => {
- if (error != null) {
- throw error
- }
- return ProjectHistoryClient.getSummarizedUpdates(
- this.project_id,
- { min_count: 1 },
- (error, updates) => {
- if (error != null) {
- throw error
- }
- expect(updates).to.deep.equal({
- nextBeforeTimestamp: 6,
- updates: [
- {
- fromV: 6,
- toV: 8,
- meta: {
- users: ['5a5637efdac84e81b71014c4', 31],
- start_ts: 1512383567277,
- end_ts: 1512383572877,
- },
- pathnames: ['bar.tex', 'main.tex'],
- project_ops: [],
- labels: [
- {
- id: label.id.toString(),
- comment: this.comment,
- version: 8,
- user_id: this.user_id,
- created_at: this.created_at.toISOString(),
- },
- ],
- },
- ],
- })
- return done()
- }
- )
- }
- )
- })
- })
|