Skip to content

Commit

Permalink
MWPW-167828 Rewrite prod links with stage on non-prod env
Browse files Browse the repository at this point in the history
  • Loading branch information
dejanpreradovic committed Feb 19, 2025
1 parent f72b9f2 commit 90e5782
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
7 changes: 6 additions & 1 deletion eds/scripts/rewriteLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { getConfig } from '../blocks/utils/utils.js';
* Domain configs where the key is the production domain,
* and the value is config object for it.
*/
const domainConfigs = { 'partners.adobe.com': { stage: { domain: 'partners.stage.adobe.com' } } };
const domainConfigs = {
'partners.adobe.com': { stage: { domain: 'partners.stage.adobe.com' } },
'solutionpartners.adobe.com': { stage: { domain: 'solutionpartners.stage2.adobe.com' } },
'exchange.adobe.com': { stage: { domain: 'stage.exchange.adobe.com' } },
'cbconnection.adobe.com': { stage: { domain: 'cbconnection-stage.adobe.com' } },
};

/**
* Rewrite a link href domain based on production to stage domain mappings.
Expand Down
30 changes: 25 additions & 5 deletions test/scripts/rewriteLinks.jest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { getUpdatedHref, rewriteLinks } from '../../eds/scripts/rewriteLinks.js';
import { rewriteLinks } from '../../eds/scripts/rewriteLinks.js';
import { getConfig } from '../../eds/blocks/utils/utils.js';
import { partnerIsSignedIn } from '../../eds/scripts/utils.js';

Expand All @@ -10,7 +10,12 @@ jest.mock('../../eds/scripts/utils.js', () => ({ partnerIsSignedIn: jest.fn(() =

// Mock DOM
document.body.innerHTML = `
<a href="https://partners.adobe.com">Partner prod Link</a>
<div>
<a href="https://partners.adobe.com">Partner prod Link</a>
<a id="spp-link" href="https://solutionpartners.adobe.com/solution-partners/contact.html">SPP prod Link</a>
<a id="exchange-link" href="https://exchange.adobe.com/">Adobe Exchange prod Link</a>
<a id="cbc-link" href="https://cbconnection.adobe.com/en/apc-helpdesk">CBC prod Link</a>
</div>
`;

describe('Test rewrite links', () => {
Expand All @@ -29,9 +34,6 @@ describe('Test rewrite links', () => {
});
afterEach(() => {
jest.clearAllMocks(); // Clear mocks after each test
document.body.innerHTML = `
<a href="https://partners.adobe.com">Partner prod Link</a>
`;
});

test('should update partners prod link when on non prod', () => {
Expand All @@ -50,4 +52,22 @@ describe('Test rewrite links', () => {
expect(links[0].href).toBe('https://partners.stage.adobe.com/');
},
);

test('should update SPP prod link when on non prod', () => {
rewriteLinks(document);
const link = document.querySelector('#spp-link');
expect(link.href).toBe('https://solutionpartners.stage2.adobe.com/solution-partners/contact.html');
});

test('should update Adobe Exchange prod link when on non prod', () => {
rewriteLinks(document);
const link = document.querySelector('#exchange-link');
expect(link.href).toBe('https://stage.exchange.adobe.com/');
});

test('should update CBC prod link when on non prod', () => {
rewriteLinks(document);
const link = document.querySelector('#cbc-link');
expect(link.href).toBe('https://cbconnection-stage.adobe.com/en/apc-helpdesk');
});
});

0 comments on commit 90e5782

Please sign in to comment.