Skip to content
Open
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
20 changes: 14 additions & 6 deletions src/controllers/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,14 +973,22 @@ function SuggestionsController(ctx, sqs, env) {
return badRequest(`Handler is not enabled for site ${site.getId()} autofix type ${opportunity.getType()}`);
}
const { AUTOFIX_JOBS_QUEUE: queueUrl } = env;
// Intentionally omit opportunityId: worker uses context differently for URL-based assessments
await sqs.sendMessage(queueUrl, {
await sqs.sendMessage(
queueUrl,
{
siteId,
opportunityId,
action: 'assess-urls',
pages,
...(precheckOnly === true && { precheckOnly: true }),
},
);
return accepted({
message: 'Assess-urls job queued',
siteId,
action: 'assess-urls',
pages,
...(precheckOnly === true && { precheckOnly: true }),
opportunityId,
pagesCount: pages.length,
});
return accepted({ message: 'Assess-urls job queued', siteId, pagesCount: pages.length });
}

// suggestion-based flow (assess, fix, etc.)
Expand Down
25 changes: 25 additions & 0 deletions test/controllers/suggestions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3971,11 +3971,13 @@ describe('Suggestions Controller', () => {
const body = await response.json();
expect(body).to.have.property('message', 'Assess-urls job queued');
expect(body).to.have.property('siteId', SITE_ID);
expect(body).to.have.property('opportunityId', OPPORTUNITY_ID);
expect(body).to.have.property('pagesCount', 2);

expect(mockSqs.sendMessage).to.have.been.calledOnce;
const payload = mockSqs.sendMessage.firstCall.args[1];
expect(payload).to.have.property('siteId', SITE_ID);
expect(payload).to.have.property('opportunityId', OPPORTUNITY_ID);
expect(payload).to.have.property('action', 'assess-urls');
expect(payload).to.deep.include({ pages });
});
Expand All @@ -3993,6 +3995,29 @@ describe('Suggestions Controller', () => {
expect(payload).to.have.property('precheckOnly', true);
});

it('passes opportunityId to worker for precheck result persistence', async () => {
const pages = ['https://example.com/page1', 'https://example.com/page2'];
const response = await suggestionsController.autofixSuggestions({
params: { siteId: SITE_ID, opportunityId: OPPORTUNITY_ID },
data: { action: 'assess-urls', pages },
...context,
});

expect(response.status).to.equal(202);
const body = await response.json();
expect(body).to.have.property('opportunityId', OPPORTUNITY_ID);

expect(mockSqs.sendMessage).to.have.been.calledOnce;
const payload = mockSqs.sendMessage.firstCall.args[1];
expect(payload).to.have.property('opportunityId', OPPORTUNITY_ID);
// Verify opportunityId is passed alongside siteId and action
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test duplicates assertions already present in the updated existing test above and adds value only in its additional expect(payload).to.include({...}) assertion (which checks three fields together).
Consider either removing the duplicate by merging the two tests or making the new test genuinely distinct.

expect(payload).to.include({
siteId: SITE_ID,
opportunityId: OPPORTUNITY_ID,
action: 'assess-urls',
});
});

it('accepts pages as array of objects with pageUrl and imageUrls', async () => {
const pages = [
{
Expand Down
Loading