From c5469d4fc3af749dfbdd91d55e7d470a8e317923 Mon Sep 17 00:00:00 2001 From: Ben Mills Date: Wed, 16 Apr 2014 16:59:24 -0600 Subject: [PATCH 1/3] Spec dispute documents --- features/rest/disputes.feature | 18 +++++++ features/step_definitions/disputes.rb | 38 ++++++++++++++ fixtures/_models/dispute_document.json | 71 ++++++++++++++++++++++++++ fixtures/dispute_documents.json | 24 +++++++++ fixtures/disputes.json | 8 ++- 5 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 fixtures/_models/dispute_document.json create mode 100644 fixtures/dispute_documents.json diff --git a/features/rest/disputes.feature b/features/rest/disputes.feature index 716fbb3..8120016 100644 --- a/features/rest/disputes.feature +++ b/features/rest/disputes.feature @@ -11,3 +11,21 @@ Feature: Disputes occur when customers dispute transactions When I GET to /disputes Then I should get a 200 OK status code And the response is valid according to the "disputes" schema + + Scenario: Retrieve a dispute document + Given I have a dispute with submitted documents + When I GET to /dispute_documents/:dispute_document_id + Then I should get a 200 OK status code + And the response is valid according to the "dispute_document" schema + + Scenario: List dispute documents for a dispute + Given I have a dispute with submitted documents + When I GET to /disputes/:dispute_id/dispute_documents + Then I should get a 200 OK status code + And the response is valid according to the "dispute_documents" schema + + Scenario: List dispute documents + Given I have a dispute with submitted documents + When I GET to /dispute_documents + Then I should get a 200 OK status code + And the response is valid according to the "dispute_documents" schema \ No newline at end of file diff --git a/features/step_definitions/disputes.rb b/features/step_definitions/disputes.rb index a5969e6..8767080 100644 --- a/features/step_definitions/disputes.rb +++ b/features/step_definitions/disputes.rb @@ -35,3 +35,41 @@ raise 'Unable to get a dispute in 3 minutes' if count == 0 @client.add_hydrate(:dispute_id, @dispute_id) end + +Given(/^I have a customer who will dispute any charge and I intend to disprove$/) do + step "I have created a customer" + @client.post('/cards', + { + number: "6500000000000003", + expiration_month: 12, + expiration_year: 3000, + cvv: "123", + customer: @customer_id + } + ) + @dispute_card_id = @client['cards']['id'] + @client.add_hydrate(:dispute_card_id, @dispute_card_id) +end + +Given(/^I have debited a card that will initiate a dispute with submitted documents$/) do + step "I have a customer who will dispute any charge and I intend to disprove" + @client.post("/cards/#{@dispute_card_id}/debits", { + 'amount' => 99999 + }) + @disputed_debit_id = @client['debits']['id'] + @client.add_hydrate(:disputed_debit_id, @disputed_debit_id) +end + +Given(/^I have a dispute with submitted documents$/) do + step 'I have debited a card that will initiate a dispute with submitted documents' + @dispute_id = nil + count = 60 + while @dispute_id.nil? and count > 0 + count -= 1 + @client.get("/debits/#{@disputed_debit_id}") + @dispute_id = @client['debits']['links']['dispute'] + sleep 3 + end + raise 'Unable to get a dispute in 3 minutes' if count == 0 + @client.add_hydrate(:dispute_id, @dispute_id) +end diff --git a/fixtures/_models/dispute_document.json b/fixtures/_models/dispute_document.json new file mode 100644 index 0000000..28a08fb --- /dev/null +++ b/fixtures/_models/dispute_document.json @@ -0,0 +1,71 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "id": { + "type": "string", + "pattern": "DD[a-zA-Z0-9]{16,32}" + }, + "href": { + "type": "string", + "format": "uri" + }, + "created_at": { + "type": "string", + "format": "date-time" + }, + "updated_at": { + "type": "string", + "format": "date-time" + }, + "url": { + "description": "The url where the file may be accessed", + "type": "string", + "format": "uri" + }, + "file_type": { + "type": "string", + "enum": [ + "pdf", + "doc", + "jpg" + ] + }, + "file_name": { + "description": "Original name of the uploaded file", + "type": "string" + }, + "meta": { + "$ref": "meta.json" + }, + "links": { + "type": "object", + "properties": { + "dispute": { + "description": "The dispute your customer has filed with their bank associated with this debit", + "type": [ + "null", + "string" + ], + "pattern": "DT[a-zA-Z0-9]{16,32}" + } + }, + "additionalProperties": false, + "required": [ + "dispute" + ] + } + }, + "additionalProperties": false, + "required": [ + "id", + "href", + "created_at", + "updated_at", + "url", + "file_type", + "file_name", + "meta", + "links" + ] +} \ No newline at end of file diff --git a/fixtures/dispute_documents.json b/fixtures/dispute_documents.json new file mode 100644 index 0000000..9367115 --- /dev/null +++ b/fixtures/dispute_documents.json @@ -0,0 +1,24 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "links": { + "type": "object", + "properties": {} + }, + "meta": { + "type": "object" + }, + "dispute_documents": { + "items": { + "$ref": "_models/dispute_document.json" + }, + "type": "array", + "minItems": 0, + "uniqueItems": true + } + }, + "required": [ + "dispute_documents" + ] +} \ No newline at end of file diff --git a/fixtures/disputes.json b/fixtures/disputes.json index 028e36c..d98cec0 100644 --- a/fixtures/disputes.json +++ b/fixtures/disputes.json @@ -14,11 +14,17 @@ "type": "string", "format": "uri", "pattern": "/disputes/{disputes.id}/events" + }, + "disputes.dispute_documents": { + "type": "string", + "format": "uri", + "pattern": "/disputes/{disputes.id}/dispute_documents" } }, "required": [ "disputes.transaction", - "disputes.events" + "disputes.events", + "disputes.dispute_documents" ] }, "meta": { From 16c7a4ffc6ad0c32969c3da21aa053426df48d79 Mon Sep 17 00:00:00 2001 From: Ben Mills Date: Thu, 17 Apr 2014 15:39:54 -0600 Subject: [PATCH 2/3] Update proposed spec for dispute document fields --- fixtures/_models/dispute_document.json | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fixtures/_models/dispute_document.json b/fixtures/_models/dispute_document.json index 28a08fb..426ea2a 100644 --- a/fixtures/_models/dispute_document.json +++ b/fixtures/_models/dispute_document.json @@ -23,18 +23,23 @@ "type": "string", "format": "uri" }, - "file_type": { + "mime_type": { "type": "string", "enum": [ - "pdf", - "doc", - "jpg" + "application/pdf", + "application/msword", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "image/jpeg" ] }, "file_name": { - "description": "Original name of the uploaded file", + "description": "Name of the document", "type": "string" }, + "file_size": { + "description": "Size on disk of the document", + "type": "integer" + }, "meta": { "$ref": "meta.json" }, @@ -42,7 +47,7 @@ "type": "object", "properties": { "dispute": { - "description": "The dispute your customer has filed with their bank associated with this debit", + "description": "The dispute the customer has filed with their bank associated with this debit", "type": [ "null", "string" @@ -63,8 +68,9 @@ "created_at", "updated_at", "url", - "file_type", + "mime_type", "file_name", + "file_size", "meta", "links" ] From ffc794bd9783e4d129c5a9401d22c9fa6d185c7d Mon Sep 17 00:00:00 2001 From: Ben Mills Date: Thu, 24 Apr 2014 11:17:58 -0600 Subject: [PATCH 3/3] Add documentation_submitted_at field to dispute spec --- fixtures/_models/dispute.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fixtures/_models/dispute.json b/fixtures/_models/dispute.json index d86243f..7aa45ff 100644 --- a/fixtures/_models/dispute.json +++ b/fixtures/_models/dispute.json @@ -46,6 +46,10 @@ "type": "string", "format": "date-time" }, + "documentation_submitted_at": { + "type": "string", + "format": "date-time" + }, "meta": { "$ref": "meta.json" },