mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 05:14:12 +03:00
f08a55c21f
refs: https://github.com/TryGhost/Team/issues/856 refs: https://github.com/TryGhost/Team/issues/756 - The .test.js extension is better than _spec.js as it's more obvious that it's an extension - It also meaans we can use the --extension parameter in mocha, which should result in a better default behaviour for `yarn test` - It also highlights that some of our tests were named incorrectly and were not (and still will not be) run (see https://github.com/TryGhost/Team/issues/856) - Note: even with this change, `yarn test` is throwing errors, I believe because of this issue https://github.com/TryGhost/Team/issues/756
77 lines
2.9 KiB
JavaScript
77 lines
2.9 KiB
JavaScript
const should = require('should');
|
|
const {Member} = require('../../../core/server/models/member');
|
|
const {MemberStripeCustomer} = require('../../../core/server/models/member-stripe-customer');
|
|
const {Product} = require('../../../core/server/models/product');
|
|
const {StripeCustomerSubscription} = require('../../../core/server/models/stripe-customer-subscription');
|
|
const {StripePrice} = require('../../../core/server/models/stripe-price');
|
|
const {StripeProduct} = require('../../../core/server/models/stripe-product');
|
|
|
|
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);
|
|
|
|
const product = await Product.add({
|
|
name: 'Ghost Product',
|
|
slug: 'ghost-product'
|
|
}, context);
|
|
|
|
await StripeProduct.add({
|
|
product_id: product.get('id'),
|
|
stripe_product_id: 'fake_product_id'
|
|
}, context);
|
|
|
|
await StripePrice.add({
|
|
stripe_price_id: 'fake_plan_id',
|
|
stripe_product_id: 'fake_product_id',
|
|
amount: 5000,
|
|
interval: 'monthly',
|
|
active: 1,
|
|
nickname: 'Monthly',
|
|
currency: 'USD',
|
|
type: 'recurring'
|
|
}, context);
|
|
|
|
await StripeCustomerSubscription.add({
|
|
customer_id: 'fake_customer_id',
|
|
subscription_id: 'fake_subscription_id',
|
|
plan_id: 'fake_plan_id',
|
|
stripe_price_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');
|
|
});
|
|
});
|
|
});
|