mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 10:53:34 +03:00
d15446593a
no-issue We are in the process of creating migrations to add foreign key constraints and cascading deletes to the members_stripe_* tables to make listing members and deleting members faster. As well as the migrations we need to update the database schema so that new installations have the correct indexes and constraints. Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
const should = require('should');
|
|
const {Member} = require('../../../core/server/models/member');
|
|
const {MemberStripeCustomer} = require('../../../core/server/models/member-stripe-customer');
|
|
const {StripeCustomerSubscription} = require('../../../core/server/models/stripe-customer-subscription');
|
|
|
|
const testUtils = require('../../utils');
|
|
|
|
describe('StripeCustomerSubscription Model', function run() {
|
|
before(testUtils.teardownDb);
|
|
beforeEach(testUtils.setup('roles'));
|
|
afterEach(testUtils.teardownDb);
|
|
|
|
describe('customer', function () {
|
|
it('Is correctly mapped to the stripe customer', async function () {
|
|
const context = testUtils.context.admin;
|
|
const member = await Member.add({
|
|
email: 'test@test.member'
|
|
}, context);
|
|
await MemberStripeCustomer.add({
|
|
member_id: member.get('id'),
|
|
customer_id: 'fake_customer_id'
|
|
}, context);
|
|
|
|
await StripeCustomerSubscription.add({
|
|
customer_id: 'fake_customer_id',
|
|
subscription_id: 'fake_subscription_id',
|
|
plan_id: 'fake_plan_id',
|
|
plan_amount: 1337,
|
|
plan_nickname: 'e-LEET',
|
|
plan_interval: 'year',
|
|
plan_currency: 'btc',
|
|
status: 'active',
|
|
start_date: new Date(),
|
|
current_period_end: new Date(),
|
|
cancel_at_period_end: false
|
|
}, context);
|
|
|
|
const subscription = await StripeCustomerSubscription.findOne({
|
|
subscription_id: 'fake_subscription_id'
|
|
}, Object.assign({}, context, {
|
|
withRelated: ['customer']
|
|
}));
|
|
|
|
const customer = subscription.related('customer');
|
|
|
|
should.exist(customer, 'StripeCustomerSubscription should have been fetched with customer');
|
|
|
|
should.equal(customer.get('customer_id'), 'fake_customer_id');
|
|
});
|
|
});
|
|
});
|