2023-01-13 07:42:29 -05:00
|
|
|
import { expect } from 'chai'
|
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 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) {
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryApp.ensureRunning(error => {
|
2023-01-13 07:42:29 -05:00
|
|
|
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,
|
|
|
|
})
|
|
|
|
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.initializeProject(
|
2023-01-13 07:42:29 -05:00
|
|
|
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)
|
2024-10-01 08:36:38 -04:00
|
|
|
done()
|
2023-01-13 07:42:29 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
2024-10-01 08:36:38 -04:00
|
|
|
nock.cleanAll()
|
2023-01-13 07:42:29 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('can create and get labels', function (done) {
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.createLabel(
|
2023-01-13 07:42:29 -05:00
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
7,
|
|
|
|
this.comment,
|
|
|
|
this.created_at,
|
|
|
|
(error, label) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.getLabels(this.project_id, (error, labels) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
2023-01-13 07:42:29 -05:00
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
expect(labels).to.deep.equal([label])
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can create and get labels with no user id', function (done) {
|
|
|
|
const userId = undefined
|
|
|
|
ProjectHistoryClient.createLabel(
|
|
|
|
this.project_id,
|
|
|
|
userId,
|
|
|
|
7,
|
|
|
|
this.comment,
|
|
|
|
this.created_at,
|
|
|
|
(error, label) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
ProjectHistoryClient.getLabels(this.project_id, (error, labels) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
expect(labels).to.deep.equal([label])
|
|
|
|
done()
|
|
|
|
})
|
2023-01-13 07:42:29 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can delete labels', function (done) {
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.createLabel(
|
2023-01-13 07:42:29 -05:00
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
7,
|
|
|
|
this.comment,
|
|
|
|
this.created_at,
|
|
|
|
(error, label) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.deleteLabel(this.project_id, label.id, error => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
ProjectHistoryClient.getLabels(this.project_id, (error, labels) => {
|
2024-01-22 04:02:51 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
expect(labels).to.deep.equal([])
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2024-01-22 04:02:51 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can delete labels for the current user', function (done) {
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.createLabel(
|
2024-01-22 04:02:51 -05:00
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
7,
|
|
|
|
this.comment,
|
|
|
|
this.created_at,
|
|
|
|
(error, label) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.deleteLabelForUser(
|
2023-01-13 07:42:29 -05:00
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
label.id,
|
|
|
|
error => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.getLabels(this.project_id, (error, labels) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
2023-01-13 07:42:29 -05:00
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
expect(labels).to.deep.equal([])
|
|
|
|
done()
|
|
|
|
})
|
2023-01-13 07:42:29 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
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()
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.createLabel(
|
2023-01-13 07:42:29 -05:00
|
|
|
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
|
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.createLabel(
|
2023-01-13 07:42:29 -05:00
|
|
|
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
|
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
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
|
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.getLabels(
|
2023-01-13 07:42:29 -05:00
|
|
|
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
|
|
|
},
|
|
|
|
])
|
2024-10-01 08:36:38 -04:00
|
|
|
done()
|
2023-01-13 07:42:29 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2024-10-01 08:36:38 -04:00
|
|
|
it('should return labels with summarized updates', function (done) {
|
|
|
|
ProjectHistoryClient.createLabel(
|
2023-01-13 07:42:29 -05:00
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
8,
|
|
|
|
this.comment,
|
|
|
|
this.created_at,
|
|
|
|
(error, label) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
2024-10-01 08:36:38 -04:00
|
|
|
ProjectHistoryClient.getSummarizedUpdates(
|
2023-01-13 07:42:29 -05:00
|
|
|
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(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
2024-10-01 08:36:38 -04:00
|
|
|
done()
|
2023-01-13 07:42:29 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|