Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions src/controllers/preflight.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,6 @@ import { getCSPromiseToken, ErrorWithStatusCode } from '../support/utils.js';
export const AUDIT_STEP_IDENTIFY = 'identify';
export const AUDIT_STEP_SUGGEST = 'suggest';

/**
* List of available checks.
* Should not be changed as it would break existing clients.
* @type {string}
*/
export const AUDIT_CANONICAL = 'canonical';
export const AUDIT_LINKS = 'links';
export const AUDIT_METATAGS = 'metatags';
export const AUDIT_BODY_SIZE = 'body-size';
export const AUDIT_LOREM_IPSUM = 'lorem-ipsum';
export const AUDIT_H1_COUNT = 'h1-count';
export const AUDIT_ACCESSIBILITY = 'accessibility';
export const AUDIT_READABILITY = 'readability';

const AVAILABLE_CHECKS = [
AUDIT_CANONICAL,
AUDIT_LINKS,
AUDIT_METATAGS,
AUDIT_BODY_SIZE,
AUDIT_LOREM_IPSUM,
AUDIT_H1_COUNT,
AUDIT_ACCESSIBILITY,
AUDIT_READABILITY,
];

/**
* Creates a preflight controller instance
* @param {Object} ctx - The context object containing dataAccess and sqs
Expand Down Expand Up @@ -107,16 +82,6 @@ function PreflightController(ctx, log, env) {
if (![AUDIT_STEP_IDENTIFY, AUDIT_STEP_SUGGEST].includes(data?.step?.toLowerCase())) {
throw new Error(`Invalid request: step must be either ${AUDIT_STEP_IDENTIFY} or ${AUDIT_STEP_SUGGEST}`);
}

// Validate checks if provided
if (data.checks !== undefined) {
if (!isNonEmptyArray(data.checks)) {
throw new Error('Invalid request: checks must be a non-empty array of strings');
}
if (!data.checks.every((check) => AVAILABLE_CHECKS.includes(check))) {
throw new Error(`Invalid request: checks must be one of: ${AVAILABLE_CHECKS.join(', ')}`);
}
}
}

/**
Expand Down Expand Up @@ -181,7 +146,6 @@ function PreflightController(ctx, log, env) {
siteId: site.getId(),
urls: data.urls,
step,
checks: data.checks || AVAILABLE_CHECKS,
enableAuthentication,
},
jobType: 'preflight',
Expand Down
85 changes: 0 additions & 85 deletions test/controllers/preflight.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ describe('Preflight Controller', () => {
urls: ['https://main--example-site.aem.page/test.html'],
step: 'identify',
enableAuthentication: true,
checks: ['canonical', 'links', 'metatags', 'body-size', 'lorem-ipsum', 'h1-count', 'accessibility', 'readability'],
},
jobType: 'preflight',
tags: ['preflight'],
Expand Down Expand Up @@ -219,7 +218,6 @@ describe('Preflight Controller', () => {
urls: ['https://main--example-site.aem.page/test.html'],
step: 'identify',
enableAuthentication: false,
checks: ['canonical', 'links', 'metatags', 'body-size', 'lorem-ipsum', 'h1-count', 'accessibility', 'readability'],
},
jobType: 'preflight',
tags: ['preflight'],
Expand All @@ -236,88 +234,6 @@ describe('Preflight Controller', () => {
);
});

it('creates a preflight job with specific checks', async () => {
const context = {
data: {
urls: ['https://example.com/test.html'],
step: 'identify',
checks: ['canonical', 'metatags'],
},
};

const response = await preflightController.createPreflightJob(context);
expect(response.status).to.equal(202);

expect(mockDataAccess.AsyncJob.create).to.have.been.calledWith({
status: 'IN_PROGRESS',
metadata: {
payload: {
siteId: 'test-site-123',
urls: ['https://example.com/test.html'],
step: 'identify',
enableAuthentication: true,
checks: ['canonical', 'metatags'],
},
jobType: 'preflight',
tags: ['preflight'],
},
});
});

it('returns 400 Bad Request for empty checks array', async () => {
const context = {
data: {
urls: ['https://example.com/test.html'],
step: 'identify',
checks: [],
},
};

const response = await preflightController.createPreflightJob(context);
expect(response.status).to.equal(400);

const result = await response.json();
expect(result).to.deep.equal({
message: 'Invalid request: checks must be a non-empty array of strings',
});
});

it('returns 400 Bad Request for invalid check type', async () => {
const context = {
data: {
urls: ['https://example.com/test.html'],
step: 'identify',
checks: ['invalid-check'],
},
};

const response = await preflightController.createPreflightJob(context);
expect(response.status).to.equal(400);

const result = await response.json();
expect(result).to.deep.equal({
message: 'Invalid request: checks must be one of: canonical, links, metatags, body-size, lorem-ipsum, h1-count, accessibility, readability',
});
});

it('returns 400 Bad Request if checks is not an array', async () => {
const context = {
data: {
urls: ['https://example.com/test.html'],
step: 'identify',
checks: 'canonical',
},
};

const response = await preflightController.createPreflightJob(context);
expect(response.status).to.equal(400);

const result = await response.json();
expect(result).to.deep.equal({
message: 'Invalid request: checks must be a non-empty array of strings',
});
});

it('creates a preflight job successfully in CI environment', async () => {
const context = {
data: {
Expand Down Expand Up @@ -354,7 +270,6 @@ describe('Preflight Controller', () => {
urls: ['https://main--example-site.aem.page/test.html'],
step: 'identify',
enableAuthentication: true,
checks: ['canonical', 'links', 'metatags', 'body-size', 'lorem-ipsum', 'h1-count', 'accessibility', 'readability'],
},
jobType: 'preflight',
tags: ['preflight'],
Expand Down