From 4cf1be966d3b8ef03405f80c6287d5890720868c Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sat, 29 Jul 2023 18:38:52 +0200 Subject: [PATCH] fix appendRevision (#5805) * test cov * Added test for checking if a new pad can be created and deleted. --------- Co-authored-by: SamTV12345 <40429738+samtv12345@users.noreply.github.com> --- src/node/db/Pad.js | 2 +- src/tests/backend/specs/api/chat.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index a9c87541f..751da1ae5 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -75,7 +75,7 @@ class Pad { async appendRevision(aChangeset, authorId = '') { const newAText = Changeset.applyToAText(aChangeset, this.atext, this.pool); - if (newAText.text === this.atext.text && newAText.attribs === this.atext.attribs) { + if (newAText.text === this.atext.text && newAText.attribs === this.atext.attribs && this.head !== -1) { return this.head; } Changeset.copyAText(newAText, this.atext); diff --git a/src/tests/backend/specs/api/chat.js b/src/tests/backend/specs/api/chat.js index fcc69a363..bfd637349 100644 --- a/src/tests/backend/specs/api/chat.js +++ b/src/tests/backend/specs/api/chat.js @@ -49,6 +49,24 @@ describe(__filename, function () { }); }); + + describe('createPad with empty text', () => { + it('creates a new Pad with empty text', function (done) { + agent.get(`${endPoint('createPad')}&padID=${padID}&text=`) + .expect((res) => { + if (res.body.code !== 0) throw new Error('Unable to create new Pad'); + }) + .expect('Content-Type', /json/) + .expect(200); + agent.get(`${endPoint('deletePad')}&padID=${padID}`) + .expect((res) => { + if (res.body.code !== 0) throw new Error('Unable to delete empty Pad'); + }) + .expect('Content-Type', /json/) + .expect(200, done); + }); + }); + describe('createAuthor', function () { it('Creates an author with a name set', function (done) { agent.get(endPoint('createAuthor'))