|
8 | 8 | getMetadata, |
9 | 9 | getPreviewUrl, |
10 | 10 | getAemUrlVars, |
| 11 | + aemToContentUrl, |
11 | 12 | getItemDetails, |
12 | 13 | getItems, |
13 | 14 | getPreviewStatus, |
@@ -118,6 +119,35 @@ describe('da-library/helpers exports', () => { |
118 | 119 | }); |
119 | 120 | }); |
120 | 121 |
|
| 122 | + describe('aemToContentUrl', () => { |
| 123 | + it('Rewrites aem.page preview URLs to content.da.live', () => { |
| 124 | + expect(aemToContentUrl('https://main--site--org.aem.page/blocks/cards')) |
| 125 | + .to.equal('https://content.da.live/org/site/blocks/cards'); |
| 126 | + }); |
| 127 | + |
| 128 | + it('Rewrites aem.live, hlx.page and hlx.live URLs the same way', () => { |
| 129 | + expect(aemToContentUrl('https://main--site--org.aem.live/blocks/cards')) |
| 130 | + .to.equal('https://content.da.live/org/site/blocks/cards'); |
| 131 | + expect(aemToContentUrl('https://main--site--org.hlx.page/blocks/cards')) |
| 132 | + .to.equal('https://content.da.live/org/site/blocks/cards'); |
| 133 | + expect(aemToContentUrl('https://feature--site--org.hlx.live/deep/nested/path')) |
| 134 | + .to.equal('https://content.da.live/org/site/deep/nested/path'); |
| 135 | + }); |
| 136 | + |
| 137 | + it('Leaves content.da.live and admin.da.live URLs unchanged', () => { |
| 138 | + const con = 'https://content.da.live/org/site/blocks/cards'; |
| 139 | + expect(aemToContentUrl(con)).to.equal(con); |
| 140 | + const admin = 'https://admin.da.live/source/org/site/blocks/cards'; |
| 141 | + expect(aemToContentUrl(admin)).to.equal(admin); |
| 142 | + }); |
| 143 | + |
| 144 | + it('Leaves unrelated origins, relative paths and non-URL strings unchanged', () => { |
| 145 | + expect(aemToContentUrl('https://example.com/blocks/cards')).to.equal('https://example.com/blocks/cards'); |
| 146 | + expect(aemToContentUrl('/blocks/cards.json')).to.equal('/blocks/cards.json'); |
| 147 | + expect(aemToContentUrl('not a url')).to.equal('not a url'); |
| 148 | + }); |
| 149 | + }); |
| 150 | + |
121 | 151 | describe('getItemDetails', () => { |
122 | 152 | it('Parses an aem.live URL', () => { |
123 | 153 | const result = getItemDetails({ path: 'https://main--repo--org.aem.live/folder/page' }); |
@@ -236,6 +266,19 @@ describe('da-library/helpers/index getBlocks', () => { |
236 | 266 | expect(result).to.deep.equal([]); |
237 | 267 | }); |
238 | 268 |
|
| 269 | + it('Rewrites an AEM source URL to content.da.live before fetching', async () => { |
| 270 | + let captured; |
| 271 | + window.fetch = (url) => { |
| 272 | + captured = url; |
| 273 | + return Promise.resolve(new Response( |
| 274 | + JSON.stringify({ ':type': 'sheet', data: [] }), |
| 275 | + { status: 200 }, |
| 276 | + )); |
| 277 | + }; |
| 278 | + await getBlocks(['https://main--repo--org.aem.page/blocks.json']); |
| 279 | + expect(captured).to.equal('https://content.da.live/org/repo/blocks.json'); |
| 280 | + }); |
| 281 | + |
239 | 282 | it('Caches fetched source data so subsequent calls do not refetch', async () => { |
240 | 283 | let calls = 0; |
241 | 284 | window.fetch = () => { |
|
0 commit comments