From 317ca32148d266415dbfdceaf35c3630db73f5b8 Mon Sep 17 00:00:00 2001 From: alinarublea Date: Wed, 13 Dec 2023 14:37:16 +0100 Subject: [PATCH 1/2] feat: add rum api calls to shared --- .../src/index.js | 16 +++++++++++++ .../test/rum-api-client.test.js | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/packages/spacecat-shared-rum-api-client/src/index.js b/packages/spacecat-shared-rum-api-client/src/index.js index 195fd2a7..fda9255c 100644 --- a/packages/spacecat-shared-rum-api-client/src/index.js +++ b/packages/spacecat-shared-rum-api-client/src/index.js @@ -18,6 +18,8 @@ import { fetch } from './utils.js'; const APIS = { ROTATE_DOMAINKEYS: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rotate-domainkeys', RUM_DASHBOARD: 'https://main--franklin-dashboard--adobe.hlx.live/views/rum-dashboard', + DOMAIN_LIST: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-dashboard', + NOT_FOUND_CHECKPOINTS: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-checkpoint-urls', }; export async function sendRequest(url, opts) { @@ -85,6 +87,20 @@ export default class RUMAPIClient { this.domainkey = domainkey; } + async getRUMDashboard(params) { + return sendRequest(createUrl( + APIS.DOMAIN_LIST, + { domainkey: this.domainkey, ...params }, + )); + } + + async get404Checkpoints(params) { + return sendRequest(createUrl( + APIS.NOT_FOUND_CHECKPOINTS, + { domainkey: this.domainkey, ...params }, + )); + } + async createBacklink(url, expiry) { const scopedDomainKey = await generateDomainKey(this.domainkey, url, expiry); return `${APIS.RUM_DASHBOARD}?interval=${expiry}&offset=0&limit=100&url=${url}&domainkey=${scopedDomainKey}`; diff --git a/packages/spacecat-shared-rum-api-client/test/rum-api-client.test.js b/packages/spacecat-shared-rum-api-client/test/rum-api-client.test.js index fad0eb76..9418a51c 100644 --- a/packages/spacecat-shared-rum-api-client/test/rum-api-client.test.js +++ b/packages/spacecat-shared-rum-api-client/test/rum-api-client.test.js @@ -59,4 +59,28 @@ describe('rum api client', () => { await expect(sendRequest('https://space.cat/dummy-page')) .to.be.rejectedWith('Unexpected response from rum api. $.results.data is not array'); }); + + it('returns data when getRUMDashboard api is successful', async () => { + nock('https://helix-pages.anywhere.run/helix-services') + .get('/run-query@v3/rum-dashboard') + .query({ + domainkey: 'hebele', + }) + .reply(200, JSON.stringify({ results: { data: [] } })); + const rumApiClient = RUMAPIClient.createFrom({ env: { RUM_API_KEY: 'hebele' } }); + await expect(rumApiClient.getRUMDashboard()) + .to.be.fulfilled; + }); + + it('returns data when get404Checkpoints api is successful', async () => { + nock('https://helix-pages.anywhere.run/helix-services') + .get('/run-query@v3/rum-checkpoint-urls') + .query({ + domainkey: 'hebele', + }) + .reply(200, JSON.stringify({ results: { data: [] } })); + const rumApiClient = RUMAPIClient.createFrom({ env: { RUM_API_KEY: 'hebele' } }); + await expect(rumApiClient.get404Checkpoints()) + .to.be.fulfilled; + }); }); From dbb9457a1cc744cb4ddb12128a4734bc4efee156 Mon Sep 17 00:00:00 2001 From: alinarublea Date: Tue, 30 Jan 2024 13:58:48 +0100 Subject: [PATCH 2/2] fix: update config for site --- .../spacecat-shared-data-access/src/models/site/config.js | 6 +++--- .../test/it/generateSampleData.js | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/spacecat-shared-data-access/src/models/site/config.js b/packages/spacecat-shared-data-access/src/models/site/config.js index a7608530..9a614cf9 100644 --- a/packages/spacecat-shared-data-access/src/models/site/config.js +++ b/packages/spacecat-shared-data-access/src/models/site/config.js @@ -18,11 +18,11 @@ export const configSchema = Joi.object({ channel: Joi.string(), }), alerts: Joi.array().items(Joi.object({ - type: Joi.string(), + type: Joi.string().required(), byOrg: Joi.boolean(), mentions: Joi.array().items(Joi.object({ slack: Joi.array().items(Joi.string()) })), - })), -}); + }).unknown(true)), +}).unknown(true); export const DEFAULT_CONFIG = { slack: { diff --git a/packages/spacecat-shared-data-access/test/it/generateSampleData.js b/packages/spacecat-shared-data-access/test/it/generateSampleData.js index d13f9193..e22f2866 100644 --- a/packages/spacecat-shared-data-access/test/it/generateSampleData.js +++ b/packages/spacecat-shared-data-access/test/it/generateSampleData.js @@ -180,6 +180,10 @@ export default async function generateSampleData( type: '404', byOrg: true, mentions: [{ slack: [`${i}-slackId`] }], + }, + { + type: 'organic-keywords', + country: 'RO', }], }, });