-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate fullpage redirect to App Bridge CDN
- Loading branch information
1 parent
59c5f1b
commit a2db4cd
Showing
9 changed files
with
19 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
12.22.8 | ||
20.10.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,21 @@ | ||
const { assert } = require("chai"); | ||
|
||
suite('appBridgeRedirect', () => { | ||
const sandbox = sinon.createSandbox(); | ||
const url = '/settings'; | ||
const originalAppBridge = window['app-bridge']; | ||
|
||
setup(() => { | ||
window['app-bridge'] = { | ||
default() {}, | ||
actions: { | ||
Redirect: { | ||
Action: { | ||
REMOTE: 'REDIRECT::REMOTE', | ||
}, | ||
create() { | ||
return { | ||
dispatch() {}, | ||
}; | ||
}, | ||
}, | ||
}, | ||
}; | ||
document.body.dataset.apiKey = '123'; | ||
document.body.dataset.shopOrigin = 'myshop.com'; | ||
document.body.dataset.host = 'https://mock-host/admin'; | ||
}); | ||
|
||
teardown(() => { | ||
sandbox.restore(); | ||
window['app-bridge'] = originalAppBridge; | ||
}); | ||
|
||
|
||
test('calls App Bridge to create an app with the apiKey and shopOrigin from window', () => { | ||
var createApp = sinon.spy(); | ||
sinon.stub(window['app-bridge'], 'default').callsFake(createApp); | ||
|
||
appBridgeRedirect(url); | ||
|
||
sinon.assert.calledWith(createApp, { | ||
apiKey: '123', | ||
host: 'https://mock-host/admin', | ||
}); | ||
}); | ||
|
||
test('calls to dispatch a remote redirect App Bridge action with the url normalized to be relative to the window origin', () => { | ||
const AppBridge = window['app-bridge']; | ||
const Redirect = AppBridge.actions.Redirect; | ||
var mockApp = {}; | ||
var RedirectInstance = { | ||
dispatch: sinon.spy(), | ||
}; | ||
sinon.stub(AppBridge, 'default').callsFake(() => mockApp); | ||
sinon.stub(Redirect, 'create').callsFake(() => RedirectInstance); | ||
|
||
const normalizedUrl = `${window.location.origin}${url}`; | ||
test('calls App Bridge redirect to normalized url', () => { | ||
const open = sinon.spy(); | ||
sandbox.stub(window, 'open').callsFake(open); | ||
|
||
appBridgeRedirect(url); | ||
|
||
sinon.assert.calledWith(Redirect.create, mockApp); | ||
sinon.assert.calledWith( | ||
RedirectInstance.dispatch, | ||
'REDIRECT::REMOTE', | ||
normalizedUrl | ||
); | ||
assert(open.calledOnce); | ||
assert.match(open.lastCall.args[0], new RegExp(`${url}$`)); | ||
assert.equal(open.lastCall.args[1], '_top'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters