Skip to content
Permalink
Browse files

Start to move sub status into /accounts/profile

  • Loading branch information...
lmorchard committed Apr 14, 2019
1 parent f186834 commit d0874e05f65137f415c48e54a3f5ae7104ac5070
@@ -180,7 +180,7 @@ function buildStubAPI(log, config) {
.filter(plan => plan.plan_id === plan_id)[0];

const storage = { subscriptions: {} };
const subscriptionsKey = (uid, sub_id) => `${uid }|${ sub_id}`;
const subscriptionsKey = (uid, sub_id) => `${uid}|${sub_id}`;

return {
isStubAPI: true,
@@ -10,6 +10,11 @@ const Client = require('../client')();

const config = require('../../config').getProperties();

const PRODUCT_ID = 'megaProductHooray';
const CLIENT_ID = 'client8675309';
const PLAN_ID = 'allDoneProMonthly';
const PAYMENT_TOKEN = 'pay8675309';

function makeMockOAuthHeader(opts) {
const token = Buffer.from(JSON.stringify(opts)).toString('hex');
return `Bearer ${ token}`;
@@ -21,6 +26,26 @@ describe('remote account profile', function() {
let server;
before(() => {
config.oauth.url = 'http://localhost:9010';
config.subhub.useStubs = true;
config.subhub.stubs = {
plans: [
{
plan_id: PLAN_ID,
product_id: PRODUCT_ID,
interval: 'month',
amount: 50,
currency: 'usd'
}
]
};
config.subscriptions = {
productCapabilities: {
[ PRODUCT_ID ]: [ '123donePro', '321donePro', 'FirefoxPlus', 'MechaMozilla' ],
},
clientCapabilities: {
[ CLIENT_ID ]: [ '123donePro', 'ILikePie', 'MechaMozilla', 'FooBar' ],
}
};
return TestServer.start(config)
.then(s => {
server = s;
@@ -284,6 +309,56 @@ describe('remote account profile', function() {
}
);

it('should report all subscription capabilities to session token client', async () => {
const email = server.uniqueEmail();
const client = await Client.create(
config.publicUrl,
email,
'password',
{ lang: 'en-US' }
);
const responseBefore = await client.api.subscriptionCapabilities(client.sessionToken);
assert.deepEqual(responseBefore, []);
await client.api.createSubscription(client.sessionToken, PLAN_ID, PAYMENT_TOKEN, email);
const responseAfter = await client.api.subscriptionCapabilities(client.sessionToken);
assert.deepEqual(responseAfter, [
'123donePro',
'321donePro',
'FirefoxPlus',
'MechaMozilla'
]);
});

it('should report subset of subscription capabilities to OAuth client', async () => {
const email = server.uniqueEmail();
const client = await Client.create(
config.publicUrl,
email,
'password',
{ lang: 'en-US' }
);
const responseBefore = await client.api.subscriptionCapabilities(null, {
Authorization: makeMockOAuthHeader({
user: client.uid,
client_id: CLIENT_ID,
scope: ['profile:email']
})
});
assert.deepEqual(responseBefore, []);
await client.api.createSubscription(client.sessionToken, PLAN_ID, PAYMENT_TOKEN, email);
const responseAfter = await client.api.subscriptionCapabilities(null, {
Authorization: makeMockOAuthHeader({
user: client.uid,
client_id: CLIENT_ID,
scope: ['profile:email']
})
});
assert.deepEqual(responseAfter, [
'123donePro',
'MechaMozilla'
]);
});

after(() => {
return TestServer.stop(server);
});

This file was deleted.

Oops, something went wrong.

0 comments on commit d0874e0

Please sign in to comment.
You can’t perform that action at this time.