Skip to content

Commit

Permalink
Use a domain instead of full URL for cdp-cdp-service (consistent with…
Browse files Browse the repository at this point in the history
… SitecoreCloud Engage SDK)
  • Loading branch information
ambrauer committed Sep 21, 2022
1 parent 2f5aa3c commit 14147c6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('PersonalizeMiddleware', () => {
},
cookies: {
get(cookieName: string) {
const cookies = { 'bid_cdp-client-key': 'browser-id', ...props.cookieValues };
const cookies = { 'BID_cdp-client-key': 'browser-id', ...props.cookieValues };

return cookies[cookieName];
},
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('PersonalizeMiddleware', () => {
) => {
const cdpConfig = {
clientKey: 'cdp-client-key',
endpoint: 'http://cdp-endpoint',
domain: 'cdp-endpoint',
pointOfSale: 'cdp-pos',
...(props?.cdpConfig || {}),
};
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('PersonalizeMiddleware', () => {

validateDebugLog('skipped (personalize middleware is disabled)');

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

Expand All @@ -216,7 +216,7 @@ describe('PersonalizeMiddleware', () => {

validateDebugLog('skipped (%s)', 'redirected');

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

Expand Down Expand Up @@ -246,7 +246,7 @@ describe('PersonalizeMiddleware', () => {

validateDebugLog('skipped (%s)', 'preview');

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('__prerender_bypass')).to.be.true;

expect(finalRes).to.deep.equal(res);
Expand Down Expand Up @@ -276,7 +276,7 @@ describe('PersonalizeMiddleware', () => {

validateDebugLog('skipped (%s)', 'preview');

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('__prerender_bypass')).to.be.true;
expect(getCookiesSpy.calledWith('__next_preview_data')).to.be.true;

Expand Down Expand Up @@ -307,7 +307,7 @@ describe('PersonalizeMiddleware', () => {

validateDebugLog('skipped (%s)', 'route excluded');

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

Expand Down Expand Up @@ -355,7 +355,7 @@ describe('PersonalizeMiddleware', () => {

validateDebugLog('skipped (personalize info not found)');

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

Expand Down Expand Up @@ -387,7 +387,7 @@ describe('PersonalizeMiddleware', () => {

validateDebugLog('skipped (no personalization configured)');

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

Expand All @@ -396,7 +396,7 @@ describe('PersonalizeMiddleware', () => {

it('browser id generation failed', async () => {
const req = createRequest({
cookieValues: { 'bid_cdp-client-key': undefined },
cookieValues: { 'BID_cdp-client-key': undefined },
});

const res = createResponse();
Expand All @@ -420,7 +420,7 @@ describe('PersonalizeMiddleware', () => {

validateDebugLog('skipped (browser id generation failed)');

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

Expand Down Expand Up @@ -451,7 +451,7 @@ describe('PersonalizeMiddleware', () => {

validateDebugLog('skipped (no variant identified)');

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

Expand Down Expand Up @@ -482,7 +482,7 @@ describe('PersonalizeMiddleware', () => {

validateDebugLog('skipped (invalid variant)');

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

Expand All @@ -494,7 +494,7 @@ describe('PersonalizeMiddleware', () => {
it('browser id is present in cookies', async () => {
const req = createRequest({
cookieValues: {
'bid_cdp-client-key': 'browser-id',
'BID_cdp-client-key': 'browser-id',
},
});

Expand Down Expand Up @@ -527,11 +527,11 @@ describe('PersonalizeMiddleware', () => {
},
});

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);

getCookiesSpy.restore();
nextRewriteStub.restore();
Expand All @@ -540,7 +540,7 @@ describe('PersonalizeMiddleware', () => {
it('browser id is not present in cookies', async () => {
const req = createRequest({
cookieValues: {
'bid_cdp-client-key': undefined,
'BID_cdp-client-key': undefined,
},
});

Expand Down Expand Up @@ -581,11 +581,11 @@ describe('PersonalizeMiddleware', () => {
},
});

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);

getCookiesSpy.restore();
nextRewriteStub.restore();
Expand Down Expand Up @@ -634,11 +634,11 @@ describe('PersonalizeMiddleware', () => {
},
});

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);

getCookiesSpy.restore();
nextRewriteStub.restore();
Expand Down Expand Up @@ -681,11 +681,11 @@ describe('PersonalizeMiddleware', () => {
},
});

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);

getCookiesSpy.restore();
nextRewriteStub.restore();
Expand Down Expand Up @@ -723,11 +723,11 @@ describe('PersonalizeMiddleware', () => {
},
});

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);

getCookiesSpy.restore();
nextRewriteStub.restore();
Expand Down Expand Up @@ -777,11 +777,11 @@ describe('PersonalizeMiddleware', () => {
},
});

expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;

expect(finalRes).to.deep.equal(res);

expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);

getCookiesSpy.restore();
nextRewriteStub.restore();
Expand Down Expand Up @@ -826,7 +826,7 @@ describe('PersonalizeMiddleware', () => {
it('should log error when generateBrowserId throws', async () => {
const error = new Error('CDP generateBrowserId fails');
const req = createRequest({
cookieValues: { 'bid_cdp-client-key': undefined },
cookieValues: { 'BID_cdp-client-key': undefined },
});

const generateBrowserIdWithError = sinon.stub().throws(error);
Expand Down
9 changes: 5 additions & 4 deletions packages/sitecore-jss/src/personalize/cdp-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { AxiosDataFetcher } from '../axios-fetcher';
use(spies);

describe('CdpService', () => {
const endpoint = 'http://sctest';
const domain = 'sctest.com';
const endpoint = `https://${domain}`;
const clientKey = 'client-key';
const contentId = 'content-id';
const variantId = 'variant-1';
Expand All @@ -29,7 +30,7 @@ describe('CdpService', () => {
} as ExperienceParams;

const config = {
endpoint,
domain,
clientKey,
pointOfSale,
};
Expand Down Expand Up @@ -127,7 +128,7 @@ describe('CdpService', () => {

expect(actualVariantId).to.deep.equal(variantId);
expect(fetcherSpy).to.be.called.once;
expect(fetcherSpy).to.be.called.with('http://sctest/v2/callFlows');
expect(fetcherSpy).to.be.called.with('https://sctest.com/v2/callFlows');
});

it('should use custom fetcher resolver and return undefined id when timeout is exceeded', async () => {
Expand Down Expand Up @@ -220,7 +221,7 @@ describe('CdpService', () => {
expect(actualRef).to.deep.equal(ref);
expect(fetcherSpy).to.be.called.once;
expect(fetcherSpy).to.be.called.with(
`http://sctest/v1.2/browser/create.json?client_key=${clientKey}&message={}`
`https://sctest.com/v1.2/browser/create.json?client_key=${clientKey}&message={}`
);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/sitecore-jss/src/personalize/cdp-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export type GenerateBrowserIdResult = {

export type CdpServiceConfig = {
/**
* Your Sitecore CDP API endpoint
* Your Sitecore CDP API domain
*/
endpoint: string;
domain: string;
/**
* The client key to use for authentication
*/
Expand Down Expand Up @@ -158,15 +158,15 @@ export class CdpService {
* @returns {string} formatted URL
*/
protected getGenerateBrowserIdUrl() {
return `${this.config.endpoint}/v1.2/browser/create.json?client_key=${this.config.clientKey}&message={}`;
return `https://${this.config.domain}/v1.2/browser/create.json?client_key=${this.config.clientKey}&message={}`;
}

/**
* Get formatted URL for executeExperience call
* @returns {string} formatted URL
*/
protected getExecuteExperienceUrl() {
return `${this.config.endpoint}/v2/callFlows`;
return `https://${this.config.domain}/v2/callFlows`;
}

/**
Expand Down

0 comments on commit 14147c6

Please sign in to comment.