Просмотр исходного кода

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

Shane Kilkelly 10 лет назад
Родитель
Сommit
e03d16e0cd

+ 3 - 0
services/web/app/coffee/Features/Subscription/RecurlyWrapper.coffee

@@ -418,6 +418,9 @@ module.exports = RecurlyWrapper =
 			url: "subscriptions/#{subscriptionId}/cancel",
 			url: "subscriptions/#{subscriptionId}/cancel",
 			method: "put"
 			method: "put"
 		}, (error, response, body) ->
 		}, (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)
 			callback(error)
 		)
 		)
 
 

+ 13 - 0
services/web/test/UnitTests/coffee/Subscription/RecurlyWrapperTests.coffee

@@ -314,6 +314,19 @@ describe "RecurlyWrapper", ->
 		it "should send a cancel request to the API", ->
 		it "should send a cancel request to the API", ->
 			@apiRequest.called.should.equal true
 			@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", ->
 	describe "reactivateSubscription", ->
 		beforeEach (done) ->
 		beforeEach (done) ->
 			@recurlySubscriptionId = "subscription-id-123"
 			@recurlySubscriptionId = "subscription-id-123"