From 92933002e923ff75539769e0dee4390d91578eb6 Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Wed, 1 Oct 2025 12:03:23 +0200 Subject: [PATCH] use async/await HealthCheckTests, promisify helpers GitOrigin-RevId: 1016296695eb1c09d74d6f50c765438b83df1024 --- .../test/acceptance/js/HealthCheckTests.js | 87 +++++++------------ .../js/helpers/ProjectHistoryApp.js | 5 ++ .../js/helpers/ProjectHistoryClient.js | 5 ++ 3 files changed, 42 insertions(+), 55 deletions(-) diff --git a/services/project-history/test/acceptance/js/HealthCheckTests.js b/services/project-history/test/acceptance/js/HealthCheckTests.js index 1fc9efa14c..c70b893de5 100644 --- a/services/project-history/test/acceptance/js/HealthCheckTests.js +++ b/services/project-history/test/acceptance/js/HealthCheckTests.js @@ -1,17 +1,6 @@ -/* eslint-disable - no-undef, -*/ -// 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 { expect } from 'chai' import settings from '@overleaf/settings' -import request from 'request' +import { fetchNothing } from '@overleaf/fetch-utils' import mongodb from 'mongodb-legacy' import nock from 'nock' import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js' @@ -22,55 +11,43 @@ const MockHistoryStore = () => nock('http://127.0.0.1:3100') const MockWeb = () => nock('http://127.0.0.1:3000') describe('Health Check', function () { - beforeEach(function (done) { + beforeEach(async function () { const projectId = new ObjectId() const historyId = new ObjectId().toString() settings.history.healthCheck = { project_id: projectId } - return ProjectHistoryApp.ensureRunning(error => { - if (error != null) { - throw error - } - MockHistoryStore().post('/api/projects').reply(200, { - projectId: historyId, - }) - MockHistoryStore() - .get(`/api/projects/${historyId}/latest/history`) - .reply(200, { - chunk: { - startVersion: 0, - history: { - snapshot: {}, - changes: [], - }, - }, - }) - MockWeb() - .get(`/project/${projectId}/details`) - .reply(200, { - name: 'Test Project', - overleaf: { - history: { - id: historyId, - }, - }, - }) - return ProjectHistoryClient.initializeProject(historyId, done) + await ProjectHistoryApp.promises.ensureRunning() + + MockHistoryStore().post('/api/projects').reply(200, { + projectId: historyId, }) + MockHistoryStore() + .get(`/api/projects/${historyId}/latest/history`) + .reply(200, { + chunk: { + startVersion: 0, + history: { + snapshot: {}, + changes: [], + }, + }, + }) + MockWeb() + .get(`/project/${projectId}/details`) + .reply(200, { + name: 'Test Project', + overleaf: { + history: { + id: historyId, + }, + }, + }) + + await ProjectHistoryClient.promises.initializeProject(historyId) }) - return it('should respond to the health check', function (done) { - return request.get( - { - url: 'http://127.0.0.1:3054/health_check', - }, - (error, res, body) => { - if (error != null) { - return callback(error) - } - expect(res.statusCode).to.equal(200) - return done() - } - ) + it('should respond to the health check', async function () { + const response = await fetchNothing('http://127.0.0.1:3054/health_check') + expect(response.status).to.equal(200) }) }) diff --git a/services/project-history/test/acceptance/js/helpers/ProjectHistoryApp.js b/services/project-history/test/acceptance/js/helpers/ProjectHistoryApp.js index 6a81221840..59a9d34d88 100644 --- a/services/project-history/test/acceptance/js/helpers/ProjectHistoryApp.js +++ b/services/project-history/test/acceptance/js/helpers/ProjectHistoryApp.js @@ -10,6 +10,7 @@ */ import { app } from '../../../../app/js/server.js' import { mongoClient } from '../../../../app/js/mongodb.js' +import { promisify } from '@overleaf/promise-utils' let running = false let initing = false @@ -43,3 +44,7 @@ export function ensureRunning(callback) { }) }) } + +export const promises = { + ensureRunning: promisify(ensureRunning), +} diff --git a/services/project-history/test/acceptance/js/helpers/ProjectHistoryClient.js b/services/project-history/test/acceptance/js/helpers/ProjectHistoryClient.js index 92caa4bd0e..77f3103a7c 100644 --- a/services/project-history/test/acceptance/js/helpers/ProjectHistoryClient.js +++ b/services/project-history/test/acceptance/js/helpers/ProjectHistoryClient.js @@ -3,6 +3,7 @@ import request from 'request' import Settings from '@overleaf/settings' import RedisWrapper from '@overleaf/redis-wrapper' import { db } from '../../../../app/js/mongodb.js' +import { promisify } from '@overleaf/promise-utils' const rclient = RedisWrapper.createClient(Settings.redis.project_history) const Keys = Settings.redis.project_history.key_schema @@ -352,3 +353,7 @@ export function deleteProject(projectId, callback) { callback() }) } + +export const promises = { + initializeProject: promisify(initializeProject), +}