From 183fe4b29b01569909c2c3ae905f2a917b30c515 Mon Sep 17 00:00:00 2001 From: nikiwycherley Date: Wed, 8 May 2024 16:24:51 +0100 Subject: [PATCH] refactored deleting a station --- lib/functions/imtd-process.js | 1 + lib/helpers/imtd-api.js | 9 +-------- test/unit/functions/imtd-process.js | 5 +++-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/functions/imtd-process.js b/lib/functions/imtd-process.js index c023817..8deb30e 100644 --- a/lib/functions/imtd-process.js +++ b/lib/functions/imtd-process.js @@ -60,6 +60,7 @@ async function getData (stationId) { await insertThresholds(stationId, thresholds) } else { await deleteThresholds(stationId, tableName) + logger.info(`Deleted data for RLOI id ${stationId}`) } } catch (error) { logger.error(`Could not process data for station ${stationId} (${error.message})`) diff --git a/lib/helpers/imtd-api.js b/lib/helpers/imtd-api.js index 1b52369..6f126bd 100644 --- a/lib/helpers/imtd-api.js +++ b/lib/helpers/imtd-api.js @@ -1,14 +1,7 @@ -const logger = require('./logging') const pg = require('./db') async function deleteStation (stationId, tableName) { - try { - await pg(tableName).where({ station_id: stationId }).delete() - logger.info(`Deleted data for RLOI id ${stationId}`) - } catch (error) { - logger.error(`Error deleting data for station ${stationId}`, error) - throw error - } + await pg(tableName).where({ station_id: stationId }).delete() } module.exports = { deleteStation } diff --git a/test/unit/functions/imtd-process.js b/test/unit/functions/imtd-process.js index 58b547c..107867a 100644 --- a/test/unit/functions/imtd-process.js +++ b/test/unit/functions/imtd-process.js @@ -199,9 +199,10 @@ experiment('imtd processing', () => { await handler() const logInfoCalls = logger.info.getCalls() - expect(logInfoCalls.length).to.equal(3) + console.log(logInfoCalls) + expect(logInfoCalls.length).to.equal(4) expect(logInfoCalls[2].args[0]).to.equal('Station 1001 not found (HTTP Status: 404)') - // expect(logInfoCalls[3].args[0]).to.equal('Deleted thresholds for RLOI id 1001') + expect(logInfoCalls[3].args[0]).to.equal('Deleted data for RLOI id 1001') const logErrorCalls = logger.error.getCalls() expect(logErrorCalls.length).to.equal(0)