Skip to content

Commit

Permalink
Ensure site and variant prefixes are position agnostic (#1286)
Browse files Browse the repository at this point in the history
* personalize rewrite unit tests

(cherry picked from commit 3c412ed6855d60452e1e29d21a92d1901312d3d4)

* site path utils unit tests, tweak to personalize path unit test
  • Loading branch information
art-alexeyenko authored Jan 12, 2023
1 parent 2a6e7bf commit fd498ae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/sitecore-jss/src/personalize/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ describe('utils', () => {
const result = getPersonalizedRewriteData(pathname);
expect(result.variantId).to.equal('');
});
it('should return varinat id from any position in pathname', () => {
const testId = '0451';
const path1 = `/${VARIANT_PREFIX}${testId}/some/path/`;
const path2 = `/_site_mysite/${VARIANT_PREFIX}${testId}/some/path/`;

expect(getPersonalizedRewriteData(path1)).to.deep.equal(getPersonalizedRewriteData(path2));
});
});

describe('normalizePersonalizedRewrite', () => {
Expand All @@ -78,6 +85,13 @@ describe('utils', () => {
const result = normalizePersonalizedRewrite(pathname);
expect(result).to.equal('/');
});
it('should normalize path with other prefixes present', () => {
const pathname = `/_site_mysite/${VARIANT_PREFIX}foo`;
const pathNameInversed = `/${VARIANT_PREFIX}foo/_site_mysite/`;
const result = normalizePersonalizedRewrite(pathname);
expect(result).to.equal('/_site_mysite/');
expect(normalizePersonalizedRewrite(pathNameInversed)).to.equal(result);
});
});

describe('CdpHelper', () => {
Expand Down
17 changes: 17 additions & 0 deletions packages/sitecore-jss/src/site/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ describe('utils', () => {
const result = getSiteRewriteData(pathname, defaultSiteName);
expect(result.siteName).to.equal(defaultSiteName);
});

it('should return site name from anywhere in the path', () => {
const siteName = 'fiftyone';
const path1 = `/${SITE_PREFIX}${siteName}/some/path/`;
const path2 = `/_variantId_0451/${SITE_PREFIX}${siteName}/some/path/`;

expect(getSiteRewriteData(path1, defaultSiteName)).to.deep.equal(getSiteRewriteData(path2, defaultSiteName));
});
});

describe('normalizeSiteRewrite', () => {
Expand Down Expand Up @@ -84,5 +92,14 @@ describe('utils', () => {
const result = normalizeSiteRewrite(pathname);
expect(result).to.equal('/');
});

it('should normalize path with other prefixes present', () => {
const pathnameWithPrefix = `/_variantId_0451/${SITE_PREFIX}foo`;
const pathnameWithPostfix = `/${SITE_PREFIX}foo/_variantId_0451/`;
const resultPrefix = normalizeSiteRewrite(pathnameWithPrefix);
const resultPostfix = normalizeSiteRewrite(pathnameWithPostfix);
expect(resultPrefix).to.equal('/_variantId_0451/');
expect(resultPrefix).to.equal(resultPostfix);
});
});
});

0 comments on commit fd498ae

Please sign in to comment.