Skip to content

Instantly share code, notes, and snippets.

@alovak
Last active August 29, 2015 14:15
Show Gist options
  • Save alovak/f0860cfd7b23717bd722 to your computer and use it in GitHub Desktop.
Save alovak/f0860cfd7b23717bd722 to your computer and use it in GitHub Desktop.
White specs
describe 'examples' do
describe 'POST /customers/:customer_id/cards' do
context 'when with card' do
it 'adds card to customer' do
post "/customers/#{customer[:id]}/cards", <<-JSON, headers
{
"card": {
"number": "4242424242424242",
"exp_year": 2020,
"exp_month": 11,
"cvc": "123",
"name": "John Doe"
}
}
JSON
expect(response.status).to eq(201)
expect(response).to match_response_schema(:card)
expect(response).to include_json(<<-JSON)
{
"customer_id": "#{customer[:id]}"
}
JSON
end
end
end
describe 'DELETE /customers/:customer_id/cards/:id' do
it 'returns empty response' do
delete "/customers/#{customer[:id]}/cards/#{customer[:default_card_id]}", '', headers
expect(response.status).to eq(204)
end
end
describe 'PUT /customers' do
let(:customer) { create_customer(account: account) }
context 'without card' do
it 'updates existing customer attributes and do not touch default card' do
put "/customers/#{customer[:id]}", <<-JSON, headers
{
"description": "New Description",
"email": "[email protected]",
"name": "New Name"
}
JSON
expect(response.status).to eq(200)
expect(response).to match_response_schema(:customer)
expect(response).to include_json(<<-JSON)
{
"description": "New Description",
"email": "[email protected]",
"name": "New Name",
"default_card_id": "#{customer[:default_card_id]}"
}
JSON
end
end
context 'when with card/token' do
let(:token) { create_token(open_api_key: open_api_key) }
it 'replaces default customer card' do
put "/customers/#{customer[:id]}", <<-JSON, headers
{
"description": "New Description",
"card": "#{token['id']}"
}
JSON
expect(response.status).to eq(200)
expect(response).to match_response_schema(:customer)
expect(response).to include_json(<<-JSON)
{
"description": "New Description",
"default_card_id": "#{token[:card][:id]}"
}
JSON
end
end
context 'whith default_card_id' do
let(:card_1_token) { create_token(open_api_key: open_api_key) }
let(:card_2_token ) { create_token(open_api_key: open_api_key) }
let(:new_card_id) { card_2_token['card']['id'] }
before do
AddCustomerCard.new(customer: customer, params: { card: card_1_token['id'] }).perform
AddCustomerCard.new(customer: customer, params: { card: card_2_token['id'] }).perform
end
it 'updates default customer card' do
old_default_card_id = customer.default_card_id
expect(customer.default_card_id).to_not eq(new_card_id)
put "/customers/#{customer[:id]}", <<-JSON, headers
{
"default_card_id": "#{new_card_id}"
}
JSON
expect(response.status).to eq(200)
expect(response).to match_response_schema(:customer)
expect(response).to include_json(<<-JSON)
{
"default_card_id": "#{new_card_id}"
}
JSON
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment