Skip to content

Commit 4bb774f

Browse files
committed
features and steps
1 parent 6f01958 commit 4bb774f

File tree

11 files changed

+309
-6
lines changed

11 files changed

+309
-6
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
.idea
1212
.sass-cache
1313
.vagrant
14-
.rspec
14+
.rspec-local
1515
.yardoc
1616
/.bundle
1717
/config/application.yml

.rspec-local

Lines changed: 0 additions & 4 deletions
This file was deleted.

config/environments/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
config.assets.allow_debugging = true
1616
config.middleware.use RackSessionAccess::Middleware # allows to set session from within Capybara
1717

18-
Rails.logger = Logger.new(STDOUT)
18+
Rails.logger = Logger.new(STDOUT) # provides more verbose output when testing with headless browsers in case of errors
1919
Rails.logger.level = Logger::DEBUG
2020
end

spec/features/steps/basic_steps.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
step 'I am logged in as :name with email :email' do |name, email|
2+
login_as(username: name, email: email, bypass_ui_login: true)
3+
@logged_in_user = User.where(username: name).first
4+
end
5+
6+
step 'I go/am to/on page for :pupropse' do |purpose|
7+
path = case purpose
8+
when 'team management' then team_path(@logged_in_user.reload.team)
9+
end
10+
11+
visit path
12+
end
13+
14+
step 'show me the page' do
15+
page.save_screenshot('tmp/screenshot.png', full: true)
16+
end
17+
18+
step 'I click :link_name' do |name|
19+
click_link name
20+
end
21+
22+
step 'I am an administrator' do
23+
@logged_in_user.admin = true
24+
@logged_in_user.save
25+
end
26+
27+
step 'I should see :text' do |text|
28+
expect(page).to have_content(text)
29+
end
30+
31+
step 'I should see:' do |table|
32+
table.hashes.each do |text|
33+
expect(page).to have_content(text.values.first)
34+
end
35+
end
36+
37+
step 'the last email should contain:' do |table|
38+
mail = ActionMailer::Base.deliveries.last
39+
40+
table.hashes.each do |text|
41+
expect(mail).to have_content(text.values.first)
42+
end
43+
end

