mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Merged v5.12.3 into main
v5.12.3
This commit is contained in:
commit
df99e1aec3
4 changed files with 226 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ghost-admin",
|
"name": "ghost-admin",
|
||||||
"version": "5.12.2",
|
"version": "5.12.3",
|
||||||
"description": "Ember.js admin client for Ghost",
|
"description": "Ember.js admin client for Ghost",
|
||||||
"author": "Ghost Foundation",
|
"author": "Ghost Foundation",
|
||||||
"homepage": "http://ghost.org",
|
"homepage": "http://ghost.org",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ghost",
|
"name": "ghost",
|
||||||
"version": "5.12.2",
|
"version": "5.12.3",
|
||||||
"description": "The professional publishing platform",
|
"description": "The professional publishing platform",
|
||||||
"author": "Ghost Foundation",
|
"author": "Ghost Foundation",
|
||||||
"homepage": "https://ghost.org",
|
"homepage": "https://ghost.org",
|
||||||
|
|
|
@ -964,8 +964,11 @@ module.exports = class MemberRepository {
|
||||||
...eventData
|
...eventData
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
|
const context = options?.context || {};
|
||||||
|
const source = this._resolveContextSource(context);
|
||||||
|
|
||||||
// Notify paid member subscription start
|
// Notify paid member subscription start
|
||||||
if (this._labsService.isSet('emailAlerts')) {
|
if (this._labsService.isSet('emailAlerts') && ['member', 'api'].includes(source)) {
|
||||||
await this.staffService.notifyPaidSubscriptionStart({
|
await this.staffService.notifyPaidSubscriptionStart({
|
||||||
member: member.toJSON(),
|
member: member.toJSON(),
|
||||||
offer: offer ? this._offerRepository.toJSON(offer) : null,
|
offer: offer ? this._offerRepository.toJSON(offer) : null,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const sinon = require('sinon');
|
||||||
const MemberRepository = require('../../../../lib/repositories/member');
|
const MemberRepository = require('../../../../lib/repositories/member');
|
||||||
|
|
||||||
describe('MemberRepository', function () {
|
describe('MemberRepository', function () {
|
||||||
|
@ -49,4 +50,218 @@ describe('MemberRepository', function () {
|
||||||
assert.equal(source, 'member');
|
assert.equal(source, 'member');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('linkSubscription', function (){
|
||||||
|
let Member;
|
||||||
|
let staffService;
|
||||||
|
let notifySpy;
|
||||||
|
let MemberPaidSubscriptionEvent;
|
||||||
|
let StripeCustomerSubscription;
|
||||||
|
let MemberProductEvent;
|
||||||
|
let stripeAPIService;
|
||||||
|
let productRepository;
|
||||||
|
let labsService;
|
||||||
|
let subscriptionData;
|
||||||
|
|
||||||
|
beforeEach(async function () {
|
||||||
|
notifySpy = sinon.spy();
|
||||||
|
subscriptionData = {
|
||||||
|
id: 'sub_123',
|
||||||
|
customer: 'cus_123',
|
||||||
|
status: 'active',
|
||||||
|
items: {
|
||||||
|
type: 'list',
|
||||||
|
data: [{
|
||||||
|
id: 'item_123',
|
||||||
|
price: {
|
||||||
|
id: 'price_123',
|
||||||
|
product: 'product_123',
|
||||||
|
active: true,
|
||||||
|
nickname: 'Monthly',
|
||||||
|
currency: 'usd',
|
||||||
|
recurring: {
|
||||||
|
interval: 'month'
|
||||||
|
},
|
||||||
|
unit_amount: 500,
|
||||||
|
type: 'recurring'
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
start_date: Date.now() / 1000,
|
||||||
|
current_period_end: Date.now() / 1000 + (60 * 60 * 24 * 31),
|
||||||
|
cancel_at_period_end: false
|
||||||
|
};
|
||||||
|
|
||||||
|
Member = {
|
||||||
|
findOne: sinon.stub().resolves({
|
||||||
|
related: () => {
|
||||||
|
return {
|
||||||
|
query: sinon.stub().returns({
|
||||||
|
fetchOne: sinon.stub().resolves({})
|
||||||
|
}),
|
||||||
|
toJSON: sinon.stub().returns([]),
|
||||||
|
fetch: sinon.stub().resolves({
|
||||||
|
toJSON: sinon.stub().returns({})
|
||||||
|
})
|
||||||
|
};
|
||||||
|
},
|
||||||
|
toJSON: sinon.stub().returns({})
|
||||||
|
}),
|
||||||
|
edit: sinon.stub().resolves({
|
||||||
|
attributes: {},
|
||||||
|
_previousAttributes: {}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
staffService = {
|
||||||
|
notifyPaidSubscriptionStart: notifySpy
|
||||||
|
};
|
||||||
|
MemberPaidSubscriptionEvent = {
|
||||||
|
add: sinon.stub().resolves()
|
||||||
|
};
|
||||||
|
StripeCustomerSubscription = {
|
||||||
|
add: sinon.stub().resolves({
|
||||||
|
get: sinon.stub().returns()
|
||||||
|
})
|
||||||
|
};
|
||||||
|
MemberProductEvent = {
|
||||||
|
add: sinon.stub().resolves({})
|
||||||
|
};
|
||||||
|
|
||||||
|
stripeAPIService = {
|
||||||
|
configured: true,
|
||||||
|
getSubscription: sinon.stub().resolves(subscriptionData)
|
||||||
|
};
|
||||||
|
|
||||||
|
productRepository = {
|
||||||
|
get: sinon.stub().resolves({
|
||||||
|
get: sinon.stub().returns(),
|
||||||
|
toJSON: sinon.stub().returns({})
|
||||||
|
}),
|
||||||
|
update: sinon.stub().resolves({})
|
||||||
|
};
|
||||||
|
|
||||||
|
labsService = {
|
||||||
|
isSet: sinon.stub().returns(true)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('triggers email alert for member context', async function (){
|
||||||
|
const repo = new MemberRepository({
|
||||||
|
stripeAPIService,
|
||||||
|
StripeCustomerSubscription,
|
||||||
|
MemberPaidSubscriptionEvent,
|
||||||
|
MemberProductEvent,
|
||||||
|
staffService,
|
||||||
|
productRepository,
|
||||||
|
labsService,
|
||||||
|
Member
|
||||||
|
});
|
||||||
|
|
||||||
|
sinon.stub(repo, 'getSubscriptionByStripeID').resolves(null);
|
||||||
|
|
||||||
|
await repo.linkSubscription({
|
||||||
|
subscription: subscriptionData
|
||||||
|
}, {
|
||||||
|
transacting: true,
|
||||||
|
context: {}
|
||||||
|
});
|
||||||
|
notifySpy.calledOnce.should.be.true();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('triggers email alert for api context', async function (){
|
||||||
|
const repo = new MemberRepository({
|
||||||
|
stripeAPIService,
|
||||||
|
StripeCustomerSubscription,
|
||||||
|
MemberPaidSubscriptionEvent,
|
||||||
|
MemberProductEvent,
|
||||||
|
staffService,
|
||||||
|
productRepository,
|
||||||
|
labsService,
|
||||||
|
Member
|
||||||
|
});
|
||||||
|
|
||||||
|
sinon.stub(repo, 'getSubscriptionByStripeID').resolves(null);
|
||||||
|
|
||||||
|
await repo.linkSubscription({
|
||||||
|
subscription: subscriptionData
|
||||||
|
}, {
|
||||||
|
transacting: true,
|
||||||
|
context: {api_key: 'abc'}
|
||||||
|
});
|
||||||
|
notifySpy.calledOnce.should.be.true();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not trigger email alert for importer context', async function (){
|
||||||
|
const repo = new MemberRepository({
|
||||||
|
stripeAPIService,
|
||||||
|
StripeCustomerSubscription,
|
||||||
|
MemberPaidSubscriptionEvent,
|
||||||
|
MemberProductEvent,
|
||||||
|
staffService,
|
||||||
|
productRepository,
|
||||||
|
labsService,
|
||||||
|
Member
|
||||||
|
});
|
||||||
|
|
||||||
|
sinon.stub(repo, 'getSubscriptionByStripeID').resolves(null);
|
||||||
|
|
||||||
|
await repo.linkSubscription({
|
||||||
|
subscription: subscriptionData
|
||||||
|
}, {
|
||||||
|
transacting: true,
|
||||||
|
context: {importer: true}
|
||||||
|
});
|
||||||
|
notifySpy.calledOnce.should.be.false();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not trigger email alert for admin context', async function (){
|
||||||
|
const repo = new MemberRepository({
|
||||||
|
stripeAPIService,
|
||||||
|
StripeCustomerSubscription,
|
||||||
|
MemberPaidSubscriptionEvent,
|
||||||
|
MemberProductEvent,
|
||||||
|
staffService,
|
||||||
|
productRepository,
|
||||||
|
labsService,
|
||||||
|
Member
|
||||||
|
});
|
||||||
|
|
||||||
|
sinon.stub(repo, 'getSubscriptionByStripeID').resolves(null);
|
||||||
|
|
||||||
|
await repo.linkSubscription({
|
||||||
|
subscription: subscriptionData
|
||||||
|
}, {
|
||||||
|
transacting: true,
|
||||||
|
context: {user: {}}
|
||||||
|
});
|
||||||
|
notifySpy.calledOnce.should.be.false();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not trigger email alert for internal context', async function (){
|
||||||
|
const repo = new MemberRepository({
|
||||||
|
stripeAPIService,
|
||||||
|
StripeCustomerSubscription,
|
||||||
|
MemberPaidSubscriptionEvent,
|
||||||
|
MemberProductEvent,
|
||||||
|
staffService,
|
||||||
|
productRepository,
|
||||||
|
labsService,
|
||||||
|
Member
|
||||||
|
});
|
||||||
|
|
||||||
|
sinon.stub(repo, 'getSubscriptionByStripeID').resolves(null);
|
||||||
|
|
||||||
|
await repo.linkSubscription({
|
||||||
|
subscription: subscriptionData
|
||||||
|
}, {
|
||||||
|
transacting: true,
|
||||||
|
context: {internal: true}
|
||||||
|
});
|
||||||
|
notifySpy.calledOnce.should.be.false();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
sinon.restore();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue