Skip to content

Commit

Permalink
fix: use domain key for rum sources query
Browse files Browse the repository at this point in the history
  • Loading branch information
alinarublea committed Mar 19, 2024
1 parent f81d056 commit 559c9db
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/spacecat-shared-rum-api-client/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ export default class RUMAPIClient {
* Method to return the url composed of params that the 404 sources API is called with.
* @param {RUMAPIOptions} params - An object representing the parameters to be included
* for the 404 sources API call.
* @returns A string returning to the 404 sources url including query parameters.
* @returns A promise that resolves a string returning the 404
* sources url including query parameters.
*/
create404URL(params?: RUMAPIOptions): string;
create404URL(params?: RUMAPIOptions): Promise<string>;

/**
* Asynchronous method to return an array with the domain for a specific url
Expand Down
8 changes: 5 additions & 3 deletions packages/spacecat-shared-rum-api-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ export default class RUMAPIClient {
this.domainkey = domainkey;
}

create404URL(params = {}) {
async create404URL(params = {}) {
const scopedDomainKey = await generateDomainKey(this.domainkey, params?.url, 7);
return createUrl(
APIS.RUM_SOURCES,
{
domainkey: this.domainkey, ...NOT_FOUND_DEFAULT_PARAMS, ...params,
domainkey: scopedDomainKey, ...NOT_FOUND_DEFAULT_PARAMS, ...params,
},
);
}
Expand Down Expand Up @@ -159,7 +160,8 @@ export default class RUMAPIClient {
}

async get404Sources(params = {}) {
return sendRequest(this.create404URL(params));
const notFoundURL = await this.create404URL(params);
return sendRequest(notFoundURL);
}

async getDomainList(params = {}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import nock from 'nock';
import RUMAPIClient, { sendRequest } from '../src/index.js';
import { successKeyResponse } from './rumapi-data.js';

chai.use(chaiAsPromised);
const { expect } = chai;
Expand Down Expand Up @@ -91,10 +92,14 @@ describe('rum api client', () => {
}]);
});

it('returns the URL to call the get404Sources', () => {
it('returns the URL to call the get404Sources', async () => {
const rumApiClient = RUMAPIClient.createFrom({ env: { RUM_DOMAIN_KEY: 'hebele' } });
expect(rumApiClient.create404URL({ url: 'http://spacecar.com' }))
.to.eql('https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-sources?domainkey=hebele&interval=7&offset=0&limit=101&checkpoint=404&url=http%3A%2F%2Fspacecar.com');
nock('https://helix-pages.anywhere.run')
.post('/helix-services/run-query@v3/rotate-domainkeys')
.query(true)
.reply(200, successKeyResponse);
await expect(rumApiClient.create404URL({ url: 'http://spacecar.com' }))
.to.eventually.eql('https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-sources?domainkey=scoped-domain-key&interval=7&offset=0&limit=101&checkpoint=404&url=http%3A%2F%2Fspacecar.com');
});

it('returns the URL to call the getRUMDashboard', () => {
Expand All @@ -104,18 +109,23 @@ describe('rum api client', () => {
});

it('returns data when get404Sources api is successful', async () => {
nock('https://helix-pages.anywhere.run')
.post('/helix-services/run-query@v3/rotate-domainkeys')
.query(true)
.reply(200, successKeyResponse);
nock('https://helix-pages.anywhere.run/helix-services')
.get('/run-query@v3/rum-sources')
.query({
domainkey: 'hebele',
domainkey: 'scoped-domain-key',
url: 'spacecar.com',
interval: 7,
offset: 0,
limit: 101,
checkpoint: 404,
})
.reply(200, JSON.stringify({ results: { data: [{ url: 'http://spacecar.com', views: 100, sources: 'www.google.com' }] } }));
const rumApiClient = RUMAPIClient.createFrom({ env: { RUM_DOMAIN_KEY: 'hebele' } });
await expect(rumApiClient.get404Sources())
await expect(rumApiClient.get404Sources({ url: 'spacecar.com' }))
.to.eventually.eql([{ url: 'http://spacecar.com', views: 100, sources: 'www.google.com' }]);
});

Expand Down

0 comments on commit 559c9db

Please sign in to comment.