spec/features/steps/team_steps.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
step 'a team :team_name exists' do |team_name|
2+
Fabricate(:team, name: team_name)
3+
end
4+
5+
step 'team :team_name is subscribed to plan :plan_name with card :card_no' do |team_name, plan_name, card_no|
6+
plan = Fabricate.build(:plan, name: plan_name)
7+
8+
stripe_plan = JSON.parse(File.read('./spec/fixtures/stripe/stripe_plan.json')).with_indifferent_access.tap do |h|
9+
h[:interval] = plan.interval
10+
h[:name] = plan.name
11+
h[:created] = plan.created_at
12+
h[:amount] = plan.amount
13+
h[:currency] = plan.currency
14+
h[:id] = plan.public_id
15+
end
16+
stub_request(:post, /api.stripe.com\/v1\/plans/).to_return(body: stripe_plan.to_json)
17+
18+
plan.save
19+
20+
team = Team.where(name: team_name).first
21+
team.account.plan_ids = [plan.id]
22+
team.save
23+
24+
stripe_customer = JSON.parse(File.read('./spec/fixtures/stripe/stripe_customer.json')).with_indifferent_access.tap do |h|
25+
h[:id] = team.account.stripe_customer_token
26+
h[:description] = "test@test.com for #{team_name}"
27+
h[:cards][:data].first[:last4] = card_no
28+
end
29+
stub_request(:get, /api.stripe.com\/v1\/customers\/#{team.account.stripe_customer_token}/).to_return(body: stripe_customer.to_json)
30+
end
31+
32+
step 'team :team_name has invoices with data:' do |team_name, table|
33+
team = Team.where(name: team_name).first
34+
data = table.rows_hash
35+
36+
stripe_invoices = JSON.parse(File.read('./spec/fixtures/stripe/stripe_invoices.json')).with_indifferent_access.tap do |h|
37+
h[:data].first[:date] = Date.parse(data['Date']).to_time.to_i
38+
h[:data].first[:lines][:data].first[:period][:start] = Date.parse(data['Start']).to_time.to_i
39+
h[:data].first[:lines][:data].first[:period][:end] = Date.parse(data['End']).to_time.to_i
40+
end
41+
stub_request(:get, /api.stripe.com\/v1\/invoices/).to_return(body: stripe_invoices.to_json)
42+
end
43+
44+
step 'I am member of team :team_name' do |team_name|
45+
team = Team.find_by(name: team_name)
46+
team.add_user(@logged_in_user)
47+
team.account.admin_id = @logged_in_user.id
48+
team.save
49+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@js
2+
Feature: Generating an invoice
3+
In order to know what I was charged for
4+
As a customer
5+
I would like to receive invoice by email
6+
7+
Background:
8+
Given a team BOB_TEAM exists
9+
And team BOB_TEAM is subscribed to plan 'monthly' with card '1234'
10+
11+
Given I am logged in as Bob with email 'bob@bob.com'
12+
And I am an administrator
13+
And I am member of team BOB_TEAM
14+
15+
Scenario: Request an invoice
16+
Given team 'BOB_TEAM' has invoices with data:
17+
| Field | Value |
18+
| Date | 10/11/2015 |
19+
| Start | 02/11/2015 |
20+
| End | 02/12/2015 |
21+
When I go to page for "team management"
22+
And I click 'Send Invoice'
23+
Then show me the page
24+
Then I should see 'sent invoice for October to bob@bob.com'
25+
And the last email should contain:
26+
| Text |
27+
| Your card ending in 1234 has been charged |
28+
| Bill Date: November 10th, 2015 |
29+
| Bill To: bob BOB_TEAM |
30+
| Duration: November 2nd, 2015-December 2nd, 2015 |
31+
| Description: Enhanced Team Profile |
32+
| Price: $99.00 |
33+
| Assembly Made, Inc |
34+
| 548 Market St #45367 |
35+
| San Francisco, CA 94104-5401 |

spec/features/teams/team_management_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
feature "Teams management", js: true do
44

55
background do
6+
stub_request(:post, /api.mixpanel.com/)
67
login_as(username: 'alice', bypass_ui_login: true)
78
end
89

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"object": "customer",
3+
"created": 1414869388,
4+
"id": "id",
5+
"livemode": false,
6+
"description": "description",
7+
"email": null,
8+
"delinquent": false,
9+
"metadata": {
10+
},
11+
"subscriptions": {
12+
"object": "list",
13+
"total_count": 1,
14+
"has_more": false,
15+
"url": "/v1/customers/cus_54FsD2W2VkrKpW/subscriptions",
16+
"data": [
17+
{
18+
"id": "sub_54Fs1HFcWAAIpq",
19+
"plan": {
20+
"interval": "month",
21+
"name": "Monthly",
22+
"created": 1414770688,
23+
"amount": 9900,
24+
"currency": "usd",
25+
"id": "xdvd6q",
26+
"object": "plan",
27+
"livemode": false,
28+
"interval_count": 1,
29+
"trial_period_days": null,
30+
"metadata": {
31+
},
32+
"statement_description": null
33+
},
34+
"object": "subscription",
35+
"start": 1414869391,
36+
"status": "active",
37+
"customer": "cus_54FsD2W2VkrKpW",
38+
"cancel_at_period_end": false,
39+
"current_period_start": 1414869391,
40+
"current_period_end": 1417461391,
41+
"ended_at": null,
42+
"trial_start": null,
43+
"trial_end": null,
44+
"canceled_at": null,
45+
"quantity": 1,
46+
"application_fee_percent": null,
47+
"discount": null,
48+
"metadata": {
49+
}
50+
}
51+
]
52+
},
53+
"discount": null,
54+
"account_balance": 0,
55+
"currency": "eur",
56+
"cards": {
57+
"object": "list",
58+
"total_count": 1,
59+
"has_more": false,
60+
"url": "/v1/customers/cus_54FsD2W2VkrKpW/cards",
61+
"data": [
62+
{
63+
"id": "card_14u7LDFs0zmMxCeEcXXov7c3",
64+
"object": "card",
65+
"last4": "#{card_no}",
66+
"brand": "Visa",
67+
"funding": "credit",
68+
"exp_month": 12,
69+
"exp_year": 2015,
70+
"fingerprint": "ki37AQ0kNMxXqji5",
71+
"country": "US",
72+
"name": "test@test.com",
73+
"address_line1": null,
74+
"address_line2": null,
75+
"address_city": null,
76+
"address_state": null,
77+
"address_zip": null,
78+
"address_country": null,
79+
"cvc_check": "pass",
80+
"address_line1_check": null,
81+
"address_zip_check": null,
82+
"dynamic_last4": null,
83+
"customer": "cus_54FsD2W2VkrKpW"
84+
}
85+
]
86+
},
87+
"default_card": "card_14u7LDFs0zmMxCeEcXXov7c3"
88+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"object": "list",
3+
"count": 3,
4+
"url": "/v1/invoices",
5+
"data": [
6+
{
7+
"date": 1351728000,
8+
"id": "in_14u7MRFs0zmMxCeEaT5cKVge",
9+
"period_start": 1414869391,
10+
"period_end": 1414869391,
11+
"lines": {
12+
"data": [
13+
{
14+
"id": "sub_54eOiJskbnJ8Fn",
15+
"object": "line_item",
16+
"type": "subscription",
17+
"livemode": true,
18+
"amount": 3,
19+
"currency": "eur",
20+
"proration": false,
21+
"period": {
22+
"start": 1351728000,
23+
"end": 1351728000
24+
},
25+
"subscription": null,
26+
"quantity": 1,
27+
"plan": {
28+
"interval": "month",
29+
"name": "plan_no_1",
30+
"created": 1414956345,
31+
"amount": 3,
32+
"currency": "eur",
33+
"id": "aja7sg",
34+
"object": "plan",
35+
"livemode": false,
36+
"interval_count": 1,
37+
"trial_period_days": null,
38+
"metadata": {
39+
},
40+
"statement_description": null
41+
},
42+
"description": null,
43+
"metadata": {
44+
}
45+
}
46+
],
47+
"count": 1,
48+
"object": "list",
49+
"url": "/v1/invoices/in_14u7MRFs0zmMxCeEaT5cKVge/lines"
50+
},
51+
"subtotal": 9900,
52+
"total": 9900,
53+
"customer": "cus_54FsD2W2VkrKpW",
54+
"object": "invoice",
55+
"attempted": true,
56+
"closed": true,
57+
"forgiven": false,
58+
"paid": true,
59+
"livemode": false,
60+
"attempt_count": 1,
61+
"amount_due": 9900,
62+
"currency": "eur",
63+
"starting_balance": 0,
64+
"ending_balance": 0,
65+
"next_payment_attempt": null,
66+
"webhooks_delivered_at": 1414869391,
67+
"charge": "ch_14u7MRFs0zmMxCeE4GIkvsLG",
68+
"discount": null,
69+
"application_fee": null,
70+
"subscription": "sub_54Fs1HFcWAAIpq",
71+
"metadata": {
72+
},
73+
"statement_description": null,
74+
"description": null,
75+
"receipt_number": null
76+
}
77+
]
78+
}

spec/fixtures/stripe/stripe_plan.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"interval": "interval",
3+
"name": "name",
4+
"created": 1351728000,
5+
"amount": 29.99,
6+
"currency": "usd",
7+
"id": "asn53dl",
8+
"object": "plan",
9+
"livemode": false,
10+
"interval_count": 1,
11+
"trial_period_days": "",
12+
"statement_description": ""
13+
}

0 commit comments

Comments
 (0)