Skip to content

Commit b189ff2

Browse files
committed
feat: add empty suggestions for forms opportunity - refactoring
1 parent f4a02ca commit b189ff2

File tree

4 files changed

+74
-177
lines changed

4 files changed

+74
-177
lines changed

src/forms-opportunities/guidance-handlers/guidance-high-form-views-low-conversions.js

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,8 @@
1111
*/
1212

1313
import { ok } from '@adobe/spacecat-shared-http-utils';
14-
import { v4 as uuidv4 } from 'uuid';
1514
import { FORM_OPPORTUNITY_TYPES, ORIGINS } from '../constants.js';
16-
17-
/**
18-
* Fetches existing suggestions and merges them with new suggestions
19-
* @param opportunity
20-
* @param newSuggestions
21-
* @returns {Promise<void>}
22-
*/
23-
async function addSuggestions(
24-
opportunity,
25-
newSuggestions,
26-
) {
27-
const existingSuggestions = await opportunity.getSuggestions();
28-
29-
if (
30-
(existingSuggestions && existingSuggestions.length > 0)
31-
|| (newSuggestions && newSuggestions.length > 0)
32-
) {
33-
// merge existing and new suggestions and add to opportunity.
34-
// To be done once M starts generating suggestions for this guidance
35-
} else {
36-
const emptySuggestionList = [
37-
{
38-
id: uuidv4(),
39-
opportunityId: opportunity.opportunityId,
40-
type: 'CONTENT_UPDATE',
41-
rank: 1,
42-
status: 'PENDING_VALIDATION',
43-
data: {
44-
variations: [
45-
{
46-
name: 'Control',
47-
changes: [
48-
{
49-
type: 'text',
50-
element: null,
51-
text: 'Control',
52-
},
53-
],
54-
variationEditPageUrl: null,
55-
id: uuidv4(),
56-
variationPageUrl: '',
57-
explanation: null,
58-
projectedImpact: null,
59-
previewImage: '',
60-
},
61-
],
62-
},
63-
kpiDeltas: {
64-
estimatedKPILift: 0,
65-
},
66-
createdAt: new Date().toISOString(),
67-
updatedAt: new Date().toISOString(),
68-
updatedBy: 'system',
69-
},
70-
];
71-
await opportunity.addSuggestions(emptySuggestionList);
72-
}
73-
}
15+
import { addSuggestions } from './suggestion-utils.js';
7416

