Deleting user: if subscription is already cancelled, ignore and proceed.

This commit is contained in:
Shane Kilkelly 2016-11-30 16:03:18 +00:00
parent 68ddf04fe8
commit e03d16e0cd
2 changed files with 16 additions and 0 deletions

View file

@ -418,6 +418,9 @@ module.exports = RecurlyWrapper =
url: "subscriptions/#{subscriptionId}/cancel",
method: "put"
}, (error, response, body) ->
if error? and body?.match(/.*A canceled subscription can't transition to canceled.*/)
logger.log {subscriptionId, error, body}, "subscription already cancelled, not really an error, proceeding"
error = null
callback(error)
)

View file

@ -314,6 +314,19 @@ describe "RecurlyWrapper", ->
it "should send a cancel request to the API", ->
@apiRequest.called.should.equal true
describe 'when the subscription is already cancelled', ->
beforeEach ->
@RecurlyWrapper.apiRequest.restore()
@recurlySubscriptionId = "subscription-id-123"
@apiRequest = sinon.stub @RecurlyWrapper, "apiRequest", (options, callback) =>
callback(new Error('woops'), {}, "<error><description>A canceled subscription can't transition to canceled</description></error>")
it 'should not produce an error', (done) ->
@RecurlyWrapper.cancelSubscription @recurlySubscriptionId, (err) =>
expect(err).to.equal null
done()
describe "reactivateSubscription", ->
beforeEach (done) ->
@recurlySubscriptionId = "subscription-id-123"