From 3840eaa0d88134dbc545e36a929075d217ed9b0b Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Wed, 1 Oct 2025 12:24:04 +0200 Subject: [PATCH] promisify DeleteProjectTests GitOrigin-RevId: a86e6962253bbf4adf5fc9748e7accb9084b31f9 --- .../test/acceptance/js/DeleteProjectTests.js | 69 +++++++------------ .../js/helpers/ProjectHistoryClient.js | 5 ++ 2 files changed, 29 insertions(+), 45 deletions(-) diff --git a/services/project-history/test/acceptance/js/DeleteProjectTests.js b/services/project-history/test/acceptance/js/DeleteProjectTests.js index dcda54a57f..56dc5da3f1 100644 --- a/services/project-history/test/acceptance/js/DeleteProjectTests.js +++ b/services/project-history/test/acceptance/js/DeleteProjectTests.js @@ -10,7 +10,7 @@ const MockWeb = () => nock('http://127.0.0.1:3000') const fixture = path => new URL(`../fixtures/${path}`, import.meta.url) describe('Deleting project', function () { - beforeEach(function (done) { + beforeEach(async function () { this.projectId = new ObjectId().toString() this.historyId = new ObjectId().toString() MockWeb() @@ -23,61 +23,40 @@ describe('Deleting project', function () { .get(`/api/projects/${this.historyId}/latest/history`) .replyWithFile(200, fixture('chunks/0-3.json')) MockHistoryStore().delete(`/api/projects/${this.historyId}`).reply(204) - ProjectHistoryApp.ensureRunning(done) + await ProjectHistoryApp.promises.ensureRunning() }) - describe('when the project has no pending updates', function (done) { - it('successfully deletes the project', function (done) { - ProjectHistoryClient.deleteProject(this.projectId, done) + describe('when the project has no pending updates', function () { + it('successfully deletes the project', async function () { + await ProjectHistoryClient.promises.deleteProject(this.projectId) }) }) - describe('when the project has pending updates', function (done) { - beforeEach(function (done) { - ProjectHistoryClient.pushRawUpdate( + describe('when the project has pending updates', function () { + beforeEach(async function () { + await ProjectHistoryClient.promises.pushRawUpdate(this.projectId, { + pathname: '/main.tex', + docLines: 'hello', + doc: this.docId, + meta: { userId: this.userId, ts: new Date() }, + }) + await ProjectHistoryClient.promises.setFirstOpTimestamp( this.projectId, - { - pathname: '/main.tex', - docLines: 'hello', - doc: this.docId, - meta: { userId: this.userId, ts: new Date() }, - }, - err => { - if (err) { - return done(err) - } - ProjectHistoryClient.setFirstOpTimestamp( - this.projectId, - Date.now(), - err => { - if (err) { - return done(err) - } - ProjectHistoryClient.deleteProject(this.projectId, done) - } - ) - } + Date.now() ) + await ProjectHistoryClient.promises.deleteProject(this.projectId) }) - it('clears pending updates', function (done) { - ProjectHistoryClient.getDump(this.projectId, (err, dump) => { - if (err) { - return done(err) - } - expect(dump.updates).to.deep.equal([]) - done() - }) + it('clears pending updates', async function () { + const dump = await ProjectHistoryClient.promises.getDump(this.projectId) + expect(dump.updates).to.deep.equal([]) }) - it('clears the first op timestamp', function (done) { - ProjectHistoryClient.getFirstOpTimestamp(this.projectId, (err, ts) => { - if (err) { - return done(err) - } - expect(ts).to.be.null - done() - }) + it('clears the first op timestamp', async function () { + const ts = await ProjectHistoryClient.promises.getFirstOpTimestamp( + this.projectId + ) + expect(ts).to.be.null }) }) }) diff --git a/services/project-history/test/acceptance/js/helpers/ProjectHistoryClient.js b/services/project-history/test/acceptance/js/helpers/ProjectHistoryClient.js index 77f3103a7c..d3afa1e547 100644 --- a/services/project-history/test/acceptance/js/helpers/ProjectHistoryClient.js +++ b/services/project-history/test/acceptance/js/helpers/ProjectHistoryClient.js @@ -356,4 +356,9 @@ export function deleteProject(projectId, callback) { export const promises = { initializeProject: promisify(initializeProject), + deleteProject: promisify(deleteProject), + pushRawUpdate: promisify(pushRawUpdate), + setFirstOpTimestamp: promisify(setFirstOpTimestamp), + getFirstOpTimestamp: promisify(getFirstOpTimestamp), + getDump: promisify(getDump), }