7517
export default async function handler(message, context) {
7618
const { log, dataAccess } = context;

src/forms-opportunities/guidance-handlers/guidance-high-page-views-low-form-nav.js

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,8 @@
1111
*/
1212

1313
import { ok } from '@adobe/spacecat-shared-http-utils';
14-
import { v4 as uuidv4 } from 'uuid';
1514
import { FORM_OPPORTUNITY_TYPES, ORIGINS } from '../constants.js';
16-
17-
/**
18-
* Fetches existing suggestions and merges them with new suggestions
19-
* @param opportunity
20-
* @param newSuggestions
21-
* @returns {Promise<void>}
22-
*/
23-
async function addSuggestions(
24-
opportunity,
25-
newSuggestions,
26-
) {
27-
const existingSuggestions = await opportunity.getSuggestions();
28-
29-
if (
30-
(existingSuggestions && existingSuggestions.length > 0)
31-
|| (newSuggestions && newSuggestions.length > 0)
32-
) {
33-
// merge existing and new suggestions and add to opportunity.
34-
// To be done once M starts generating suggestions for this guidance
35-
} else {
36-
const emptySuggestionList = [
37-
{
38-
id: uuidv4(),
39-
opportunityId: opportunity.opportunityId,
40-
type: 'CONTENT_UPDATE',
41-
rank: 1,
42-
status: 'PENDING_VALIDATION',
43-
data: {
44-
variations: [
45-
{
46-
name: 'Control',
47-
changes: [
48-
{
49-
type: 'text',
50-
element: null,
51-
text: 'Control',
52-
},
53-
],
54-
variationEditPageUrl: null,
55-
id: uuidv4(),
56-
variationPageUrl: '',
57-
explanation: null,
58-
projectedImpact: null,
59-
previewImage: '',
60-
},
61-
],
62-
},
63-
kpiDeltas: {
64-
estimatedKPILift: 0,
65-
},
66-
createdAt: new Date().toISOString(),
67-
updatedAt: new Date().toISOString(),
68-
updatedBy: 'system',
69-
},
70-
];
71-
await opportunity.addSuggestions(emptySuggestionList);
72-
}
73-
}
15+
import { addSuggestions } from './suggestion-utils.js';
7416

7517
export default async function handler(message, context) {
7618
const { log, dataAccess } = context;

src/forms-opportunities/guidance-handlers/guidance-high-page-views-low-form-views.js

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,8 @@
1111
*/
1212

1313
import { ok } from '@adobe/spacecat-shared-http-utils';
14-
import { v4 as uuidv4 } from 'uuid';
1514
import { FORM_OPPORTUNITY_TYPES, ORIGINS } from '../constants.js';
16-
17-
/**
18-
* Fetches existing suggestions and merges them with new suggestions
19-
* @param opportunity
20-
* @param newSuggestions
21-
* @returns {Promise<void>}
22-
*/
23-
async function addSuggestions(
24-
opportunity,
25-
newSuggestions,
26-
) {
27-
const existingSuggestions = await opportunity.getSuggestions();
28-
29-
if (
30-
(existingSuggestions && existingSuggestions.length > 0)
31-
|| (newSuggestions && newSuggestions.length > 0)
32-
) {
33-
// merge existing and new suggestions and add to opportunity.
34-
// To be done once M starts generating suggestions for this guidance
35-
} else {
36-
const emptySuggestionList = [
37-
{
38-
id: uuidv4(),
39-
opportunityId: opportunity.opportunityId,
40-
type: 'CONTENT_UPDATE',
41-
rank: 1,
42-
status: 'PENDING_VALIDATION',
43-
data: {
44-
variations: [
45-
{
46-
name: 'Control',
47-
changes: [
48-
{
49-
type: 'text',
50-
element: null,
51-
text: 'Control',
52-
},
53-
],
54-
variationEditPageUrl: null,
55-
id: uuidv4(),
56-
variationPageUrl: '',
57-
explanation: null,
58-
projectedImpact: null,
59-
previewImage: '',
60-
},
61-
],
62-
},
63-
kpiDeltas: {
64-
estimatedKPILift: 0,
65-
},
66-
createdAt: new Date().toISOString(),
67-
updatedAt: new Date().toISOString(),
68-
updatedBy: 'system',
69-
},
70-
];
71-
await opportunity.addSuggestions(emptySuggestionList);
72-
}
73-
}
15+
import { addSuggestions } from './suggestion-utils.js';
7416

7517
export default async function handler(message, context) {
7618
const { log, dataAccess } = context;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2025 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import { v4 as uuidv4 } from 'uuid';
14+
15+
/**
16+
* Fetches existing suggestions and merges them with new suggestions
17+
* @param opportunity
18+
* @param newSuggestions
19+
* @returns {Promise<void>}
20+
*/
21+
export async function addSuggestions(
22+
opportunity,
23+
newSuggestions,
24+
) {
25+
const existingSuggestions = await opportunity.getSuggestions();
26+
27+
if (
28+
(existingSuggestions && existingSuggestions.length > 0)
29+
|| (newSuggestions && newSuggestions.length > 0)
30+
) {
31+
// merge existing and new suggestions and add to opportunity.
32+
// To be done once M starts generating suggestions for this guidance
33+
} else {
34+
const emptySuggestionList = [
35+
{
36+
id: uuidv4(),
37+
opportunityId: opportunity.opportunityId,
38+
type: 'CONTENT_UPDATE',
39+
rank: 1,
40+
status: 'PENDING_VALIDATION',
41+
data: {
42+
variations: [
43+
{
44+
name: 'Control',
45+
changes: [
46+
{
47+
type: 'text',
48+
element: null,
49+
text: 'Control',
50+
},
51+
],
52+
variationEditPageUrl: null,
53+
id: uuidv4(),
54+
variationPageUrl: '',
55+
explanation: null,
56+
projectedImpact: null,
57+
previewImage: '',
58+
},
59+
],
60+
},
61+
kpiDeltas: {
62+
estimatedKPILift: 0,
63+
},
64+
createdAt: new Date().toISOString(),
65+
updatedAt: new Date().toISOString(),
66+
updatedBy: 'system',
67+
},
68+
];
69+
await opportunity.addSuggestions(emptySuggestionList);
70+
}
71+
}

0 commit comments

Comments
 (0)