This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
/
email_one_click_spec.rb
140 lines (115 loc) · 4.17 KB
/
email_one_click_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# frozen_string_literal: true
require 'rails_helper'
require_relative 'shared_methods'
feature 'Express From Mailing Link' do
include SharedMethods
let(:follow_up_layout) { create :liquid_layout, default_follow_up_layout: nil }
let(:liquid_layout) { create :liquid_layout, default_follow_up_layout: follow_up_layout }
let(:donation_page) { create(:page, slug: 'foo-bar', title: 'Foo Bar', follow_up_liquid_layout: liquid_layout) }
let(:email) { 'donor@example.com' }
let(:member) { Member.find_by(email: email) }
let(:customer) { Payment::Braintree::Customer.find_by(email: email) }
let(:valid_akid) { '25429.9032842.RNP4O4' }
let(:queue_payload) do
{
type: 'donation',
payment_provider: 'braintree',
params: {
donationpage: {
name: 'foo-bar-donation', payment_account: 'Braintree GBP'
},
order: {
amount: '2.10',
card_num: '1881',
card_code: '007',
exp_date_month: '12',
exp_date_year: '2020',
currency: 'GBP'
},
action: {
source: nil,
fields: { action_express_donation: 1 }
},
user: {
first_name: 'Foo',
last_name: 'Bar',
email: 'donor@example.com',
country: 'United States',
akid: valid_akid,
source: nil,
user_express_cookie: 1,
user_express_account: @is_authenticated,
user_en: 1
}
},
meta: a_hash_including(
title: 'Foo Bar',
uri: '/a/foo-bar',
slug: 'foo-bar',
first_name: 'Foo',
last_name: 'Bar',
country: 'United States',
subscribed_member: false
)
}
end
before do
allow(ChampaignQueue).to receive(:push)
end
scenario 'Authenticated member makes a one-click donation' do
store_payment_in_vault
register_member(member)
authenticate_member(member.authentication)
expect(Action.count).to eq(1)
expect(customer.transactions.count).to eq(1)
@is_authenticated = 1
expect(ChampaignQueue).to receive(:push)
.with(queue_payload, group_id: /action:\d+/)
VCR.use_cassette('feature_member_email_donation') do
visit page_path(donation_page, amount: '2.10', currency: 'GBP', akid: valid_akid, one_click: true)
end
expect(customer.reload.transactions.count).to eq(2)
expect(Action.count).to eq(2)
# Redirects to follow up url for campaign page
expect(current_url).to match(%r{/foo-bar/follow-up\?member_id=#{member.id}})
end
scenario 'Cookied customer makes a one-click donation' do
store_payment_in_vault
expect(customer.transactions.count).to eq(1)
expect(Action.count).to eq(1)
@is_authenticated = 0
expect(ChampaignQueue).to receive(:push)
.with(queue_payload, group_id: /action:\d+/)
VCR.use_cassette('feature_one_click_cookie') do
visit page_path(donation_page, amount: '2.10', currency: 'GBP', akid: valid_akid, one_click: true)
end
expect(customer.reload.transactions.count).to eq(2)
expect(Action.count).to eq(2)
expect(current_url).to match(%r{/member_authentication/new})
end
scenario 'Cookied member makes a one-click donation' do
VCR.use_cassette('feature_one_click_member_no_customer') do
visit page_path(donation_page, amount: 1.50, currency: 'GBP', one_click: true)
end
expect(Action.count).to eq(0)
expect(current_url).to match(%r{/foo-bar})
end
scenario 'Stanger makes a one-click donation' do
VCR.use_cassette('feature_one_click_stranger') do
visit page_path(donation_page, amount: 1.50, currency: 'GBP', one_click: true)
end
expect(Action.count).to eq(0)
expect(current_url).to match(%r{/foo-bar})
end
scenario 'One-click donation with AKID, but without cookied payment methods' do
store_payment_in_vault
store_payment_in_vault(2)
delete_cookies_from_browser
VCR.use_cassette('feature_one_click_stranger') do
expect do
visit page_path(donation_page, amount: 1.50, currency: 'GBP', one_click: true, akid: valid_akid)
end.to_not change { customer.transactions.count }.from(2)
end
expect(current_url).to match(%r{/foo-bar})
end
end