|
|
@@ -10,7 +10,7 @@ const cleanup = require('../storage/support/cleanup')
|
|
|
const fixtures = require('../storage/support/fixtures')
|
|
|
const testFiles = require('../storage/support/test_files')
|
|
|
|
|
|
-const { zipStore, persistChanges } = require('../../../../storage')
|
|
|
+const { zipStore, BlobStore, persistChanges } = require('../../../../storage')
|
|
|
|
|
|
const { expectHttpError } = require('./support/expect_response')
|
|
|
const testServer = require('./support/test_server')
|
|
|
@@ -155,12 +155,13 @@ describe('project controller', function () {
|
|
|
project_id: projectId,
|
|
|
})
|
|
|
expect(response.status).to.equal(HTTPStatus.OK)
|
|
|
- const changes = response.obj
|
|
|
+ const { changes, hasMore } = response.obj
|
|
|
expect(changes.length).to.equal(2)
|
|
|
const filenames = changes
|
|
|
.flatMap(change => change.operations)
|
|
|
.map(operation => operation.pathname)
|
|
|
expect(filenames).to.deep.equal(['test.tex', 'other.tex'])
|
|
|
+ expect(hasMore).to.be.false
|
|
|
})
|
|
|
|
|
|
it('returns only requested changes', async function () {
|
|
|
@@ -170,12 +171,13 @@ describe('project controller', function () {
|
|
|
since: 1,
|
|
|
})
|
|
|
expect(response.status).to.equal(HTTPStatus.OK)
|
|
|
- const changes = response.obj
|
|
|
+ const { changes, hasMore } = response.obj
|
|
|
expect(changes.length).to.equal(1)
|
|
|
const filenames = changes
|
|
|
.flatMap(change => change.operations)
|
|
|
.map(operation => operation.pathname)
|
|
|
expect(filenames).to.deep.equal(['other.tex'])
|
|
|
+ expect(hasMore).to.be.false
|
|
|
})
|
|
|
|
|
|
it('rejects negative versions', async function () {
|
|
|
@@ -196,68 +198,84 @@ describe('project controller', function () {
|
|
|
).to.be.rejectedWith('Bad Request')
|
|
|
})
|
|
|
})
|
|
|
- })
|
|
|
-
|
|
|
- describe('project with many chunks', function () {
|
|
|
- let projectId
|
|
|
-
|
|
|
- beforeEach(async function () {
|
|
|
- // used to provide a limit which forces us to persist all of the changes.
|
|
|
- const farFuture = new Date()
|
|
|
- farFuture.setTime(farFuture.getTime() + 7 * 24 * 3600 * 1000)
|
|
|
- const limits = {
|
|
|
- minChangeTimestamp: farFuture,
|
|
|
- maxChangeTimestamp: farFuture,
|
|
|
- maxChunkChanges: 5,
|
|
|
- }
|
|
|
- const changes = [
|
|
|
- new Change(
|
|
|
- [new AddFileOperation('test.tex', File.fromString(''))],
|
|
|
- new Date(),
|
|
|
- []
|
|
|
- ),
|
|
|
- ]
|
|
|
|
|
|
- for (let i = 0; i < 20; i++) {
|
|
|
- const textOperation = new TextOperation()
|
|
|
- textOperation.retain(i)
|
|
|
- textOperation.insert('x')
|
|
|
- changes.push(
|
|
|
+ describe('project with many chunks', function () {
|
|
|
+ let projectId, changes
|
|
|
+
|
|
|
+ beforeEach(async function () {
|
|
|
+ // used to provide a limit which forces us to persist all of the changes.
|
|
|
+ const farFuture = new Date()
|
|
|
+ farFuture.setTime(farFuture.getTime() + 7 * 24 * 3600 * 1000)
|
|
|
+ const limits = {
|
|
|
+ minChangeTimestamp: farFuture,
|
|
|
+ maxChangeTimestamp: farFuture,
|
|
|
+ maxChunkChanges: 5,
|
|
|
+ }
|
|
|
+ projectId = await createEmptyProject()
|
|
|
+ const blobStore = new BlobStore(projectId)
|
|
|
+ const blob = await blobStore.putString('')
|
|
|
+ changes = [
|
|
|
new Change(
|
|
|
- [new EditFileOperation('test.tex', textOperation)],
|
|
|
+ [new AddFileOperation('test.tex', File.createLazyFromBlobs(blob))],
|
|
|
new Date(),
|
|
|
[]
|
|
|
+ ),
|
|
|
+ ]
|
|
|
+
|
|
|
+ for (let i = 0; i < 20; i++) {
|
|
|
+ const textOperation = new TextOperation()
|
|
|
+ textOperation.retain(i)
|
|
|
+ textOperation.insert('x')
|
|
|
+ changes.push(
|
|
|
+ new Change(
|
|
|
+ [new EditFileOperation('test.tex', textOperation)],
|
|
|
+ new Date(),
|
|
|
+ []
|
|
|
+ )
|
|
|
)
|
|
|
- )
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- projectId = await createEmptyProject()
|
|
|
- await persistChanges(projectId, changes, limits, 0)
|
|
|
- })
|
|
|
+ await persistChanges(projectId, changes, limits, 0)
|
|
|
+ })
|
|
|
|
|
|
- it('returns all changes when not given a limit', async function () {
|
|
|
- const response = await testServer.basicAuthClient.apis.Project.getChanges(
|
|
|
- {
|
|
|
- project_id: projectId,
|
|
|
- }
|
|
|
- )
|
|
|
- expect(response.status).to.equal(HTTPStatus.OK)
|
|
|
- const changes = response.obj
|
|
|
- expect(changes.length).to.equal(21)
|
|
|
- expect(changes[10].operations[0].textOperation).to.deep.equal([9, 'x'])
|
|
|
- })
|
|
|
+ it('returns the first chunk when not given a limit', async function () {
|
|
|
+ const response =
|
|
|
+ await testServer.basicAuthClient.apis.Project.getChanges({
|
|
|
+ project_id: projectId,
|
|
|
+ })
|
|
|
|
|
|
- it('returns only requested changes', async function () {
|
|
|
- const response = await testServer.basicAuthClient.apis.Project.getChanges(
|
|
|
- {
|
|
|
- project_id: projectId,
|
|
|
- since: 10,
|
|
|
- }
|
|
|
- )
|
|
|
- expect(response.status).to.equal(HTTPStatus.OK)
|
|
|
- const changes = response.obj
|
|
|
- expect(changes.length).to.equal(11)
|
|
|
- expect(changes[2].operations[0].textOperation).to.deep.equal([11, 'x'])
|
|
|
+ expect(response.status).to.equal(HTTPStatus.OK)
|
|
|
+ expect(response.obj).to.deep.equal({
|
|
|
+ changes: changes.slice(0, 5).map(c => c.toRaw()),
|
|
|
+ hasMore: true,
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ it('returns only requested changes', async function () {
|
|
|
+ const response =
|
|
|
+ await testServer.basicAuthClient.apis.Project.getChanges({
|
|
|
+ project_id: projectId,
|
|
|
+ since: 12,
|
|
|
+ })
|
|
|
+ expect(response.status).to.equal(HTTPStatus.OK)
|
|
|
+ expect(response.obj).to.deep.equal({
|
|
|
+ changes: changes.slice(12, 15).map(c => c.toRaw()),
|
|
|
+ hasMore: true,
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ it('returns changes in the latest chunk', async function () {
|
|
|
+ const response =
|
|
|
+ await testServer.basicAuthClient.apis.Project.getChanges({
|
|
|
+ project_id: projectId,
|
|
|
+ since: 20,
|
|
|
+ })
|
|
|
+ expect(response.status).to.equal(HTTPStatus.OK)
|
|
|
+ expect(response.obj).to.deep.equal({
|
|
|
+ changes: changes.slice(20).map(c => c.toRaw()),
|
|
|
+ hasMore: false,
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
})
|
|
|
|