diff --git a/packages/spacecat-shared-rum-api-client/src/index.js b/packages/spacecat-shared-rum-api-client/src/index.js index e4233d1a..54bf0a63 100644 --- a/packages/spacecat-shared-rum-api-client/src/index.js +++ b/packages/spacecat-shared-rum-api-client/src/index.js @@ -121,13 +121,19 @@ export default class RUMAPIClient { ); } - getExperimentationURL(params = {}) { + createExperimentationURL(params = {}) { return createUrl( APIS.RUM_EXPERIMENTS, - { domainkey: this.domainkey, ...RUM_DEFAULT_PARAMS, ...params }, + { + domainkey: this.domainkey, ...RUM_DEFAULT_PARAMS, ...params, + }, ); } + async getExperimentationData(params = {}) { + return sendRequest(this.createExperimentationURL(params)); + } + async getRUMDashboard(params = {}) { return sendRequest(createUrl( APIS.RUM_DASHBOARD, 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 68602ab3..4f6e3a7d 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 @@ -113,10 +113,74 @@ describe('rum api client', () => { .to.eventually.eql([{ url: 'http://spacecar.com', views: 100, sources: 'www.google.com' }]); }); - it('returns the URL to call the getExperimentationURL', () => { + it('returns the URL to get the Experimentation data', () => { const rumApiClient = RUMAPIClient.createFrom({ env: { RUM_DOMAIN_KEY: 'hebele' } }); - expect(rumApiClient.getExperimentationURL({ url: 'http://spacecar.com' })) - .to.eql('https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-experiments?domainkey=hebele&interval=7&offset=0&limit=101&url=http%3A%2F%2Fspacecar.com'); + expect(rumApiClient.createExperimentationURL({ url: 'http://spacecat.com' })) + .to.eql('https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-experiments?domainkey=hebele&interval=7&offset=0&limit=101&url=http%3A%2F%2Fspacecat.com'); + }); + + it('returns data when getExperimentationData api is successful', async () => { + nock('https://helix-pages.anywhere.run/helix-services') + .get('/run-query@v3/rum-experiments') + .query({ + domainkey: 'hebele', + interval: 7, + offset: 0, + limit: 101, + url: 'http://spacecat.com', + }) + .reply(200, JSON.stringify({ + results: { + data: [{ + experiment: '2-21-free-trial-cp-delay-load', + variant: 'challenger-2', + tdiff: 6, + variant_experimentation_events: 24, + control_experimentation_events: 21, + variant_conversion_events: 14, + control_conversion_events: 12, + variant_experimentations: '2400', + control_experimentations: '2100', + variant_conversions: '1400', + control_conversions: '1200', + variant_conversion_rate: '0.583333333', + control_conversion_rate: '0.571428571', + topurl: 'http://spacecat.com', + time95: '2024-02-05 16:00:55+00', + time5: '2024-01-30 00:00:45+00', + pooled_sample_proportion: 0.5777777777777777, + pooled_standard_error: 0.75992086289346, + test: 0.015665791770305738, + p_value: 0.4937504754112301, + remaining_runtime: 57, + }], + }, + })); + const rumApiClient = RUMAPIClient.createFrom({ env: { RUM_DOMAIN_KEY: 'hebele' } }); + await expect(rumApiClient.getExperimentationData({ url: 'http://spacecat.com' })) + .to.eventually.eql([{ + experiment: '2-21-free-trial-cp-delay-load', + variant: 'challenger-2', + tdiff: 6, + variant_experimentation_events: 24, + control_experimentation_events: 21, + variant_conversion_events: 14, + control_conversion_events: 12, + variant_experimentations: '2400', + control_experimentations: '2100', + variant_conversions: '1400', + control_conversions: '1200', + variant_conversion_rate: '0.583333333', + control_conversion_rate: '0.571428571', + topurl: 'http://spacecat.com', + time95: '2024-02-05 16:00:55+00', + time5: '2024-01-30 00:00:45+00', + pooled_sample_proportion: 0.5777777777777777, + pooled_standard_error: 0.75992086289346, + test: 0.015665791770305738, + p_value: 0.4937504754112301, + remaining_runtime: 57, + }]); }); it('returns data when getDomainList api is successful for all', async () => {