mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #467 from sharelatex/ja-validate-recurly-subscription-on-creation
Handle a 404 from Recurly if account doesn't exist
This commit is contained in:
commit
3bf19a38ee
2 changed files with 37 additions and 1 deletions
|
@ -475,8 +475,12 @@ module.exports = RecurlyWrapper =
|
|||
url: "accounts/#{account_id}/subscriptions"
|
||||
qs:
|
||||
state: "active"
|
||||
expect404: true
|
||||
}, (error, response, body) ->
|
||||
return callback(error) if error?
|
||||
if response.statusCode == 404
|
||||
return callback null, []
|
||||
else
|
||||
RecurlyWrapper._parseSubscriptionsXml body, callback
|
||||
|
||||
_parseSubscriptionsXml: (xml, callback) ->
|
||||
|
|
|
@ -1030,3 +1030,35 @@ describe "RecurlyWrapper", ->
|
|||
@call (err, result) =>
|
||||
expect(err).to.be.instanceof Error
|
||||
done()
|
||||
|
||||
describe "listAccountActiveSubscriptions", ->
|
||||
beforeEach ->
|
||||
@user_id = "mock-user-id"
|
||||
@callback = sinon.stub()
|
||||
@RecurlyWrapper.apiRequest = sinon.stub().yields(null, @response = {"mock": "response"}, @body = "<mock body/>")
|
||||
@RecurlyWrapper._parseSubscriptionsXml = sinon.stub().yields(null, @subscriptions = ["mock", "subscriptions"])
|
||||
|
||||
describe "with an account", ->
|
||||
beforeEach ->
|
||||
@RecurlyWrapper.listAccountActiveSubscriptions @user_id, @callback
|
||||
|
||||
it "should send a request to Recurly", ->
|
||||
@RecurlyWrapper.apiRequest
|
||||
.calledWith({
|
||||
url: "accounts/#{@user_id}/subscriptions"
|
||||
qs:
|
||||
state: "active"
|
||||
expect404: true
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
it "should return the subscriptions", ->
|
||||
@callback.calledWith(null, @subscriptions).should.equal true
|
||||
|
||||
describe "without an account", ->
|
||||
beforeEach ->
|
||||
@response.statusCode = 404
|
||||
@RecurlyWrapper.listAccountActiveSubscriptions @user_id, @callback
|
||||
|
||||
it "should return an empty array of subscriptions", ->
|
||||
@callback.calledWith(null, []).should.equal true
|
Loading…
Reference in a new issue