tinypass 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.DS_Store +0 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +19 -0
- data/lib/.DS_Store +0 -0
- data/lib/tinypass.rb +48 -0
- data/lib/tinypass/.DS_Store +0 -0
- data/lib/tinypass/builder.rb +7 -0
- data/lib/tinypass/builder/client_builder.rb +40 -0
- data/lib/tinypass/builder/client_parser.rb +48 -0
- data/lib/tinypass/builder/cookie_parser.rb +25 -0
- data/lib/tinypass/builder/json_msg_builder.rb +115 -0
- data/lib/tinypass/builder/open_encoder.rb +11 -0
- data/lib/tinypass/builder/secure_encoder.rb +15 -0
- data/lib/tinypass/builder/security_utils.rb +67 -0
- data/lib/tinypass/gateway.rb +104 -0
- data/lib/tinypass/offer.rb +23 -0
- data/lib/tinypass/policies.rb +5 -0
- data/lib/tinypass/policies/discount_policy.rb +25 -0
- data/lib/tinypass/policies/policy.rb +25 -0
- data/lib/tinypass/policies/pricing_policy.rb +13 -0
- data/lib/tinypass/policies/restriction_policy.rb +14 -0
- data/lib/tinypass/price_option.rb +66 -0
- data/lib/tinypass/resource.rb +17 -0
- data/lib/tinypass/token.rb +6 -0
- data/lib/tinypass/token/access_token.rb +163 -0
- data/lib/tinypass/token/access_token_list.rb +71 -0
- data/lib/tinypass/token/access_token_store.rb +59 -0
- data/lib/tinypass/token/meter.rb +76 -0
- data/lib/tinypass/token/meter_helper.rb +82 -0
- data/lib/tinypass/token/token_data.rb +72 -0
- data/lib/tinypass/ui.rb +2 -0
- data/lib/tinypass/ui/html_widget.rb +29 -0
- data/lib/tinypass/ui/purchase_request.rb +34 -0
- data/lib/tinypass/utils.rb +34 -0
- data/lib/tinypass/version.rb +3 -0
- data/spec/.DS_Store +0 -0
- data/spec/acceptance/basic_workflow_spec.rb +81 -0
- data/spec/integration/.DS_Store +0 -0
- data/spec/integration/cases/.DS_Store +0 -0
- data/spec/integration/cases/basic_spec.rb +53 -0
- data/spec/integration/cases/combo_spec.rb +43 -0
- data/spec/integration/cases/metered_reminder_spec.rb +42 -0
- data/spec/integration/cases/metered_strict_spec.rb +54 -0
- data/spec/integration/cases/metered_views_spec.rb +92 -0
- data/spec/integration/client_builder_and_parser_spec.rb +21 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/.DS_Store +0 -0
- data/spec/support/acceptance.rb +13 -0
- data/spec/support/tinypass_factories.rb +25 -0
- data/spec/unit/.DS_Store +0 -0
- data/spec/unit/builder/.DS_Store +0 -0
- data/spec/unit/builder/client_builder_spec.rb +23 -0
- data/spec/unit/builder/client_parser_spec.rb +27 -0
- data/spec/unit/builder/cookie_parser_spec.rb +39 -0
- data/spec/unit/builder/json_msg_builder_spec.rb +73 -0
- data/spec/unit/builder/open_encoder_spec.rb +15 -0
- data/spec/unit/builder/secure_encoder_spec.rb +23 -0
- data/spec/unit/builder/security_utils_spec.rb +42 -0
- data/spec/unit/gateway_spec.rb +80 -0
- data/spec/unit/offer_spec.rb +31 -0
- data/spec/unit/policies/.DS_Store +0 -0
- data/spec/unit/policies/discount_policy_spec.rb +40 -0
- data/spec/unit/policies/pricing_policy_spec.rb +23 -0
- data/spec/unit/policies/restriction_policy_spec.rb +35 -0
- data/spec/unit/price_option_spec.rb +109 -0
- data/spec/unit/resource_spec.rb +24 -0
- data/spec/unit/tinypass_spec.rb +51 -0
- data/spec/unit/token/.DS_Store +0 -0
- data/spec/unit/token/access_token_list_spec.rb +94 -0
- data/spec/unit/token/access_token_spec.rb +267 -0
- data/spec/unit/token/access_token_store_spec.rb +93 -0
- data/spec/unit/token/meter_helper_spec.rb +103 -0
- data/spec/unit/token/meter_spec.rb +66 -0
- data/spec/unit/token/token_data_spec.rb +66 -0
- data/spec/unit/ui/.DS_Store +0 -0
- data/spec/unit/ui/html_widget_spec.rb +89 -0
- data/spec/unit/ui/purchase_request_spec.rb +46 -0
- data/spec/unit/utils_spec.rb +57 -0
- data/tinypass.gemspec +35 -0
- metadata +330 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Tinypass::AccessTokenStore do
|
4
|
+
let(:store) { Tinypass::AccessTokenStore.new }
|
5
|
+
let(:token) { Tinypass::AccessToken.new('RID1', 0) }
|
6
|
+
|
7
|
+
describe "#load_tokens_from_cookie" do
|
8
|
+
let(:cookies) { build_tinypass_cookie(token) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
store.load_tokens_from_cookie(cookies)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "produces tokens with the correct length" do
|
15
|
+
expect(store.tokens.length).to eq 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sets the raw cookie" do
|
19
|
+
expect(store.raw_cookie).to eq cookies.values.first
|
20
|
+
end
|
21
|
+
|
22
|
+
it "sets the RID correctly" do
|
23
|
+
expect(store.get_access_token('RID1')).not_to be_nil # also tests #get_access_token
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets the other values correctly" do
|
27
|
+
expect(store.get_access_token('RID1').token_data.values).to eq token.token_data.values # also tests #get_access_token
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#get_access_token" do
|
32
|
+
it "returns an RID_NOT_FOUND token if absent and there are tokens" do
|
33
|
+
Tinypass::AccessToken.new('not in store', 0)
|
34
|
+
store.tokens << token
|
35
|
+
found_token = store.get_access_token('not in store')
|
36
|
+
|
37
|
+
expect(found_token).not_to be_nil
|
38
|
+
expect(found_token.access_granted?).to be_false
|
39
|
+
expect(found_token.metered?).to be_false
|
40
|
+
expect(found_token.meter_type).to eq 0
|
41
|
+
expect(found_token.trial_period_active?).to be_false
|
42
|
+
expect(found_token.lockout_period_active?).to be_false
|
43
|
+
expect(found_token.access_state).to eq Tinypass::AccessState::RID_NOT_FOUND
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns an RID_NOT_FOUND token if absent and empty" do
|
47
|
+
Tinypass::AccessToken.new('not in store', 0)
|
48
|
+
found_token = store.get_access_token('not_in_store')
|
49
|
+
|
50
|
+
expect(found_token).not_to be_nil
|
51
|
+
expect(found_token.access_granted?).to eq false
|
52
|
+
expect(found_token.access_state).to eq Tinypass::AccessState::NO_TOKENS_FOUND
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#has_token?" do
|
57
|
+
it "returns false when empty" do
|
58
|
+
expect(store.has_token?('absent')).to be_false
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns true when present" do
|
62
|
+
store.tokens << token
|
63
|
+
expect(store.has_token?(token.rid)).to be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns false when absent but not empty" do
|
67
|
+
expect(store.has_token?('absent')).to be_false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#find_active_token" do
|
72
|
+
it "returns nil when empty" do
|
73
|
+
expect(store.find_active_token(/absent/)).to be_nil
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns nil when token is inactive" do
|
77
|
+
expired_token = Tinypass::AccessToken.new('expired', Time.now.to_i - 1)
|
78
|
+
store.tokens << expired_token
|
79
|
+
|
80
|
+
expect(store.find_active_token(/expired/)).to be_nil
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns the token when found" do
|
84
|
+
store.tokens << token
|
85
|
+
expect(store.find_active_token(Regexp.new(token.rid))).to eq token
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns the token when not found" do
|
89
|
+
store.tokens << token
|
90
|
+
expect(store.find_active_token(/absent/)).to be_nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tinypass::MeterHelper do
|
4
|
+
describe ".create_view_based" do
|
5
|
+
it "delegates to Meter" do
|
6
|
+
Tinypass::Meter.should_receive(:create_view_based).with('meter name', 20, '24 hours').
|
7
|
+
and_return('what meter generated')
|
8
|
+
expect(Tinypass::MeterHelper.create_view_based('meter name', 20, '24 hours')).to eq 'what meter generated'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".create_time_based" do
|
13
|
+
it "delegates to Meter" do
|
14
|
+
Tinypass::Meter.should_receive(:create_time_based).with('meter name', '24 hours', '72 hours').
|
15
|
+
and_return('what meter generated')
|
16
|
+
expect(Tinypass::MeterHelper.create_time_based('meter name', '24 hours', '72 hours')).to eq 'what meter generated'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".load_meter_from_cookie" do
|
21
|
+
it "returns nil when trial is done" do
|
22
|
+
token = build_expired_trial_access_token('RID')
|
23
|
+
cookie = build_tinypass_cookie(token, 'RID')
|
24
|
+
|
25
|
+
expect(Tinypass::MeterHelper.load_meter_from_cookie('RID', cookie)).to be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns nil when rid not found" do
|
29
|
+
token = Tinypass::AccessToken.new('RID')
|
30
|
+
cookie = build_tinypass_cookie(token, 'RID')
|
31
|
+
|
32
|
+
expect(Tinypass::MeterHelper.load_meter_from_cookie('unknown rid', cookie)).to be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns the meter when found and active" do
|
36
|
+
token = build_active_trial_access_token('RID')
|
37
|
+
cookie = build_tinypass_cookie(token, 'RID')
|
38
|
+
meter = Tinypass::MeterHelper.load_meter_from_cookie('RID', cookie)
|
39
|
+
|
40
|
+
expect(meter).not_to be_nil
|
41
|
+
expect(meter.data.values).to eq token.token_data.values
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe ".load_meter_from_serialized_data" do
|
46
|
+
it "returns nil when trial is done" do
|
47
|
+
token = build_expired_trial_access_token('RID')
|
48
|
+
meter = Tinypass::Meter.new(token)
|
49
|
+
serialized = Tinypass::MeterHelper.serialize(meter)
|
50
|
+
|
51
|
+
expect(Tinypass::MeterHelper.load_meter_from_serialized_data(serialized)).to be_nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns the meter when found and active" do
|
55
|
+
token = build_active_trial_access_token('RID')
|
56
|
+
meter = Tinypass::Meter.new(token)
|
57
|
+
serialized = Tinypass::MeterHelper.serialize(meter)
|
58
|
+
deserialized = Tinypass::MeterHelper.load_meter_from_serialized_data(serialized)
|
59
|
+
|
60
|
+
expect(deserialized).not_to be_nil
|
61
|
+
expect(deserialized.data.values).to eq meter.data.values
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#serialize + #deserialize" do
|
66
|
+
it "is symmetrical" do
|
67
|
+
meter = Tinypass::MeterHelper.create_view_based('rid', 1, '1 second')
|
68
|
+
serialized = Tinypass::MeterHelper.serialize(meter)
|
69
|
+
deserialized = Tinypass::MeterHelper.deserialize(serialized)
|
70
|
+
expect(meter.data.values).to eq deserialized.data.values
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#serialize_to_json + #deserialize" do
|
75
|
+
it "is symmetrical" do
|
76
|
+
meter = Tinypass::MeterHelper.create_view_based('rid', 1, '1 second')
|
77
|
+
serialized = Tinypass::MeterHelper.serialize_to_json(meter)
|
78
|
+
json_string = serialized[5..-1] # skip encoding header
|
79
|
+
MultiJson.load(json_string) # if not json, this explodes
|
80
|
+
deserialized = Tinypass::MeterHelper.deserialize(serialized)
|
81
|
+
expect(meter.data.values).to eq deserialized.data.values
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#generate_cookie_embed_script" do
|
86
|
+
it "produces the expected script tag when not locked out" do
|
87
|
+
Time.should_receive('now').at_least(:once).and_return(Time.new(2013, 9, 24, 12, 12, 23))
|
88
|
+
meter = Tinypass::MeterHelper.create_time_based('name', '1 week', '1 day')
|
89
|
+
script_tag = Tinypass::MeterHelper.generate_cookie_embed_script('cookie_name', meter)
|
90
|
+
|
91
|
+
expect(script_tag).to eq "<script>\n document.cookie='cookie_name=%7Bjax%7DFKb1__OSKlSF7CJ55VTdCksOd3POWF5-bLQ3tDcl6MhKE0YsLW3Mh0t3PabcEnAOOr_RmnEIYP_bgv6ghLMUCoquOlmyWv3IDqvgiJ6UBo0~~~FWrTYDq0ljU3Bsn3Brqz6peZODWs9lZmeRbTkU6o7o8; path=/; expires=2013-12-23 16:12:23 UTC;';\n </script>"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "produces the expected script tag when locked out" do
|
95
|
+
Time.should_receive('now').at_least(:once).and_return(Time.new(2013, 9, 24, 12, 12, 23))
|
96
|
+
meter = Tinypass::MeterHelper.create_view_based('meter_name', 20, '1 day')
|
97
|
+
21.times { meter.increment } # NOTE: probable off-by-one error
|
98
|
+
script_tag = Tinypass::MeterHelper.generate_cookie_embed_script('cookie_name', meter)
|
99
|
+
|
100
|
+
expect(script_tag).to eq "<script>\n document.cookie='cookie_name=%7Bjax%7DyRg67-kFA8Cn0OD9JZhGfYoWyixspCG9n-trTyhzROo1zmFLI4YDk9KIKl4lnGeLBITKfHXaxRhnF7BaKgwuz6vsLbAxfLR3aXahAA9XaiaCGLR-GiCAOlyHHlb5bOUxlbvR1xuqpJqQFSXE5EXQ0A~~~aoKI1vpw7ISE9xV_lR_R0gC54x__3vFrcEiZkLLffcw; path=/; expires=2013-09-25 16:13:23 UTC;';\n </script>"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tinypass::Meter do
|
4
|
+
describe "#increment" do
|
5
|
+
it "increments the view count" do
|
6
|
+
meter = Tinypass::Meter.create_view_based('rid', 100, '1 day')
|
7
|
+
meter.increment
|
8
|
+
expect(meter.trial_view_count).to eq 1
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#data" do
|
13
|
+
it "returns the TokenData" do
|
14
|
+
meter = Tinypass::Meter.create_time_based('rid', '1 week', '24 hours')
|
15
|
+
data = meter.data
|
16
|
+
|
17
|
+
expect(data.rid).to eq 'rid'
|
18
|
+
expect(data[Tinypass::TokenData::METER_TRIAL_ENDTIME]).to eq Time.now.to_i + 60 * 60 * 24 * 7
|
19
|
+
expect(data[Tinypass::TokenData::METER_LOCKOUT_ENDTIME]).to eq Time.now.to_i + 60 * 60 * 24 * 8
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ".create_view_based" do
|
24
|
+
let(:max_views) { 123 }
|
25
|
+
let(:trial_period) { '1 day' }
|
26
|
+
let(:meter) { Tinypass::Meter.create_view_based('rid', max_views, trial_period) }
|
27
|
+
|
28
|
+
it "returns a meter" do
|
29
|
+
expect(meter).to be_kind_of Tinypass::Meter
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sets the fields" do
|
33
|
+
expect(meter.view_based?).to be_true
|
34
|
+
expect(meter.meter_type).to eq Tinypass::TokenData::METER_REMINDER
|
35
|
+
expect(meter.trial_view_count).to eq 0
|
36
|
+
expect(meter.trial_view_limit).to eq max_views
|
37
|
+
expect(meter.trial_end_time_secs).to eq Time.now.to_i + 60 * 60 * 24
|
38
|
+
expect(meter.lockout_end_time_secs).to eq Time.now.to_i + 60 * 60 * 24
|
39
|
+
|
40
|
+
expect(meter.trial_dead?).to be_false
|
41
|
+
expect(meter.trial_period_active?).to be_true
|
42
|
+
expect(meter.lockout_period_active?).to be_false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe ".create_time_based" do
|
47
|
+
let(:trial_period) { '1 day' }
|
48
|
+
let(:lockout_period) { '1 day' }
|
49
|
+
let(:meter) { Tinypass::Meter.create_time_based('rid', trial_period, lockout_period) }
|
50
|
+
|
51
|
+
it "returns a meter" do
|
52
|
+
expect(meter).to be_kind_of Tinypass::Meter
|
53
|
+
end
|
54
|
+
|
55
|
+
it "sets the fields" do
|
56
|
+
expect(meter.view_based?).to be_false
|
57
|
+
expect(meter.meter_type).to eq Tinypass::TokenData::METER_REMINDER
|
58
|
+
expect(meter.trial_end_time_secs).to eq Time.now.to_i + 60 * 60 * 24
|
59
|
+
expect(meter.lockout_end_time_secs).to eq Time.now.to_i + 60 * 60 * 24 * 2
|
60
|
+
|
61
|
+
expect(meter.trial_dead?).to be_false
|
62
|
+
expect(meter.trial_period_active?).to be_true
|
63
|
+
expect(meter.lockout_period_active?).to be_false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Tinypass::TokenData do
|
4
|
+
let(:token_data) { Tinypass::TokenData.new }
|
5
|
+
|
6
|
+
it "supports hash writes and reads" do
|
7
|
+
token_data[:key] = 'value'
|
8
|
+
expect(token_data['key']).to eq 'value'
|
9
|
+
expect(token_data[:key]).to eq 'value'
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#rid returns the rid" do
|
13
|
+
it "returns the rid field" do
|
14
|
+
token_data[Tinypass::TokenData::RID] = 'the rid'
|
15
|
+
expect(token_data[Tinypass::TokenData::RID]).to eq 'the rid'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#values" do
|
20
|
+
it "returns the internal hash" do
|
21
|
+
token_data[:key] = 'value'
|
22
|
+
expect(token_data.values).to eq('key' => 'value')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#fetch" do
|
27
|
+
it "returns the value when present" do
|
28
|
+
token_data[:key] = 'value'
|
29
|
+
expect(token_data.fetch(:key)).to eq 'value'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns the default when not" do
|
33
|
+
expect(token_data.fetch(:key, 'default value')).to eq 'default value'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#size" do
|
38
|
+
it "returns 0 when new" do
|
39
|
+
expect(token_data.size).to eq 0
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns the size when populated" do
|
43
|
+
token_data[:key] = 'value'
|
44
|
+
token_data['other_key'] = 123
|
45
|
+
expect(token_data.size).to eq 2
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#merge" do
|
50
|
+
it "sets more than one value at once" do
|
51
|
+
token_data.merge(key_1: 1, key_2: 2)
|
52
|
+
token_data.merge(key_3: 'abc', key_4: 'def')
|
53
|
+
expect(token_data.values).to eq('key_1' => 1, 'key_2' => 2, 'key_3' => 'abc', 'key_4' => 'def')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ".convert_to_epoch_seconds" do
|
58
|
+
it "returns the input if before the year ~43k AD" do
|
59
|
+
expect(Tinypass::TokenData.convert_to_epoch_seconds(1000)).to eq 1000
|
60
|
+
end
|
61
|
+
|
62
|
+
it "converts from milliseconds if beyond the year ~43k AD" do
|
63
|
+
expect(Tinypass::TokenData.convert_to_epoch_seconds(1293858000000 + 1)).to eq 1293858000
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
Binary file
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tinypass::HtmlWidget do
|
4
|
+
let(:resource) { Tinypass::Resource.new('RID1', 0) }
|
5
|
+
let(:price_option) { Tinypass::PriceOption.new('.50', '24 hours') }
|
6
|
+
let(:other_price_option) { Tinypass::PriceOption.new('.50', '1 week') }
|
7
|
+
let(:offer) { Tinypass::Offer.new(resource, price_option, other_price_option) }
|
8
|
+
|
9
|
+
let(:purchase_request) do
|
10
|
+
request = Tinypass::PurchaseRequest.new(offer)
|
11
|
+
request.callback = 'myFunction'
|
12
|
+
request
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:widget) { Tinypass::HtmlWidget.new }
|
16
|
+
|
17
|
+
describe "#create_button_html" do
|
18
|
+
let(:html) { widget.create_button_html(purchase_request) }
|
19
|
+
let(:doc) { Nokogiri::XML(html) }
|
20
|
+
let(:node) { doc.children.first }
|
21
|
+
|
22
|
+
it "is stringy" do
|
23
|
+
expect(html).to respond_to :to_str
|
24
|
+
end
|
25
|
+
|
26
|
+
it "produces no unexpected parsing errors" do
|
27
|
+
expect(doc.errors.length).to eq 1
|
28
|
+
expect(doc.errors.first.message).to eq "Namespace prefix tp on request is not defined" # TODO: fragile
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sets the tag name as expected" do
|
32
|
+
expect(node.name).to eq 'tp:request'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "sets the type attribute" do
|
36
|
+
expect(node[:type]).to eq 'purchase'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "sets the rid attribute" do
|
40
|
+
expect(node[:rid]).to eq 'RID1'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "sets the url attribute" do
|
44
|
+
expect(node[:url]).to eq 'https://sandbox.tinypass.com/v2'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "sets the aid attribute" do
|
48
|
+
expect(node[:aid]).to eq 'TEST_AID'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "sets the cn attribute" do
|
52
|
+
expect(node[:cn]).to eq '__TP_TEST_AID_TOKEN'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "sets the v attribute" do
|
56
|
+
expect(node[:v]).to eq '2.0.7'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "starts the rdata correctly" do
|
60
|
+
expect(node[:rdata]).to start_with '{jax}'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "has an rdata hmac delimiter" do
|
64
|
+
expect(node[:rdata]).to include '~~~'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "sets the callback" do
|
68
|
+
expect(node[:oncheckaccess]).to eq 'myFunction'
|
69
|
+
end
|
70
|
+
|
71
|
+
context "options" do
|
72
|
+
context "button.html" do
|
73
|
+
let(:purchase_request) { Tinypass::PurchaseRequest.new(offer, "button.html" => 'custom html "goes" here') }
|
74
|
+
|
75
|
+
it "sets and html_encodes the value" do
|
76
|
+
expect(node[:custom]).to eq 'custom html "goes" here'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "button.html" do
|
81
|
+
let(:purchase_request) { Tinypass::PurchaseRequest.new(offer, "button.link" => 'custom link "goes" here') }
|
82
|
+
|
83
|
+
it "sets and html_encodes the value" do
|
84
|
+
expect(node[:link]).to eq 'custom link "goes" here'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Tinypass::PurchaseRequest do
|
4
|
+
let(:resource) { Tinypass::Resource.new('RID1', 0) }
|
5
|
+
let(:price_option) { Tinypass::PriceOption.new('.50', '24 hours') }
|
6
|
+
let(:other_price_option) { Tinypass::PriceOption.new('.50', '1 week') }
|
7
|
+
let(:offer) { Tinypass::Offer.new(resource, price_option, other_price_option) }
|
8
|
+
|
9
|
+
let(:purchase_request) { Tinypass::PurchaseRequest.new(offer) }
|
10
|
+
|
11
|
+
describe "#generate_tag" do
|
12
|
+
it "delegates to an HtmlWidget" do
|
13
|
+
Tinypass::HtmlWidget.any_instance.should_receive(:create_button_html).with(purchase_request).and_return("generated html")
|
14
|
+
html = purchase_request.generate_tag
|
15
|
+
expect(html).to eq 'generated html'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#generate_link" do
|
20
|
+
it "returns the expected value" do
|
21
|
+
Tinypass::ClientBuilder.any_instance.should_receive(:build_purchase_request).with(purchase_request).and_return("purchase_request_string")
|
22
|
+
link = purchase_request.generate_link('return_url', 'cancel_url')
|
23
|
+
expect(link).to eq "https://sandbox.tinypass.com/v2/jsapi/auth.js?aid=#{ Tinypass.aid }&r=purchase_request_string"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can set the user ref" do
|
28
|
+
purchase_request.user_ref = 'user'
|
29
|
+
expect(purchase_request.user_ref).to eq 'user'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "can set client_ip" do
|
33
|
+
purchase_request.client_ip = '127.0.0.1'
|
34
|
+
expect(purchase_request.client_ip).to eq '127.0.0.1'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "sets the offer" do
|
38
|
+
expect(purchase_request.primary_offer).to eq offer
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can set the secondary offer" do
|
42
|
+
other_offer = Tinypass::Offer.new(Tinypass::Resource.new('RID2', 0), Tinypass::PriceOption.new('10', '1 year'))
|
43
|
+
purchase_request.secondary_offer = other_offer
|
44
|
+
expect(purchase_request.secondary_offer).to eq other_offer
|
45
|
+
end
|
46
|
+
end
|