Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register classic setOnLoginRequest in basic runtime #1631

Merged
merged 4 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions src/runtime/basic-runtime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,33 +319,39 @@ describes.realWin('BasicRuntime', {}, (env) => {
await basicRuntime.setOnPaymentResponse(callback);
});

it('should delegate "setOnLoginRequest"', async () => {
const callback = function () {};
configuredClassicRuntimeMock
.expects('pageConfig')
.returns(pageConfig)
it('should delegate "setOnLoginRequest" to ConfiguredBasicRuntime', async () => {
configuredBasicRuntimeMock
.expects('setOnLoginRequest')
.withExactArgs()
.once();
const pageConfigMock = sandbox.mock(pageConfig);
pageConfigMock.expects('getPublicationId').returns('pub1').once();

const activities = configuredBasicRuntime.activities();
configuredClassicRuntimeMock
.expects('activities')
.returns(activities)
.once();
const activitiesMock = sandbox.mock(activities);
activitiesMock
.expects('open')
.withExactArgs(
'CHECK_ENTITLEMENTS',
'https://news.google.com/swg/_/ui/v1/checkentitlements?_=_',
'_blank',
{publicationId: 'pub1', _client: 'SwG $internalRuntimeVersion$'},
{width: 600, height: 600}
)
.once();
await basicRuntime.setOnLoginRequest();
});

it('should delegate "setOnLoginRequest" to ConfiguredClassicRuntime', async () => {
configuredClassicRuntimeMock.expects('setOnLoginRequest').once();

await basicRuntime.setOnLoginRequest();
});

await basicRuntime.setOnLoginRequest(callback);
it('should trigger login request', async () => {
configuredBasicRuntime.setOnLoginRequest();

const openStub = sandbox.stub(
configuredBasicRuntime.activities(),
'open'
);
await configuredBasicRuntime
.callbacks()
.triggerLoginRequest({linkRequested: true});

expect(openStub).to.be.calledOnceWithExactly(
'CHECK_ENTITLEMENTS',
'https://news.google.com/swg/_/ui/v1/checkentitlements?_=_',
'_blank',
{publicationId: 'pub1', _client: 'SwG $internalRuntimeVersion$'},
{'width': 600, 'height': 600}
);
});

it('should delegate "setupAndShowAutoPrompt"', async () => {
Expand Down
20 changes: 10 additions & 10 deletions src/runtime/basic-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export class BasicRuntime {
autoPromptType: params.autoPromptType,
alwaysShow: false,
});
this.setOnLoginRequest();
}
/* eslint-enable no-unused-vars */

Expand All @@ -216,9 +217,9 @@ export class BasicRuntime {
}

/** @override */
setOnLoginRequest(callback) {
setOnLoginRequest() {
return this.configured_(false).then((runtime) =>
runtime.setOnLoginRequest(callback)
runtime.setOnLoginRequest()
);
}

Expand Down Expand Up @@ -394,21 +395,20 @@ export class ConfiguredBasicRuntime {
}

/** @override */
setOnLoginRequest(unusedCallback) {
const runtime = this.configuredClassicRuntime_;
const args = feArgs({
'publicationId': runtime.pageConfig().getPublicationId(),
});
setOnLoginRequest() {
this.configuredClassicRuntime_.setOnLoginRequest(() => {
const args = feArgs({
ChrisAntaki marked this conversation as resolved.
Show resolved Hide resolved
'publicationId': this.pageConfig().getPublicationId(),
});

runtime
.activities()
.open(
this.activities().open(
CHECK_ENTITLEMENTS_REQUEST_ID,
feUrl('/checkentitlements'),
'_blank',
args,
{'width': 600, 'height': 600}
);
});
}

/** @override */
Expand Down