Merge branch 'develop' into iap-fix

This commit is contained in:
Matteo Pagliazzi
2016-07-04 15:45:56 +02:00
311 changed files with 37611 additions and 4751 deletions
@@ -52,7 +52,7 @@ describe('PUT /heroes/:heroId', () => {
// test response
expect(heroRes).to.have.all.keys([ // works as: object has all and only these keys
'_id', 'balance', 'profile', 'purchased',
'contributor', 'auth', 'items',
'contributor', 'auth', 'items', 'flags',
]);
expect(heroRes.auth.local).not.to.have.keys(['salt', 'hashed_password']);
expect(heroRes.profile).to.have.all.keys(['name']);
@@ -72,6 +72,18 @@ describe('PUT /heroes/:heroId', () => {
expect(hero.notifications[0].type).to.equal('NEW_CONTRIBUTOR_LEVEL');
});
it('updates chatRevoked flag', async () => {
let hero = await generateUser();
await user.put(`/hall/heroes/${hero._id}`, {
flags: {chatRevoked: true},
});
await hero.sync();
expect(hero.flags.chatRevoked).to.eql(true);
});
it('updates contributor level', async () => {
let hero = await generateUser({
contributor: {level: 5},
@@ -83,7 +95,7 @@ describe('PUT /heroes/:heroId', () => {
// test response
expect(heroRes).to.have.all.keys([ // works as: object has all and only these keys
'_id', 'balance', 'profile', 'purchased',
'contributor', 'auth', 'items',
'contributor', 'auth', 'items', 'flags',
]);
expect(heroRes.auth.local).not.to.have.keys(['salt', 'hashed_password']);
expect(heroRes.profile).to.have.all.keys(['name']);
@@ -110,7 +122,7 @@ describe('PUT /heroes/:heroId', () => {
// test response
expect(heroRes).to.have.all.keys([ // works as: object has all and only these keys
'_id', 'balance', 'profile', 'purchased',
'contributor', 'auth', 'items',
'contributor', 'auth', 'items', 'flags',
]);
expect(heroRes.auth.local).not.to.have.keys(['salt', 'hashed_password']);
expect(heroRes.profile).to.have.all.keys(['name']);
@@ -134,7 +146,7 @@ describe('PUT /heroes/:heroId', () => {
// test response
expect(heroRes).to.have.all.keys([ // works as: object has all and only these keys
'_id', 'balance', 'profile', 'purchased',
'contributor', 'auth', 'items',
'contributor', 'auth', 'items', 'flags',
]);
expect(heroRes.auth.local).not.to.have.keys(['salt', 'hashed_password']);
expect(heroRes.profile).to.have.all.keys(['name']);
@@ -1,18 +0,0 @@
import {
generateUser,
} from '../../../../../helpers/api-integration/v3';
import moment from 'moment';
describe('POST /user/auth/firebase', () => {
let user;
before(async () => {
user = await generateUser();
});
it('returns a Firebase token', async () => {
let {token, expires} = await user.post('/user/auth/firebase');
expect(moment(expires).isValid()).to.be.true;
expect(token).to.be.a('string');
});
});
@@ -0,0 +1,102 @@
/* eslint-disable camelcase */
import {
generateUser,
requester,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /user/auth/pusher', () => {
let user;
let endpoint = '/user/auth/pusher';
beforeEach(async () => {
user = await generateUser();
});
it('requires authentication', async () => {
let api = requester();
await expect(api.post(endpoint)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('missingAuthHeaders'),
});
});
it('returns an error if req.body.socket_id is missing', async () => {
await expect(user.post(endpoint, {
channel_name: '123',
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('invalidReqParams'),
});
});
it('returns an error if req.body.channel_name is missing', async () => {
await expect(user.post(endpoint, {
socket_id: '123',
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('invalidReqParams'),
});
});
it('returns an error if req.body.channel_name is badly formatted', async () => {
await expect(user.post(endpoint, {
channel_name: '123',
socket_id: '123',
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: 'Invalid Pusher channel type.',
});
});
it('returns an error if an invalid channel type is passed', async () => {
await expect(user.post(endpoint, {
channel_name: 'invalid-group-123',
socket_id: '123',
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: 'Invalid Pusher channel type.',
});
});
it('returns an error if an invalid resource type is passed', async () => {
await expect(user.post(endpoint, {
channel_name: 'presence-user-123',
socket_id: '123',
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: 'Invalid Pusher resource type.',
});
});
it('returns an error if an invalid resource id is passed', async () => {
await expect(user.post(endpoint, {
channel_name: 'presence-group-123',
socket_id: '123',
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: 'Invalid Pusher resource id, must be a UUID.',
});
});
it('returns an error if the passed resource id doesn\'t match the user\'s party', async () => {
await expect(user.post(endpoint, {
channel_name: `presence-group-${generateUUID()}`,
socket_id: '123',
})).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: 'Resource id must be the user\'s party.',
});
});
});
+22 -23
View File
@@ -4,13 +4,18 @@ import { model as User } from '../../../../../website/server/models/user';
import moment from 'moment';
describe('payments/index', () => {
let user;
beforeEach(() => {
user = new User();
sandbox.spy(sender, 'sendTxn');
});
afterEach(() => {
sandbox.restore();
});
describe('#createSubscription', () => {
let user;
beforeEach(async () => {
user = new User();
});
context('Purchasing a subscription as a gift', () => {
it('adds extra months to an existing subscription');
@@ -146,20 +151,14 @@ describe('payments/index', () => {
});
describe('#cancelSubscription', () => {
let data, user;
let data;
beforeEach(() => {
sandbox.spy(sender, 'sendTxn');
user = new User();
data = { user };
});
afterEach(() => {
sandbox.restore();
});
it('adds a month termination date by default', () => {
api.cancelSubscription(data);
it('adds a month termination date by default', async () => {
await api.cancelSubscription(data);
let now = new Date();
let daysTillTermination = moment(user.purchased.plan.dateTerminated).diff(now, 'days');
@@ -167,10 +166,10 @@ describe('payments/index', () => {
expect(daysTillTermination).to.be.within(29, 30); // 1 month +/- 1 days
});
it('adds extraMonths to dateTerminated value', () => {
it('adds extraMonths to dateTerminated value', async () => {
user.purchased.plan.extraMonths = 2;
api.cancelSubscription(data);
await api.cancelSubscription(data);
let now = new Date();
let daysTillTermination = moment(user.purchased.plan.dateTerminated).diff(now, 'days');
@@ -178,10 +177,10 @@ describe('payments/index', () => {
expect(daysTillTermination).to.be.within(89, 90); // 3 months +/- 1 days
});
it('handles extra month fractions', () => {
it('handles extra month fractions', async () => {
user.purchased.plan.extraMonths = 0.3;
api.cancelSubscription(data);
await api.cancelSubscription(data);
let now = new Date();
let daysTillTermination = moment(user.purchased.plan.dateTerminated).diff(now, 'days');
@@ -189,10 +188,10 @@ describe('payments/index', () => {
expect(daysTillTermination).to.be.within(38, 39); // should be about 1 month + 1/3 month
});
it('terminates at next billing date if it exists', () => {
it('terminates at next billing date if it exists', async () => {
data.nextBill = moment().add({ days: 15 });
api.cancelSubscription(data);
await api.cancelSubscription(data);
let now = new Date();
let daysTillTermination = moment(user.purchased.plan.dateTerminated).diff(now, 'days');
@@ -200,10 +199,10 @@ describe('payments/index', () => {
expect(daysTillTermination).to.be.within(13, 15);
});
it('resets plan.extraMonths', () => {
it('resets plan.extraMonths', async () => {
user.purchased.plan.extraMonths = 5;
api.cancelSubscription(data);
await api.cancelSubscription(data);
expect(user.purchased.plan.extraMonths).to.eql(0);
});