From 54f6836efea526ff7c1f5b3e2ff8625f0d570a40 Mon Sep 17 00:00:00 2001 From: mistakia <1823355+mistakia@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:12:34 -0400 Subject: [PATCH] fix: test failure --- api/routes/network.mjs | 8 +++++--- api/routes/posts.mjs | 16 +++++++++------- api/routes/representatives/index.mjs | 10 ++++++---- test/global.mjs | 3 +++ 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/api/routes/network.mjs b/api/routes/network.mjs index c5e30184..bc9f9318 100644 --- a/api/routes/network.mjs +++ b/api/routes/network.mjs @@ -55,9 +55,11 @@ const load_network = async () => { return response_data } -cron.schedule('*/5 * * * *', async () => { - await load_network() -}) +if (process.env.NODE_ENV !== 'test') { + cron.schedule('*/5 * * * *', async () => { + await load_network() + }) +} router.get('/', async (req, res) => { const { logger, cache } = req.app.locals diff --git a/api/routes/posts.mjs b/api/routes/posts.mjs index d57f85b9..6ba72ae9 100644 --- a/api/routes/posts.mjs +++ b/api/routes/posts.mjs @@ -255,12 +255,14 @@ router.get('/top', async (req, res) => { } }) -cron.schedule('*/7 * * * *', async () => { - const ages = [72, 168, 720] - for (const age of ages) { - await load_top_posts({ age }) - } - await load_trending_posts() -}) +if (process.env.NODE_ENV !== 'test') { + cron.schedule('*/7 * * * *', async () => { + const ages = [72, 168, 720] + for (const age of ages) { + await load_top_posts({ age }) + } + await load_trending_posts() + }) +} export default router diff --git a/api/routes/representatives/index.mjs b/api/routes/representatives/index.mjs index 920699f7..26d57ee9 100644 --- a/api/routes/representatives/index.mjs +++ b/api/routes/representatives/index.mjs @@ -96,11 +96,13 @@ const loadRepresentatives = async () => { return representatives } -loadRepresentatives() +if (process.env.NODE_ENV !== 'test') { + loadRepresentatives() -cron.schedule('*/5 * * * *', async () => { - await loadRepresentatives() -}) + cron.schedule('*/5 * * * *', async () => { + await loadRepresentatives() + }) +} router.get('/', async (req, res) => { const { logger } = req.app.locals diff --git a/test/global.mjs b/test/global.mjs index 685b2856..9eca6961 100644 --- a/test/global.mjs +++ b/test/global.mjs @@ -1,3 +1,4 @@ +/* global before */ import knex from '#db' import path, { dirname } from 'path' import fs from 'fs/promises' @@ -10,3 +11,5 @@ export async function mochaGlobalSetup() { const sql = await fs.readFile(sqlFile, 'utf8') await knex.raw(sql) } + +before(mochaGlobalSetup)