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

FPA M0.5 Adds contentType to article query param. #3540

Merged
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
77 changes: 74 additions & 3 deletions src/runtime/entitlements-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ describes.realWin('EntitlementsManager', (env) => {
fetcherMock
.expects('fetch')
.withExactArgs(
`https://news.google.com/swg/_/api/v1/publication/pub1/article?locked=true&encodedEntitlementsParams=${encodedParams}`,
`https://news.google.com/swg/_/api/v1/publication/pub1/article?locked=true&contentType=CLOSED&encodedEntitlementsParams=${encodedParams}`,
{
method: 'GET',
headers: {'Accept': 'text/plain, application/json'},
Expand Down Expand Up @@ -1771,6 +1771,77 @@ describes.realWin('EntitlementsManager', (env) => {
);
});

it('should pass OPEN contentType for unlocked content to the article endpoint', async () => {
pageConfig = new PageConfig('pub1:label1', false);
manager = new EntitlementsManager(
win,
pageConfig,
fetcher,
deps,
/* useArticleEndpoint */ true
);
jwtHelperMock = sandbox.mock(manager.jwtHelper_);
jwtHelperMock
.expects('decode')
.withExactArgs('SIGNED_DATA')
.returns({
entitlements: {
products: ['pub1:label1'],
subscriptionToken: 'token1',
source: 'google:metering',
},
});
const testSubscriptionTokenContents = {
metering: {
ownerId: 'scenic-2017.appspot.com',
action: 'READ',
clientUserAttribute: 'standard_registered_user',
},
};
jwtHelperMock
.expects('decode')
.withExactArgs('token1')
.returns(testSubscriptionTokenContents);
const article = {
entitlements: {
signedEntitlements: 'SIGNED_DATA',
},
clientConfig: {
id: 'foo',
},
};
const encodedParams = base64UrlEncodeFromBytes(
utf8EncodeSync(
`{"metering":{"clientTypes":[1],"owner":"pub1","resource":{"hashedCanonicalUrl":"${HASHED_CANONICAL_URL}"},"state":{"id":"u1","attributes":[]},"token":"token"}}`
)
);
fetcherMock
.expects('fetch')
.withExactArgs(
`https://news.google.com/swg/_/api/v1/publication/pub1/article?locked=false&contentType=OPEN&encodedEntitlementsParams=${encodedParams}`,
{
method: 'GET',
headers: {'Accept': 'text/plain, application/json'},
credentials: 'include',
}
)
.returns(
Promise.resolve({
text: () => Promise.resolve(JSON.stringify(article)),
})
);
expectGetSwgUserTokenToBeCalled();

await manager.getEntitlements({
metering: {
state: {
id: 'u1',
},
},
});
await manager.getArticle();
});

it('should use the article endpoint with preview config id param', async () => {
manager = new EntitlementsManager(
win,
Expand All @@ -1796,7 +1867,7 @@ describes.realWin('EntitlementsManager', (env) => {
fetcherMock
.expects('fetch')
.withExactArgs(
`https://news.google.com/swg/_/api/v1/publication/pub1/article?previewConfigId=${configId}&locked=true&encodedEntitlementsParams=${encodedParams}`,
`https://news.google.com/swg/_/api/v1/publication/pub1/article?previewConfigId=${configId}&locked=true&contentType=CLOSED&encodedEntitlementsParams=${encodedParams}`,
{
method: 'GET',
headers: {'Accept': 'text/plain, application/json'},
Expand Down Expand Up @@ -1851,7 +1922,7 @@ describes.realWin('EntitlementsManager', (env) => {
fetcherMock
.expects('fetch')
.withExactArgs(
`https://news.google.com/swg/_/api/v1/publication/pub1/article?previewConfigId=${configId}&previewKey=${previewKey}&locked=true&encodedEntitlementsParams=${encodedParams}`,
`https://news.google.com/swg/_/api/v1/publication/pub1/article?previewConfigId=${configId}&previewKey=${previewKey}&locked=true&contentType=CLOSED&encodedEntitlementsParams=${encodedParams}`,
{
method: 'GET',
headers: {'Accept': 'text/plain, application/json'},
Expand Down
12 changes: 12 additions & 0 deletions src/runtime/entitlements-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,11 @@ export class EntitlementsManager {
// Add locked param.
if (this.useArticleEndpoint_) {
url = addQueryParam(url, 'locked', String(this.pageConfig_.isLocked()));
url = addQueryParam(
url,
'contentType',
getContentTypeParam(this.pageConfig_.isLocked())
);
}
const hashedCanonicalUrl = await this.getHashedCanonicalUrl_();

Expand Down Expand Up @@ -1020,3 +1025,10 @@ function irtpStringToBoolean(value: string | null): boolean | undefined {
return undefined;
}
}

/**
* Returns ContentType Enum string from isLocked page config status.
*/
function getContentTypeParam(isLocked: boolean) {
return isLocked ? 'CLOSED' : 'OPEN';
}
Loading