From abe3bd50a72282d67a1f3ff8ef654ddcea7ab97d Mon Sep 17 00:00:00 2001 From: ekremney Date: Mon, 26 Aug 2024 14:06:22 +0200 Subject: [PATCH] feat: coverage --- src/index.js | 12 ++++-------- test/index.test.js | 10 ++++------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/index.js b/src/index.js index ca3a21e3..c52d4299 100644 --- a/src/index.js +++ b/src/index.js @@ -11,10 +11,10 @@ */ import wrap from '@adobe/helix-shared-wrap'; import { helixStatus } from '@adobe/helix-status'; -import { Response } from '@adobe/fetch'; import secrets from '@adobe/helix-shared-secrets'; import dataAccess from '@adobe/spacecat-shared-data-access'; import { resolveSecretsName, sqsEventAdapter } from '@adobe/spacecat-shared-utils'; +import { internalServerError, notFound, ok } from '@adobe/spacecat-shared-http-utils'; import sqs from './support/sqs.js'; import apex from './apex/handler.js'; @@ -45,6 +45,7 @@ const HANDLERS = { 'experimentation-ess-daily': essExperimentationDaily, 'experimentation-ess-all': essExperimentationAll, costs, + dummy: (message) => ok(message), }; function getElapsedSeconds(startTime) { @@ -69,7 +70,7 @@ async function run(message, context) { if (!handler) { const msg = `no such audit type: ${type}`; log.error(msg); - return new Response('', { status: 404 }); + return notFound(); } const startTime = process.hrtime(); @@ -82,12 +83,7 @@ async function run(message, context) { return result; } catch (e) { log.error(`Audit failed after ${getElapsedSeconds(startTime)} seconds`, e); - return new Response('', { - status: e.statusCode || 500, - headers: { - 'x-error': 'internal server error', - }, - }); + return internalServerError(); } } diff --git a/test/index.test.js b/test/index.test.js index 6f3769dd..01addaa5 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -29,8 +29,8 @@ describe('Index Tests', () => { beforeEach('setup', () => { messageBodyJson = { - type: 'cwv', - url: 'adobe.com', + type: 'dummy', + url: 'site-id', auditContext: { key: 'value', }, @@ -80,10 +80,8 @@ describe('Index Tests', () => { expect(resp.status).to.equal(500); }); - it('fails when missing required env variables', async () => { + it('happy path', async () => { const resp = await main(request, context); - - expect(resp.status).to.equal(500); - expect(resp.headers.plain()['x-error']).to.equal('internal server error'); + expect(resp.status).to.equal(200); }); });