candy_check 0.5.0 → 0.6.0
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 +4 -4
- data/.github/workflows/build.yml +1 -0
- data/.rubocop.yml +10 -0
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Guardfile +5 -3
- data/Rakefile +5 -5
- data/candy_check.gemspec +10 -10
- data/lib/candy_check/app_store/client.rb +7 -7
- data/lib/candy_check/app_store/config.rb +7 -9
- data/lib/candy_check/app_store/receipt.rb +16 -16
- data/lib/candy_check/app_store/receipt_collection.rb +2 -2
- data/lib/candy_check/app_store/subscription_verification.rb +5 -5
- data/lib/candy_check/app_store/verification.rb +3 -3
- data/lib/candy_check/app_store/verification_failure.rb +25 -21
- data/lib/candy_check/app_store/verifier.rb +4 -5
- data/lib/candy_check/app_store.rb +8 -8
- data/lib/candy_check/cli/app.rb +1 -1
- data/lib/candy_check/cli/commands/app_store.rb +1 -1
- data/lib/candy_check/cli/commands.rb +4 -4
- data/lib/candy_check/cli/out.rb +1 -3
- data/lib/candy_check/cli.rb +3 -3
- data/lib/candy_check/play_store/product_acknowledgements/acknowledgement.rb +2 -1
- data/lib/candy_check/play_store/product_purchases/product_purchase.rb +3 -3
- data/lib/candy_check/play_store/product_purchases/product_verification.rb +1 -1
- data/lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb +2 -1
- data/lib/candy_check/play_store/subscription_purchases/subscription_verification.rb +1 -0
- data/lib/candy_check/play_store/verification_failure.rb +2 -2
- data/lib/candy_check/utils/attribute_reader.rb +3 -2
- data/lib/candy_check/utils/config.rb +2 -0
- data/lib/candy_check/utils.rb +2 -2
- data/lib/candy_check/version.rb +1 -1
- data/lib/candy_check.rb +4 -4
- data/spec/app_store/client_spec.rb +18 -18
- data/spec/app_store/config_spec.rb +9 -9
- data/spec/app_store/receipt_collection_spec.rb +38 -40
- data/spec/app_store/receipt_spec.rb +47 -47
- data/spec/app_store/subscription_verification_spec.rb +35 -32
- data/spec/app_store/verifcation_failure_spec.rb +7 -7
- data/spec/app_store/verification_spec.rb +23 -11
- data/spec/app_store/verifier_spec.rb +40 -48
- data/spec/cli/app_spec.rb +11 -13
- data/spec/cli/commands/app_store_spec.rb +22 -23
- data/spec/cli/commands/play_store_spec.rb +3 -1
- data/spec/cli/commands/version_spec.rb +2 -2
- data/spec/cli/out_spec.rb +9 -9
- data/spec/play_store/acknowledger_spec.rb +4 -0
- data/spec/play_store/product_acknowledgements/acknowledgement_spec.rb +4 -0
- data/spec/play_store/product_acknowledgements/response_spec.rb +16 -15
- data/spec/play_store/product_purchases/product_purchase_spec.rb +6 -27
- data/spec/play_store/subscription_purchases/subscription_purchase_spec.rb +22 -46
- data/spec/play_store/verification_failure_spec.rb +6 -4
- data/spec/play_store/verifier_spec.rb +4 -2
- data/spec/spec_helper.rb +5 -7
- metadata +76 -76
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "date"
|
2
2
|
|
3
3
|
module CandyCheck
|
4
4
|
module Utils
|
@@ -23,7 +23,8 @@ module CandyCheck
|
|
23
23
|
def read_bool(field)
|
24
24
|
val = read(field).to_s
|
25
25
|
return nil unless %w(false true).include?(val)
|
26
|
-
|
26
|
+
|
27
|
+
val == "true"
|
27
28
|
end
|
28
29
|
|
29
30
|
def read_datetime_from_string(field)
|
@@ -26,6 +26,7 @@ module CandyCheck
|
|
26
26
|
# @raise [ArgumentError] if attribute is missing
|
27
27
|
def validates_presence(name)
|
28
28
|
return if send(name)
|
29
|
+
|
29
30
|
raise ArgumentError, "Configuration field #{name} is missing"
|
30
31
|
end
|
31
32
|
|
@@ -34,6 +35,7 @@ module CandyCheck
|
|
34
35
|
# @param values [Array] of possible values
|
35
36
|
def validates_inclusion(name, *values)
|
36
37
|
return if values.include?(send(name))
|
38
|
+
|
37
39
|
raise ArgumentError, "Configuration field #{name} should be "\
|
38
40
|
"one of: #{values.join(', ')}"
|
39
41
|
end
|
data/lib/candy_check/utils.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "candy_check/utils/attribute_reader"
|
2
|
+
require "candy_check/utils/config"
|
data/lib/candy_check/version.rb
CHANGED
data/lib/candy_check.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "candy_check/version"
|
2
|
+
require "candy_check/utils"
|
3
|
+
require "candy_check/app_store"
|
4
|
+
require "candy_check/play_store"
|
5
5
|
|
6
6
|
# Module to check and verify in-app receipts
|
7
7
|
module CandyCheck
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::AppStore::Client do
|
4
|
-
let(:endpoint_url) {
|
4
|
+
let(:endpoint_url) { "https://some.endpoint.com/verify" }
|
5
5
|
let(:receipt_data) do
|
6
|
-
|
6
|
+
"some_very_long_receipt_information_which_is_normaly_base64_encoded"
|
7
7
|
end
|
8
8
|
let(:password) do
|
9
|
-
|
9
|
+
"some_secret_password"
|
10
10
|
end
|
11
11
|
let(:response) do
|
12
12
|
'{
|
@@ -18,40 +18,40 @@ describe CandyCheck::AppStore::Client do
|
|
18
18
|
end
|
19
19
|
let(:expected) do
|
20
20
|
{
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
21
|
+
"status" => 0,
|
22
|
+
"receipt" => {
|
23
|
+
"item_id" => "521129812",
|
24
|
+
},
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
28
|
subject { CandyCheck::AppStore::Client.new(endpoint_url) }
|
29
29
|
|
30
|
-
describe
|
31
|
-
it
|
30
|
+
describe "valid response" do
|
31
|
+
it "sends JSON and parses the JSON response without a secret" do
|
32
32
|
stub_endpoint
|
33
33
|
.with(
|
34
34
|
body: {
|
35
|
-
|
36
|
-
}
|
35
|
+
"receipt-data" => receipt_data,
|
36
|
+
},
|
37
37
|
)
|
38
38
|
.to_return(
|
39
|
-
body: response
|
39
|
+
body: response,
|
40
40
|
)
|
41
41
|
result = subject.verify(receipt_data)
|
42
42
|
_(result).must_equal expected
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "sends JSON and parses the JSON response with a secret" do
|
46
46
|
stub_endpoint
|
47
47
|
.with(
|
48
48
|
body: {
|
49
|
-
|
50
|
-
|
51
|
-
}
|
49
|
+
"receipt-data" => receipt_data,
|
50
|
+
"password" => password,
|
51
|
+
},
|
52
52
|
)
|
53
53
|
.to_return(
|
54
|
-
body: response
|
54
|
+
body: response,
|
55
55
|
)
|
56
56
|
result = subject.verify(receipt_data, password)
|
57
57
|
_(result).must_equal expected
|
@@ -1,39 +1,39 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::AppStore::Config do
|
4
4
|
subject { CandyCheck::AppStore::Config.new(attributes) }
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe "valid" do
|
7
7
|
let(:attributes) do
|
8
8
|
{
|
9
|
-
environment: :sandbox
|
9
|
+
environment: :sandbox,
|
10
10
|
}
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it "returns environment" do
|
14
14
|
_(subject.environment).must_equal :sandbox
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it "checks for production?" do
|
18
18
|
_(subject.production?).must_be_false
|
19
19
|
|
20
20
|
other = CandyCheck::AppStore::Config.new(
|
21
|
-
environment: :production
|
21
|
+
environment: :production,
|
22
22
|
)
|
23
23
|
_(other.production?).must_be_true
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe
|
27
|
+
describe "invalid" do
|
28
28
|
let(:attributes) do
|
29
29
|
{}
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it "needs an environment" do
|
33
33
|
_(proc { subject }).must_raise ArgumentError
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it "needs an included environment" do
|
37
37
|
attributes[:environment] = :invalid
|
38
38
|
_(proc { subject }).must_raise ArgumentError
|
39
39
|
end
|
@@ -1,98 +1,96 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::AppStore::ReceiptCollection do
|
4
4
|
subject { CandyCheck::AppStore::ReceiptCollection.new(attributes) }
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe "overdue subscription" do
|
7
7
|
let(:attributes) do
|
8
8
|
[{
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
"expires_date" => "2014-04-15 12:52:40 Etc/GMT",
|
10
|
+
"expires_date_pst" => "2014-04-15 05:52:40 America/Los_Angeles",
|
11
|
+
"purchase_date" => "2014-04-14 12:52:40 Etc/GMT",
|
12
|
+
"is_trial_period" => "false",
|
13
13
|
}, {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
"expires_date" => "2015-04-15 12:52:40 Etc/GMT",
|
15
|
+
"expires_date_pst" => "2015-04-15 05:52:40 America/Los_Angeles",
|
16
|
+
"purchase_date" => "2015-04-14 12:52:40 Etc/GMT",
|
17
|
+
"is_trial_period" => "false",
|
18
18
|
}]
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it "is expired" do
|
22
22
|
_(subject.expired?).must_be_true
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it "is not a trial" do
|
26
26
|
_(subject.trial?).must_be_false
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it "has positive overdue days" do
|
30
30
|
overdue = subject.overdue_days
|
31
31
|
_(overdue).must_be_instance_of Integer
|
32
32
|
assert overdue > 0
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it "has a last expires date" do
|
36
36
|
expected = DateTime.new(2015, 4, 15, 12, 52, 40)
|
37
37
|
_(subject.expires_at).must_equal expected
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it "is expired? at same pointin time" do
|
41
41
|
Timecop.freeze(Time.utc(2015, 4, 15, 12, 52, 40)) do
|
42
42
|
_(subject.expired?).must_be_true
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
describe
|
47
|
+
describe "unordered receipts" do
|
48
48
|
let(:attributes) do
|
49
49
|
[{
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
50
|
+
"expires_date" => "2015-04-15 12:52:40 Etc/GMT",
|
51
|
+
"expires_date_pst" => "2015-04-15 05:52:40 America/Los_Angeles",
|
52
|
+
"purchase_date" => "2015-04-14 12:52:40 Etc/GMT",
|
53
|
+
"is_trial_period" => "false",
|
54
|
+
}, {
|
55
|
+
"expires_date" => "2014-04-15 12:52:40 Etc/GMT",
|
56
|
+
"expires_date_pst" => "2014-04-15 05:52:40 America/Los_Angeles",
|
57
|
+
"purchase_date" => "2014-04-14 12:52:40 Etc/GMT",
|
58
|
+
"is_trial_period" => "false",
|
59
|
+
}]
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it "the expires date is the latest one in time" do
|
63
63
|
expected = DateTime.new(2015, 4, 15, 12, 52, 40)
|
64
64
|
_(subject.expires_at).must_equal expected
|
65
65
|
end
|
66
|
-
|
67
66
|
end
|
68
67
|
|
69
|
-
describe
|
68
|
+
describe "unexpired trial subscription" do
|
70
69
|
two_days_from_now = DateTime.now + 2
|
71
70
|
|
72
71
|
let(:attributes) do
|
73
72
|
[{
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
"expires_date" => "2016-04-15 12:52:40 Etc/GMT",
|
74
|
+
"purchase_date" => "2016-04-15 12:52:40 Etc/GMT",
|
75
|
+
"is_trial_period" => "true",
|
77
76
|
}, {
|
78
|
-
|
79
|
-
two_days_from_now.strftime(
|
80
|
-
|
81
|
-
|
77
|
+
"expires_date" =>
|
78
|
+
two_days_from_now.strftime("%Y-%m-%d %H:%M:%S Etc/GMT"),
|
79
|
+
"purchase_date" => "2016-04-15 12:52:40 Etc/GMT",
|
80
|
+
"is_trial_period" => "true",
|
82
81
|
}]
|
83
82
|
end
|
84
83
|
|
85
|
-
it
|
84
|
+
it "has not expired" do
|
86
85
|
_(subject.expired?).must_be_false
|
87
86
|
end
|
88
87
|
|
89
|
-
it
|
88
|
+
it "it is a trial" do
|
90
89
|
_(subject.trial?).must_be_true
|
91
90
|
end
|
92
91
|
|
93
|
-
it
|
92
|
+
it "expires in two days" do
|
94
93
|
_(subject.overdue_days).must_equal(-2)
|
95
94
|
end
|
96
95
|
end
|
97
|
-
|
98
96
|
end
|
@@ -1,105 +1,105 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::AppStore::Receipt do
|
4
4
|
subject { CandyCheck::AppStore::Receipt.new(attributes) }
|
5
5
|
|
6
6
|
let(:attributes) do
|
7
7
|
{
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
8
|
+
"original_purchase_date_pst" => "2015-01-08 03:40:46" \
|
9
|
+
" America/Los_Angeles",
|
10
|
+
"purchase_date_ms" => "1420803646868",
|
11
|
+
"unique_identifier" => "some_uniq_identifier_from_apple" \
|
12
|
+
"_for_this",
|
13
|
+
"original_transaction_id" => "some_original_transaction_id",
|
14
|
+
"bvrs" => "2.0",
|
15
|
+
"transaction_id" => "some_transaction_id",
|
16
|
+
"quantity" => "1",
|
17
|
+
"unique_vendor_identifier" => "00000000-1111-2222-3333-" \
|
18
|
+
"444444444444",
|
19
|
+
"item_id" => "some_item_id",
|
20
|
+
"product_id" => "some_product",
|
21
|
+
"purchase_date" => "2015-01-09 11:40:46 Etc/GMT",
|
22
|
+
"original_purchase_date" => "2015-01-08 11:40:46 Etc/GMT",
|
23
|
+
"purchase_date_pst" => "2015-01-09 03:40:46" \
|
24
|
+
" America/Los_Angeles",
|
25
|
+
"bid" => "some.test.app",
|
26
|
+
"original_purchase_date_ms" => "1420717246868",
|
27
|
+
"expires_date" => "2016-06-09 13:59:40 Etc/GMT",
|
28
|
+
"is_trial_period" => "false",
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
33
|
-
it
|
32
|
+
describe "valid transaction" do
|
33
|
+
it "is valid" do
|
34
34
|
_(subject.valid?).must_be_true
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
38
|
-
_(subject.item_id).must_equal
|
37
|
+
it "returns the item's id" do
|
38
|
+
_(subject.item_id).must_equal "some_item_id"
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
_(subject.product_id).must_equal
|
41
|
+
it "returns the item's product_id" do
|
42
|
+
_(subject.product_id).must_equal "some_product"
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "returns the quantity" do
|
46
46
|
_(subject.quantity).must_equal 1
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
50
|
-
_(subject.app_version).must_equal
|
49
|
+
it "returns the app version" do
|
50
|
+
_(subject.app_version).must_equal "2.0"
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
54
|
-
_(subject.bundle_identifier).must_equal
|
53
|
+
it "returns the bundle identifier" do
|
54
|
+
_(subject.bundle_identifier).must_equal "some.test.app"
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
57
|
+
it "returns the purchase date" do
|
58
58
|
expected = DateTime.new(2015, 1, 9, 11, 40, 46)
|
59
59
|
_(subject.purchase_date).must_equal expected
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it "returns the original purchase date" do
|
63
63
|
expected = DateTime.new(2015, 1, 8, 11, 40, 46)
|
64
64
|
_(subject.original_purchase_date).must_equal expected
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
68
|
-
_(subject.transaction_id).must_equal
|
67
|
+
it "returns the transaction id" do
|
68
|
+
_(subject.transaction_id).must_equal "some_transaction_id"
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
_(subject.original_transaction_id).must_equal
|
71
|
+
it "returns the original transaction id" do
|
72
|
+
_(subject.original_transaction_id).must_equal "some_original_transaction_id"
|
73
73
|
end
|
74
74
|
|
75
|
-
it
|
75
|
+
it "return nil for cancellation date" do
|
76
76
|
_(subject.cancellation_date).must_be_nil
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
79
|
+
it "returns raw attributes" do
|
80
80
|
_(subject.attributes).must_be_same_as attributes
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it "returns the subscription expiration date" do
|
84
84
|
expected = DateTime.new(2016, 6, 9, 13, 59, 40)
|
85
85
|
_(subject.expires_date).must_equal expected
|
86
86
|
end
|
87
87
|
|
88
|
-
it
|
88
|
+
it "returns the trial status" do
|
89
89
|
_(subject.is_trial_period).must_be_false
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
describe
|
93
|
+
describe "valid transaction" do
|
94
94
|
before do
|
95
|
-
attributes[
|
95
|
+
attributes["cancellation_date"] = "2015-01-12 11:40:46 Etc/GMT"
|
96
96
|
end
|
97
97
|
|
98
|
-
it
|
98
|
+
it "isn't valid" do
|
99
99
|
_(subject.valid?).must_be_false
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
102
|
+
it "return nil for cancellation date" do
|
103
103
|
expected = DateTime.new(2015, 1, 12, 11, 40, 46)
|
104
104
|
_(subject.cancellation_date).must_equal expected
|
105
105
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::AppStore::SubscriptionVerification do
|
4
4
|
subject do
|
5
5
|
CandyCheck::AppStore::SubscriptionVerification.new(endpoint, data, secret)
|
6
6
|
end
|
7
|
-
let(:endpoint) {
|
8
|
-
let(:data) {
|
9
|
-
let(:secret) {
|
7
|
+
let(:endpoint) { "https://some.endpoint" }
|
8
|
+
let(:data) { "some_data" }
|
9
|
+
let(:secret) { "some_secret" }
|
10
10
|
|
11
|
-
it
|
12
|
-
with_mocked_response(
|
11
|
+
it "returns a verification failure for status != 0" do
|
12
|
+
with_mocked_response("status" => 21_000) do |client, recorded|
|
13
13
|
result = subject.call!
|
14
14
|
_(client.receipt_data).must_equal data
|
15
15
|
_(client.secret).must_equal secret
|
@@ -21,7 +21,7 @@ describe CandyCheck::AppStore::SubscriptionVerification do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it "returns a verification failure when receipt is missing" do
|
25
25
|
with_mocked_response({}) do |client, recorded|
|
26
26
|
result = subject.call!
|
27
27
|
_(client.receipt_data).must_equal data
|
@@ -34,13 +34,13 @@ describe CandyCheck::AppStore::SubscriptionVerification do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it "returns a collection of receipt when status is 0 and receipts exists" do
|
38
38
|
response = {
|
39
|
-
|
40
|
-
|
41
|
-
{
|
42
|
-
{
|
43
|
-
]
|
39
|
+
"status" => 0,
|
40
|
+
"latest_receipt_info" => [
|
41
|
+
{ "item_id" => "some_id", "purchase_date" => "2016-04-15 12:52:40 Etc/GMT" },
|
42
|
+
{ "item_id" => "some_other_id", "purchase_date" => "2016-04-15 12:52:40 Etc/GMT" },
|
43
|
+
],
|
44
44
|
}
|
45
45
|
with_mocked_response(response) do
|
46
46
|
result = subject.call!
|
@@ -49,29 +49,30 @@ describe CandyCheck::AppStore::SubscriptionVerification do
|
|
49
49
|
_(result.receipts.size).must_equal(2)
|
50
50
|
last = result.receipts.last
|
51
51
|
_(last).must_be_instance_of CandyCheck::AppStore::Receipt
|
52
|
-
_(last.item_id).must_equal(
|
52
|
+
_(last.item_id).must_equal("some_other_id")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
describe
|
56
|
+
describe "filtered product_ids" do
|
57
57
|
subject do
|
58
58
|
CandyCheck::AppStore::SubscriptionVerification.new(
|
59
59
|
endpoint,
|
60
60
|
data,
|
61
61
|
secret,
|
62
|
-
product_ids
|
62
|
+
product_ids,
|
63
63
|
)
|
64
64
|
end
|
65
|
-
let(:product_ids) { [
|
65
|
+
let(:product_ids) { ["product_1"] }
|
66
66
|
|
67
|
-
it
|
67
|
+
it "returns only filtered reciepts when specifc product_ids are reqested" do
|
68
68
|
response = {
|
69
|
-
|
70
|
-
|
71
|
-
{
|
72
|
-
{
|
73
|
-
|
74
|
-
|
69
|
+
"status" => 0,
|
70
|
+
"latest_receipt_info" => [
|
71
|
+
{ "item_id" => "some_id", "product_id" => "product_1", "purchase_date" => "2016-04-15 12:52:40 Etc/GMT" },
|
72
|
+
{ "item_id" => "some_other_id", "product_id" => "product_1",
|
73
|
+
"purchase_date" => "2016-04-15 12:52:40 Etc/GMT" },
|
74
|
+
{ "item_id" => "some_id", "product_id" => "product_2", "purchase_date" => "2016-04-15 12:52:40 Etc/GMT" },
|
75
|
+
],
|
75
76
|
}
|
76
77
|
with_mocked_response(response) do
|
77
78
|
result = subject.call!
|
@@ -80,26 +81,28 @@ describe CandyCheck::AppStore::SubscriptionVerification do
|
|
80
81
|
_(result.receipts.size).must_equal(2)
|
81
82
|
last = result.receipts.last
|
82
83
|
_(last).must_be_instance_of CandyCheck::AppStore::Receipt
|
83
|
-
_(last.item_id).must_equal(
|
84
|
+
_(last.item_id).must_equal("some_other_id")
|
84
85
|
end
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
88
89
|
private
|
89
90
|
|
90
|
-
|
91
|
-
|
91
|
+
let(:dummy_client_class) do
|
92
|
+
Struct.new(:response) do
|
93
|
+
attr_reader :receipt_data, :secret
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
95
|
+
def verify(receipt_data, secret)
|
96
|
+
@receipt_data = receipt_data
|
97
|
+
@secret = secret
|
98
|
+
response
|
99
|
+
end
|
97
100
|
end
|
98
101
|
end
|
99
102
|
|
100
103
|
def with_mocked_response(response)
|
101
104
|
recorded = []
|
102
|
-
dummy =
|
105
|
+
dummy = dummy_client_class.new(response)
|
103
106
|
stub = proc do |*args|
|
104
107
|
recorded << args
|
105
108
|
dummy
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::AppStore::VerificationFailure do
|
4
4
|
subject { CandyCheck::AppStore::VerificationFailure }
|
@@ -6,23 +6,23 @@ describe CandyCheck::AppStore::VerificationFailure do
|
|
6
6
|
[21_000, 21_002, 21_003, 21_004, 21_005, 21_006, 21_007, 21_008]
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it "fetched an failure with message for every known code" do
|
10
10
|
known.each do |code|
|
11
11
|
got = subject.fetch(code)
|
12
12
|
_(got.code).must_equal code
|
13
|
-
_(got.message).wont_equal
|
13
|
+
_(got.message).wont_equal "Unknown error"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it "fetched an failure for unknown codes" do
|
18
18
|
got = subject.fetch(1234)
|
19
19
|
_(got.code).must_equal 1234
|
20
|
-
_(got.message).must_equal
|
20
|
+
_(got.message).must_equal "Unknown error"
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it "fetched an failure for nil code" do
|
24
24
|
got = subject.fetch(nil)
|
25
25
|
_(got.code).must_equal(-1)
|
26
|
-
_(got.message).must_equal
|
26
|
+
_(got.message).must_equal "Unknown error"
|
27
27
|
end
|
28
28
|
end
|