Skip to content

Commit 30ee85b

Browse files
committed
originalurl header added for client async mode
1 parent e3c8a45 commit 30ee85b

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@puzzle-js/client-lib",
33
"main": "dist/index.js",
4-
"version": "1.4.3",
4+
"version": "1.4.4",
55
"author": "<[email protected]>",
66
"license": "MIT",
77
"repository": {

src/core.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export class Core extends Module {
144144
const queryString = this.prepareQueryString(fragment.attributes);
145145
const fragmentRequestUrl = `${fragment.source}${window.location.pathname}${queryString}`;
146146
return fetch(fragmentRequestUrl, {
147+
headers: {
148+
originalurl: window.location.pathname
149+
},
147150
credentials: 'include'
148151
})
149152
.then(res => {

test/core.spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {JSDOM} from "jsdom";
33
import {PuzzleJs} from "../src/puzzle";
44
import {Core} from "../src/core";
55
import {createPageLibConfiguration} from "./mock";
6-
import sinon from "sinon";
6+
import sinon, { SinonStub } from "sinon";
77
import {AssetHelper} from "../src/assetHelper";
88
import * as faker from "faker";
99
import {IPageLibAsset, IPageLibConfiguration, IPageLibDependency} from "../src/types";
@@ -22,17 +22,20 @@ declare global {
2222
export interface Global {
2323
document: Document;
2424
window: Window;
25+
fetch: any;
2526
}
2627

2728
declare var global: Global;
2829

2930
describe('Module - Core', () => {
3031
beforeEach(() => {
31-
global.window = (new JSDOM(``, {runScripts: "outside-only"})).window;
32+
global.window = (new JSDOM(``, { runScripts: "outside-only" })).window;
33+
global.fetch = sandbox.stub().resolves({json: () => {}});
3234
});
3335

3436
afterEach(() => {
3537
delete global.window;
38+
delete global.fetch;
3639
PuzzleJs.clearListeners();
3740
sandbox.verifyAndRestore();
3841
(Core as any)._pageConfiguration = undefined;
@@ -210,14 +213,15 @@ describe('Module - Core', () => {
210213
fragmentContainer.setAttribute('puzzle-fragment', 'test');
211214
global.window.document.body.appendChild(fragmentContainer);
212215

213-
const stubFetchGatewayFragment = sandbox.stub(Core as any, "fetchGatewayFragment").resolves();
216+
const fetchStub = global.fetch as SinonStub;
214217
const stubAsyncRenderResponse = sandbox.stub(Core as any, "asyncRenderResponse").resolves();
215218

216219
Core.config(JSON.stringify(config));
217220
await Core.renderAsyncFragment('test');
218221
await Core.renderAsyncFragment('test');
219-
220-
expect(stubFetchGatewayFragment.calledOnce).to.eq(true);
222+
223+
expect(fetchStub.calledOnce).to.eq(true);
224+
expect(fetchStub.getCall(0).lastArg.headers).to.haveOwnProperty("originalurl");
221225
expect(stubAsyncRenderResponse.calledOnce).to.eq(true);
222226
});
223227
});

0 commit comments

Comments
 (0)