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
12 changes: 10 additions & 2 deletions src/controllers/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,17 @@ function SuggestionsController(ctx, sqs, env) {
if (!isNonEmptyObject(context.data)) {
return badRequest('No updates provided');
}
const { suggestionIds, variationName: variation } = context.data;
const { suggestionIds, variations, action } = context.data;

if (!isArray(suggestionIds)) {
return badRequest('Request body must be an array of suggestionIds');
}
if (variations && !isArray(variations)) {
return badRequest('variations must be an array');
}
if (action !== undefined && !hasText(action)) {
return badRequest('action cannot be empty');
}
const site = await Site.findById(siteId);
if (!site) {
return notFound('Site not found');
Expand Down Expand Up @@ -593,7 +600,8 @@ function SuggestionsController(ctx, sqs, env) {
opportunityId,
groupedSuggestions.map((s) => s.getId()),
promiseTokenResponse,
variation,
variations,
action,
{ url },
)),
);
Expand Down
28 changes: 28 additions & 0 deletions test/controllers/suggestions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,34 @@ describe('Suggestions Controller', () => {
expect(error).to.have.property('message', 'Opportunity ID required');
});

it('auto-fix suggestions status returns bad request if variations is not an array', async () => {
const response = await suggestionsController.autofixSuggestions({
params: {
siteId: SITE_ID,
opportunityId: OPPORTUNITY_ID,
},
data: { suggestionIds: [SUGGESTION_IDS[0], SUGGESTION_IDS[2]], variations: 'not an array' },
...context,
});
expect(response.status).to.equal(400);
const error = await response.json();
expect(error).to.have.property('message', 'variations must be an array');
});

it('auto-fix suggestions status returns bad request if action is empty', async () => {
const response = await suggestionsController.autofixSuggestions({
params: {
siteId: SITE_ID,
opportunityId: OPPORTUNITY_ID,
},
data: { suggestionIds: [SUGGESTION_IDS[0], SUGGESTION_IDS[2]], action: '' },
...context,
});
expect(response.status).to.equal(400);
const error = await response.json();
expect(error).to.have.property('message', 'action cannot be empty');
});

it('auto-fix suggestions status returns bad request if no data is passed', async () => {
const response = await suggestionsController.autofixSuggestions({
params: {
Expand Down