balanced / balanced-api

Balanced API specification.
220 stars 72 forks source link

Step definitions should use href instead of id #619

Open matin opened 10 years ago

matin commented 10 years ago

Step definitions currently look like this:

Given(/^I have a tokenized debit card$/) do
  @client.post('/cards',
    {
      name: "Johannes Bach",
      number: "4342561111111118",
      expiration_month: "05",
      expiration_year: "2015"
    }
  )
  @debit_card_id = @client['cards']['id']
  @client.add_hydrate(:debit_card_id, @debit_card_id)
end

It's referenced like this: When I POST to /cards/:debit_card_id/credits with the JSON API body:

It should instead be:

Given(/^I have a tokenized debit card$/) do
  @client.post('/cards',
    {
      name: "Johannes Bach",
      number: "4342561111111118",
      expiration_month: "05",
      expiration_year: "2015"
    }
  )
  @debit_card_id = @client['cards']['href']
  @client.add_hydrate(:debit_card_href, @debit_card_href)
end

and When I POST to :debit_card_href/credits with the JSON API body:

matthewfl commented 10 years ago

iirc when we redid the scenarios using cukes, we chose to use the ids instead as it made it easier to read.

This was compared to the yaml scenarios which did not have urls all over the scenarios since they were extrapolating from the hypermedia, and therefore somewhat confusing/hard to read

steveklabnik commented 10 years ago

I did it because our documentation specifically suggests URLs and IDs, so I had to make sure we covered those cases.

But we should have URL ones, too.

matin commented 10 years ago

@steveklabnik Should we use the two styles interchangeably in the scenarios?

steveklabnik commented 10 years ago

If we want to be truly exhaustive, we'd do both, because we want people to use hrefs, but also suggest they use ids.

:/

matin commented 10 years ago

Let's switch to using HREFs as we refactor. I'm worried about using IDs for the same reason we ask customers not to do so: it's prone to typos.

steveklabnik commented 10 years ago

Seems good. We should consider how we document all our endpoints, though...

matin commented 10 years ago

We should consider how we document all our endpoints, though...

What do you mean?

steveklabnik commented 10 years ago

Well, take https://docs.balancedpayments.com/1.1/api/cards/#fetch-a-card

This tells people to GET https://api.balancedpayments.com/cards/:card_id. So of course, they're going to use the ID, rather than an href from a previous response.