balanced / balanced-api

Balanced API specification.
220 stars 72 forks source link

Regression: crediting a deleted card #625

Closed steveklabnik closed 10 years ago

steveklabnik commented 10 years ago

This spec used to pass, but now fails:

https://github.com/balanced/balanced-api/blob/master/features/credits.feature#L4-L18

https://travis-ci.org/balanced/balanced-api/builds/25547319#L61

{"errors"=>[{"status"=>"Bad Request", "category_code"=>"request", "additional"=>nil, "status_code"=>400, "category_type"=>"request", "extras"=>{"amount"=>"Missing required field [amount]"}, "request_id"=>"OHM8e9a3c08df9b11e3be3f02b12035401b", "description"=>"Missing required field [amount] Your request id is OHM8e9a3c08df9b11e3be3f02b12035401b."}]}

Did we recently change what's required for credits? A credit without an amount used to be the full amount.

msherry commented 10 years ago

The full amount of what? That makes sense for refunds and reversals, which are related to debits and credits, but crediting 'the full amount' doesn't really make sense, except maybe in the context of an order.

steveklabnik commented 10 years ago

I guess I was thinking of refunds and/or reversals.

steveklabnik commented 10 years ago

@msherry do you have any idea what may have changed recently to cause this to start failing where it wasn't before?

steveklabnik commented 10 years ago

This diff makes the test pass:

diff --git a/features/credits.feature b/features/credits.feature
index 72c82f9..7e6d85b 100644
--- a/features/credits.feature
+++ b/features/credits.feature
@@ -1,19 +1,27 @@
 Feature: Credits
   Credits are used for sending money to a customer

   Scenario: Crediting a deleted card leads to failure
     Given I have tokenized a card
     When I make a DELETE request to the href "href"
     Then I should get a 204 status code

-    When I make a POST request to /cards/:card_id/credits
-    Then I should get a 404 status code
+    When I make a POST request to /cards/:card_id/credits with the body:
+      """
+        {
+          "amount": 200,
+          "name": "John Doe"
+        }
+      """
+
+    Then I should get a 409 status code

     And the response is valid according to the "errors" schema
     And the fields on this error match:
     """
       {
-       "category_code": "not-found"
+       "category_code": "funding-destination-not-creditable"
       }
     """
diff --git a/features/step_definitions/cards.rb b/features/step_definitions/cards.rb
index aba5c0a..9f037c4 100644
--- a/features/step_definitions/cards.rb
+++ b/features/step_definitions/cards.rb
@@ -1,6 +1,7 @@
 Given(/^I have tokenized a card$/) do
   @client.post('/cards',
     {
+      name: "John Doe",
       number: "4111 1111 1111 1111",
       expiration_month: 12,
       expiration_year: 2016,
diff --git a/features/step_definitions/http_steps.rb b/features/step_definitions/http_steps.rb
index 2a4e087..41baa70 100644
--- a/features/step_definitions/http_steps.rb
+++ b/features/step_definitions/http_steps.rb

I'm investigating to see when this last actually worked. That's a lot of change.

steveklabnik commented 10 years ago

At some point, this existing test passed: https://travis-ci.org/balanced/balanced-api/builds/23978012

steveklabnik commented 10 years ago

Specifically https://github.com/balanced/balanced-api/blob/e8088d2d241d2198b52dacff9841be6d5f0d47f2/features/credits.feature#L4

matthewfl commented 10 years ago

https://github.com/balanced/balanced-api/blob/master/features/credits.feature#L79

This scenario is now passing, so I am going to close this