mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-13 21:53:43 +01:00
Merge pull request #28200 from overleaf/rh-trial-extension-fix
Fix calculation of extended trial renewal date GitOrigin-RevId: 3a73b4bba37ebcccfc80d123a1a6e6c286320571
This commit is contained in:
@@ -700,11 +700,12 @@ const promises = {
|
||||
if (trialEndsAt == null) {
|
||||
trialEndsAt = new Date()
|
||||
}
|
||||
const nextRenewalDate = new Date()
|
||||
nextRenewalDate.setDate(trialEndsAt.getDate() + daysUntilExpire)
|
||||
const nextRenewalDate = new Date(
|
||||
trialEndsAt.getTime() + daysUntilExpire * 24 * 60 * 60 * 1000
|
||||
)
|
||||
logger.debug(
|
||||
{ subscriptionId, daysUntilExpire },
|
||||
'Exending Free trial for user'
|
||||
'Extending Free trial for user'
|
||||
)
|
||||
try {
|
||||
await RecurlyWrapper.promises.apiRequest({
|
||||
|
||||
@@ -1472,4 +1472,57 @@ describe('RecurlyWrapper', function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('extendTrial', function () {
|
||||
beforeEach(function () {
|
||||
this.subscriptionId = 'subscription-id-123'
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
this.RecurlyWrapper.promises.apiRequest.restore()
|
||||
tk.reset()
|
||||
})
|
||||
|
||||
describe('with default parameters (7 days)', function () {
|
||||
beforeEach(async function () {
|
||||
tk.freeze(new Date('2025-01-25T10:30:00Z'))
|
||||
|
||||
this.apiRequest = sinon
|
||||
.stub(this.RecurlyWrapper.promises, 'apiRequest')
|
||||
.resolves()
|
||||
await this.RecurlyWrapper.promises.extendTrial(this.subscriptionId)
|
||||
})
|
||||
|
||||
it('should extend trial by 7 days from current time', function () {
|
||||
const options = this.apiRequest.lastCall.args[0]
|
||||
expect(options.qs.next_bill_date).to.deep.equal(
|
||||
new Date('2025-02-01T10:30:00Z')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('extending trial across year boundary', function () {
|
||||
beforeEach(async function () {
|
||||
// Trial ends on December 28, 2025, extend by 14 days to cross into 2026
|
||||
this.trialEndsAt = new Date('2025-12-28T12:00:00Z')
|
||||
this.daysUntilExpire = 14
|
||||
|
||||
this.apiRequest = sinon
|
||||
.stub(this.RecurlyWrapper.promises, 'apiRequest')
|
||||
.resolves()
|
||||
await this.RecurlyWrapper.promises.extendTrial(
|
||||
this.subscriptionId,
|
||||
this.trialEndsAt,
|
||||
this.daysUntilExpire
|
||||
)
|
||||
})
|
||||
|
||||
it('should correctly calculate date across year boundary', function () {
|
||||
const options = this.apiRequest.lastCall.args[0]
|
||||
expect(options.qs.next_bill_date).to.deep.equal(
|
||||
new Date('2026-01-11T12:00:00Z')
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user