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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰Subscriptions: fixing entitlement shape for swg #15560

Merged
merged 1 commit into from May 24, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,7 +20,7 @@ import {
SubscribeResponse,
} from '../../../third_party/subscriptions-project/swg';
import {DocImpl} from '../../amp-subscriptions/0.1/doc-impl';
import {Entitlement} from '../../amp-subscriptions/0.1/entitlement';
import {Entitlement, GrantReason} from '../../amp-subscriptions/0.1/entitlement';
import {PageConfig} from '../../../third_party/subscriptions-project/config';
import {Services} from '../../../src/services';
import {parseUrlDeprecated} from '../../../src/url';
Expand Down Expand Up @@ -160,8 +160,9 @@ export class GoogleSubscriptionsPlatform {
source: swgEntitlement.source,
raw: swgEntitlements.raw,
service: PLATFORM_ID,
products: swgEntitlement.products,
subscriptionToken: swgEntitlement.subscriptionToken,
granted: true, //swgEntitlements.getEntitlementForThis makes sure this is true.
grantReason: GrantReason.SUBSCRIBER, // there is no other case of subscription for SWG as of now.
dataObject: swgEntitlement.json(),
});
});
}
Expand Down
Expand Up @@ -331,4 +331,48 @@ describes.realWin('amp-subscriptions-google', {amp: true}, env => {
platform.executeAction('subscribe');
expect(executeStub).to.be.calledWith({list: 'amp', isClosable: true});
});

describe('getEntitlements', () => {
it('should convert granted entitlements to internal shape', () => {
const entitlementResponse = {
source: 'google',
products: ['example.org:basic'],
subscriptionToken: 'tok1',
};
sandbox.stub(xhr, 'fetchJson').callsFake(() => {
return Promise.resolve({
json: () => {
return Promise.resolve({
entitlements: entitlementResponse,
});
},
});
});
return platform.getEntitlements().then(entitlement => {
expect(entitlement.source).to.be.equal('google');
expect(entitlement.granted).to.be.equal(true);
expect(entitlement.grantReason).to.be.equal(GrantReason.SUBSCRIBER);
expect(entitlement.data).to.deep.equal(entitlementResponse);
});
});

it('should convert non granted entitlements to null', () => {
sandbox.stub(xhr, 'fetchJson').callsFake(() => {
return Promise.resolve({
json: () => {
return Promise.resolve({
entitlements: {
source: 'google',
products: ['example.org:premium'],
subscriptionToken: '',
},
});
},
});
});
return platform.getEntitlements().then(entitlement => {
expect(entitlement).to.be.equal(null);
});
});
});
});