Skip to content

Commit

Permalink
feat: coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ekremney committed Aug 26, 2024
1 parent 4a06a38 commit abe3bd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
12 changes: 4 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -45,6 +45,7 @@ const HANDLERS = {
'experimentation-ess-daily': essExperimentationDaily,
'experimentation-ess-all': essExperimentationAll,
costs,
dummy: (message) => ok(message),
};

function getElapsedSeconds(startTime) {
Expand All @@ -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();
Expand All @@ -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();
}
}

Expand Down
10 changes: 4 additions & 6 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('Index Tests', () => {

beforeEach('setup', () => {
messageBodyJson = {
type: 'cwv',
url: 'adobe.com',
type: 'dummy',
url: 'site-id',
auditContext: {
key: 'value',
},
Expand Down Expand Up @@ -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);
});
});

0 comments on commit abe3bd5

Please sign in to comment.