mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 13:47:33 +01:00
Add field to track when current subscription type started
This commit is contained in:
committed by
Phillip Thelen
parent
f9a9d4919b
commit
8dfa21a4b8
@@ -13,7 +13,7 @@ import {
|
||||
import * as worldState from '../../../../../website/server/libs/worldState';
|
||||
import { TransactionModel } from '../../../../../website/server/models/transaction';
|
||||
|
||||
describe('payments/index', () => {
|
||||
describe.only('payments/index', () => {
|
||||
let user;
|
||||
let group;
|
||||
let data;
|
||||
@@ -203,6 +203,28 @@ describe('payments/index', () => {
|
||||
expect(recipient.purchased.plan.dateCreated).to.exist;
|
||||
});
|
||||
|
||||
it('sets plan.dateCurrentTypeCreated if it did not previously exist', async () => {
|
||||
expect(recipient.purchased.plan.dateCurrentTypeCreated).to.not.exist;
|
||||
|
||||
await api.createSubscription(data);
|
||||
|
||||
expect(recipient.purchased.plan.dateCurrentTypeCreated).to.exist;
|
||||
});
|
||||
|
||||
it('keeps plan.dateCreated when changing subscription type', async () => {
|
||||
await api.createSubscription(data);
|
||||
const initialDate = recipient.purchased.plan.dateCreated
|
||||
await api.createSubscription(data);
|
||||
expect(recipient.purchased.plan.dateCreated).to.eql(initialDate);
|
||||
});
|
||||
|
||||
it('sets plan.dateCurrentTypeCreated when changing subscription type', async () => {
|
||||
await api.createSubscription(data);
|
||||
const initialDate = recipient.purchased.plan.dateCurrentTypeCreated
|
||||
await api.createSubscription(data);
|
||||
expect(recipient.purchased.plan.dateCurrentTypeCreated).to.not.eql(initialDate);
|
||||
});
|
||||
|
||||
it('does not change plan.customerId if it already exists', async () => {
|
||||
recipient.purchased.plan = plan;
|
||||
data.customerId = 'purchaserCustomerId';
|
||||
@@ -386,6 +408,36 @@ describe('payments/index', () => {
|
||||
expect(user.purchased.plan.dateCreated).to.exist;
|
||||
});
|
||||
|
||||
it('sets plan.dateCreated if it did not previously exist', async () => {
|
||||
expect(user.purchased.plan.dateCreated).to.not.exist;
|
||||
|
||||
await api.createSubscription(data);
|
||||
|
||||
expect(user.purchased.plan.dateCreated).to.exist;
|
||||
});
|
||||
|
||||
it('sets plan.dateCurrentTypeCreated if it did not previously exist', async () => {
|
||||
expect(user.purchased.plan.dateCurrentTypeCreated).to.not.exist;
|
||||
|
||||
await api.createSubscription(data);
|
||||
|
||||
expect(user.purchased.plan.dateCurrentTypeCreated).to.exist;
|
||||
});
|
||||
|
||||
it('keeps plan.dateCreated when changing subscription type', async () => {
|
||||
await api.createSubscription(data);
|
||||
const initialDate = user.purchased.plan.dateCreated
|
||||
await api.createSubscription(data);
|
||||
expect(user.purchased.plan.dateCreated).to.eql(initialDate);
|
||||
});
|
||||
|
||||
it('sets plan.dateCurrentTypeCreated when changing subscription type', async () => {
|
||||
await api.createSubscription(data);
|
||||
const initialDate = user.purchased.plan.dateCurrentTypeCreated
|
||||
await api.createSubscription(data);
|
||||
expect(user.purchased.plan.dateCurrentTypeCreated).to.not.eql(initialDate);
|
||||
});
|
||||
|
||||
it('awards the Royal Purple Jackalope pet', async () => {
|
||||
await api.createSubscription(data);
|
||||
|
||||
|
||||
@@ -144,6 +144,7 @@ async function prepareSubscriptionValues (data) {
|
||||
plan.dateTerminated = moment().add({ months }).toDate();
|
||||
plan.dateCreated = today;
|
||||
}
|
||||
plan.dateCurrentTypeCreated = today;
|
||||
}
|
||||
|
||||
if (!plan.customerId) {
|
||||
@@ -160,6 +161,7 @@ async function prepareSubscriptionValues (data) {
|
||||
planId: block.key,
|
||||
customerId: data.customerId,
|
||||
dateUpdated: today,
|
||||
dateCurrentTypeCreated: today,
|
||||
paymentMethod: data.paymentMethod,
|
||||
extraMonths: Number(plan.extraMonths) + _dateDiff(today, plan.dateTerminated),
|
||||
dateTerminated: null,
|
||||
|
||||
@@ -13,6 +13,7 @@ export const schema = new mongoose.Schema({
|
||||
dateCreated: Date,
|
||||
dateTerminated: Date,
|
||||
dateUpdated: Date,
|
||||
dateCurrentTypeCreated: Date,
|
||||
extraMonths: { $type: Number, default: 0 },
|
||||
gemsBought: { $type: Number, default: 0 },
|
||||
mysteryItems: { $type: Array, default: () => [] },
|
||||
|
||||
Reference in New Issue
Block a user