2023-01-13 07:42:29 -05:00
|
|
|
/* 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'
|
2023-12-15 05:51:11 -05:00
|
|
|
import mongodb from 'mongodb-legacy'
|
2023-01-13 07:42:29 -05:00
|
|
|
import nock from 'nock'
|
|
|
|
import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
|
|
|
|
import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
|
2023-12-15 05:51:11 -05:00
|
|
|
const { ObjectId } = mongodb
|
2023-01-13 07:42:29 -05:00
|
|
|
|
2024-04-25 08:56:00 -04:00
|
|
|
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')
|
2023-01-13 07:42:29 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-12-15 05:51:11 -05:00
|
|
|
this.historyId = new ObjectId().toString()
|
2023-01-13 07:42:29 -05:00
|
|
|
MockHistoryStore().post('/api/projects').reply(200, {
|
|
|
|
projectId: this.historyId,
|
|
|
|
})
|
|
|
|
|
|
|
|
return ProjectHistoryClient.initializeProject(
|
|
|
|
this.historyId,
|
2023-03-20 09:41:11 -04:00
|
|
|
(error, olProject) => {
|
2023-01-13 07:42:29 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
2023-12-15 05:51:11 -05:00
|
|
|
this.project_id = new ObjectId().toString()
|
2023-01-13 07:42:29 -05:00
|
|
|
MockWeb()
|
|
|
|
.get(`/project/${this.project_id}/details`)
|
|
|
|
.reply(200, {
|
|
|
|
name: 'Test Project',
|
2023-03-20 09:41:11 -04:00
|
|
|
overleaf: { history: { id: olProject.id } },
|
2023-01-13 07:42:29 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
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'
|
2023-12-15 05:51:11 -05:00
|
|
|
this.user_id = new ObjectId().toString()
|
2023-01-13 07:42:29 -05:00
|
|
|
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(
|
2024-01-22 04:02:51 -05:00
|
|
|
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(
|
2023-01-13 07:42:29 -05:00
|
|
|
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) {
|
2023-12-15 05:51:11 -05:00
|
|
|
const fromUser = new ObjectId().toString()
|
|
|
|
const toUser = new ObjectId().toString()
|
2023-01-13 07:42:29 -05:00
|
|
|
return ProjectHistoryClient.createLabel(
|
|
|
|
this.project_id,
|
2023-03-20 09:41:11 -04:00
|
|
|
fromUser,
|
2023-01-13 07:42:29 -05:00
|
|
|
7,
|
|
|
|
this.comment,
|
|
|
|
this.created_at,
|
|
|
|
(error, label) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return ProjectHistoryClient.createLabel(
|
|
|
|
this.project_id,
|
2023-03-20 09:41:11 -04:00
|
|
|
fromUser,
|
2023-01-13 07:42:29 -05:00
|
|
|
7,
|
|
|
|
this.comment2,
|
|
|
|
this.created_at,
|
|
|
|
(error, label2) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return ProjectHistoryClient.transferLabelOwnership(
|
2023-03-20 09:41:11 -04:00
|
|
|
fromUser,
|
|
|
|
toUser,
|
2023-01-13 07:42:29 -05:00
|
|
|
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,
|
2023-03-20 09:41:11 -04:00
|
|
|
user_id: toUser,
|
2023-01-13 07:42:29 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: label2.id,
|
|
|
|
comment: label2.comment,
|
|
|
|
version: label2.version,
|
|
|
|
created_at: label2.created_at,
|
2023-03-20 09:41:11 -04:00
|
|
|
user_id: toUser,
|
2023-01-13 07:42:29 -05:00
|
|
|
},
|
|
|
|
])
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|