Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions features/rest/disputes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steveklabnik do you like dispute_documents vs evidence? What's your reasoning for choosing one over the other?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pluralization of evidence was what steered me away from using it as a resource name.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"evidence" can be evidence of anything, "dispute document" is extremely unambiguous.

I don't feel particularly strongly about it, though.

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
38 changes: 38 additions & 0 deletions features/step_definitions/disputes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@remear what do you think about removing this polling shit and tasking someone to fix the dispute latency? this is a cancer across all our specs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anigif_enhanced-buzz-30309-1388524076-1

Completely agree. This polling stuff horrible.

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
71 changes: 71 additions & 0 deletions fixtures/_models/dispute_document.json
Original file line number Diff line number Diff line change
@@ -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": {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not mime-type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections. I was initially avoiding adding a lot of file metadata for which I didn't feel there was a hard requirement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mime/type is exactly what you're looking for here so that would be my recommendation. otherwise anyone that consumes this has to do a mime/type -> file_type mapping otherwise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, mime_type is even better.

"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"
]
}
24 changes: 24 additions & 0 deletions fixtures/dispute_documents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"links": {
"type": "object",
"properties": {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a dispute_document.dispute reference

},
"meta": {
"type": "object"
},
"dispute_documents": {
"items": {
"$ref": "_models/dispute_document.json"
},
"type": "array",
"minItems": 0,
"uniqueItems": true
}
},
"required": [
"dispute_documents"
]
}
8 changes: 7 additions & 1 deletion fixtures/disputes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down