candy_check 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +35 -0
- data/.rubocop.yml +10 -0
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Guardfile +5 -3
- data/README.md +2 -2
- data/Rakefile +5 -5
- data/candy_check.gemspec +14 -12
- 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 +3 -3
- 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/play_store.rb +2 -1
- 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 +39 -41
- 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/fixtures/vcr_cassettes/play_store/product_acknowledgements/acknowledged.yml +1 -1
- data/spec/fixtures/vcr_cassettes/play_store/product_acknowledgements/already_acknowledged.yml +1 -1
- data/spec/fixtures/vcr_cassettes/play_store/product_acknowledgements/refunded.yml +1 -1
- data/spec/fixtures/vcr_cassettes/play_store/product_purchases/permission_denied.yml +2 -2
- data/spec/fixtures/vcr_cassettes/play_store/product_purchases/response_with_empty_body.yml +2 -2
- data/spec/fixtures/vcr_cassettes/play_store/product_purchases/valid_but_not_consumed.yml +1 -1
- data/spec/fixtures/vcr_cassettes/play_store/subscription_purchases/permission_denied.yml +2 -2
- data/spec/fixtures/vcr_cassettes/play_store/subscription_purchases/valid_but_expired.yml +1 -1
- 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 +20 -9
- metadata +91 -63
- data/.travis.yml +0 -18
@@ -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
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::AppStore::Verification do
|
4
4
|
subject { CandyCheck::AppStore::Verification.new(endpoint, data, secret) }
|
5
|
-
let(:endpoint) {
|
6
|
-
let(:data) {
|
7
|
-
let(:secret) {
|
5
|
+
let(:endpoint) { "https://some.endpoint" }
|
6
|
+
let(:data) { "some_data" }
|
7
|
+
let(:secret) { "some_secret" }
|
8
8
|
|
9
|
-
it
|
10
|
-
with_mocked_response(
|
9
|
+
it "returns a verification failure for status != 0" do
|
10
|
+
with_mocked_response("status" => 21_000) do |client, recorded|
|
11
11
|
result = subject.call!
|
12
12
|
_(client.receipt_data).must_equal data
|
13
13
|
_(client.secret).must_equal secret
|
@@ -19,7 +19,7 @@ describe CandyCheck::AppStore::Verification do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it "returns a verification failure when receipt is missing" do
|
23
23
|
with_mocked_response({}) do |client, recorded|
|
24
24
|
result = subject.call!
|
25
25
|
_(client.receipt_data).must_equal data
|
@@ -32,20 +32,32 @@ describe CandyCheck::AppStore::Verification do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
36
|
-
response = {
|
35
|
+
it "returns a receipt when status is 0 and receipt exists" do
|
36
|
+
response = { "status" => 0, "receipt" => { "item_id" => "some_id" } }
|
37
37
|
with_mocked_response(response) do
|
38
38
|
result = subject.call!
|
39
39
|
_(result).must_be_instance_of CandyCheck::AppStore::Receipt
|
40
|
-
_(result.item_id).must_equal(
|
40
|
+
_(result.item_id).must_equal("some_id")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
|
+
let(:dummy_client_class) do
|
47
|
+
Struct.new(:response) do
|
48
|
+
attr_reader :receipt_data, :secret
|
49
|
+
|
50
|
+
def verify(receipt_data, secret)
|
51
|
+
@receipt_data = receipt_data
|
52
|
+
@secret = secret
|
53
|
+
response
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
46
58
|
def with_mocked_response(response)
|
47
59
|
recorded = []
|
48
|
-
dummy =
|
60
|
+
dummy = dummy_client_class.new(response)
|
49
61
|
stub = proc do |*args|
|
50
62
|
recorded << args
|
51
63
|
dummy
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::AppStore::Verifier do
|
4
4
|
subject { CandyCheck::AppStore::Verifier.new(config) }
|
@@ -6,32 +6,32 @@ describe CandyCheck::AppStore::Verifier do
|
|
6
6
|
CandyCheck::AppStore::Config.new(environment: environment)
|
7
7
|
end
|
8
8
|
let(:environment) { :production }
|
9
|
-
let(:data) {
|
10
|
-
let(:secret) {
|
9
|
+
let(:data) { "some_data" }
|
10
|
+
let(:secret) { "some_secret" }
|
11
11
|
let(:receipt) { CandyCheck::AppStore::Receipt.new({}) }
|
12
12
|
let(:receipt_collection) { CandyCheck::AppStore::ReceiptCollection.new({}) }
|
13
13
|
let(:production_endpoint) do
|
14
|
-
|
14
|
+
"https://buy.itunes.apple.com/verifyReceipt"
|
15
15
|
end
|
16
16
|
let(:sandbox_endpoint) do
|
17
|
-
|
17
|
+
"https://sandbox.itunes.apple.com/verifyReceipt"
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it "holds the config" do
|
21
21
|
_(subject.config).must_be_same_as config
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
24
|
+
describe "sandbox" do
|
25
25
|
let(:environment) { :sandbox }
|
26
26
|
|
27
|
-
it
|
27
|
+
it "uses sandbox endpoint without retry on success" do
|
28
28
|
with_mocked_verifier(receipt) do
|
29
29
|
_(subject.verify(data, secret)).must_be_same_as receipt
|
30
30
|
assert_recorded([sandbox_endpoint, data, secret])
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
34
|
+
it "only uses sandbox endpoint for normal failures" do
|
35
35
|
failure = get_failure(21_000)
|
36
36
|
with_mocked_verifier(failure) do
|
37
37
|
_(subject.verify(data, secret)).must_be_same_as failure
|
@@ -39,29 +39,29 @@ describe CandyCheck::AppStore::Verifier do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
42
|
+
it "retries production endpoint for redirect error" do
|
43
43
|
failure = get_failure(21_008)
|
44
44
|
with_mocked_verifier(failure, receipt) do
|
45
45
|
_(subject.verify(data, secret)).must_be_same_as receipt
|
46
46
|
assert_recorded(
|
47
47
|
[sandbox_endpoint, data, secret],
|
48
|
-
[production_endpoint, data, secret]
|
48
|
+
[production_endpoint, data, secret],
|
49
49
|
)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
54
|
+
describe "production" do
|
55
55
|
let(:environment) { :production }
|
56
56
|
|
57
|
-
it
|
57
|
+
it "uses production endpoint without retry on success" do
|
58
58
|
with_mocked_verifier(receipt) do
|
59
59
|
_(subject.verify(data, secret)).must_be_same_as receipt
|
60
60
|
assert_recorded([production_endpoint, data, secret])
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
it
|
64
|
+
it "only uses production endpoint for normal failures" do
|
65
65
|
failure = get_failure(21_000)
|
66
66
|
with_mocked_verifier(failure) do
|
67
67
|
_(subject.verify(data, secret)).must_be_same_as failure
|
@@ -69,31 +69,31 @@ describe CandyCheck::AppStore::Verifier do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
72
|
+
it "retries production endpoint for redirect error" do
|
73
73
|
failure = get_failure(21_007)
|
74
74
|
with_mocked_verifier(failure, receipt) do
|
75
75
|
_(subject.verify(data, secret)).must_be_same_as receipt
|
76
76
|
assert_recorded(
|
77
77
|
[production_endpoint, data, secret],
|
78
|
-
[sandbox_endpoint, data, secret]
|
78
|
+
[sandbox_endpoint, data, secret],
|
79
79
|
)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
describe
|
84
|
+
describe "subscription" do
|
85
85
|
let(:environment) { :production }
|
86
86
|
|
87
|
-
it
|
87
|
+
it "uses production endpoint without retry on success" do
|
88
88
|
with_mocked_verifier(receipt_collection) do
|
89
89
|
_(subject.verify_subscription(
|
90
|
-
|
91
|
-
|
90
|
+
data, secret
|
91
|
+
)).must_be_same_as receipt_collection
|
92
92
|
assert_recorded([production_endpoint, data, secret, nil])
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
it
|
96
|
+
it "only uses production endpoint for normal failures" do
|
97
97
|
failure = get_failure(21_000)
|
98
98
|
with_mocked_verifier(failure) do
|
99
99
|
_(subject.verify_subscription(data, secret)).must_be_same_as failure
|
@@ -101,23 +101,23 @@ describe CandyCheck::AppStore::Verifier do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
it
|
104
|
+
it "retries production endpoint for redirect error" do
|
105
105
|
failure = get_failure(21_007)
|
106
106
|
with_mocked_verifier(failure, receipt) do
|
107
107
|
_(subject.verify_subscription(data, secret)).must_be_same_as receipt
|
108
108
|
assert_recorded(
|
109
109
|
[production_endpoint, data, secret, nil],
|
110
|
-
[sandbox_endpoint, data, secret, nil]
|
110
|
+
[sandbox_endpoint, data, secret, nil],
|
111
111
|
)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
it
|
116
|
-
product_ids = [
|
115
|
+
it "passed the product_ids" do
|
116
|
+
product_ids = ["product_1"]
|
117
117
|
with_mocked_verifier(receipt_collection) do
|
118
118
|
_(subject.verify_subscription(
|
119
|
-
|
120
|
-
|
119
|
+
data, secret, product_ids
|
120
|
+
)).must_be_same_as receipt_collection
|
121
121
|
assert_recorded([production_endpoint, data, secret, product_ids])
|
122
122
|
end
|
123
123
|
end
|
@@ -125,15 +125,23 @@ describe CandyCheck::AppStore::Verifier do
|
|
125
125
|
|
126
126
|
private
|
127
127
|
|
128
|
-
|
128
|
+
let(:dummy_verification_class) do
|
129
|
+
Struct.new(:endpoint, :data, :secret, :product_ids) do
|
130
|
+
attr_accessor :results
|
131
|
+
|
132
|
+
def call!
|
133
|
+
results.shift
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def with_mocked_verifier(*results, &block)
|
129
139
|
@recorded ||= []
|
130
140
|
stub = proc do |*args|
|
131
141
|
@recorded << args
|
132
|
-
|
133
|
-
end
|
134
|
-
CandyCheck::AppStore::Verification.stub :new, stub do
|
135
|
-
yield
|
142
|
+
dummy_verification_class.new(*args).tap { |v| v.results = results }
|
136
143
|
end
|
144
|
+
CandyCheck::AppStore::Verification.stub :new, stub, &block
|
137
145
|
end
|
138
146
|
|
139
147
|
def assert_recorded(*calls)
|
@@ -143,20 +151,4 @@ describe CandyCheck::AppStore::Verifier do
|
|
143
151
|
def get_failure(code)
|
144
152
|
CandyCheck::AppStore::VerificationFailure.fetch(code)
|
145
153
|
end
|
146
|
-
|
147
|
-
class DummyAppStoreVerification
|
148
|
-
attr_reader :endpoint, :data, :secret, :product_ids
|
149
|
-
attr_accessor :results
|
150
|
-
|
151
|
-
def initialize(endpoint, data, secret, product_ids = nil)
|
152
|
-
@endpoint = endpoint
|
153
|
-
@data = data
|
154
|
-
@secret = secret
|
155
|
-
@product_ids = product_ids
|
156
|
-
end
|
157
|
-
|
158
|
-
def call!
|
159
|
-
results.shift
|
160
|
-
end
|
161
|
-
end
|
162
154
|
end
|
data/spec/cli/app_spec.rb
CHANGED
@@ -1,42 +1,40 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::CLI::App do
|
4
4
|
subject { CandyCheck::CLI::App.new }
|
5
5
|
|
6
|
-
it
|
6
|
+
it "supports the version command" do
|
7
7
|
stub_command(CandyCheck::CLI::Commands::Version) do
|
8
8
|
_(subject.version).must_equal :stubbed
|
9
9
|
_(@arguments).must_be_empty
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it "supports the app_store command" do
|
14
14
|
stub_command(CandyCheck::CLI::Commands::AppStore) do
|
15
|
-
_(subject.app_store(
|
16
|
-
_(@arguments).must_equal [
|
15
|
+
_(subject.app_store("receipt")).must_equal :stubbed
|
16
|
+
_(@arguments).must_equal ["receipt"]
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it "supports the play_store command" do
|
21
21
|
stub_command(CandyCheck::CLI::Commands::PlayStore) do
|
22
|
-
_(subject.play_store(
|
23
|
-
_(@arguments).must_equal
|
22
|
+
_(subject.play_store("package", "id", "token")).must_equal :stubbed
|
23
|
+
_(@arguments).must_equal %w(package id token)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it "returns true when call .exit_on_failure?" do
|
28
28
|
_(CandyCheck::CLI::App.exit_on_failure?).must_equal true
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
-
def stub_command(target)
|
33
|
+
def stub_command(target, &block)
|
34
34
|
stub = proc do |*args|
|
35
35
|
@arguments = args
|
36
36
|
:stubbed
|
37
37
|
end
|
38
|
-
target.stub :run, stub
|
39
|
-
yield
|
40
|
-
end
|
38
|
+
target.stub :run, stub, &block
|
41
39
|
end
|
42
40
|
end
|
@@ -1,56 +1,55 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::CLI::Commands::AppStore do
|
4
4
|
include WithCommand
|
5
5
|
subject { CandyCheck::CLI::Commands::AppStore }
|
6
6
|
let(:arguments) { [receipt, options] }
|
7
|
-
let(:receipt) {
|
7
|
+
let(:receipt) { "data" }
|
8
8
|
let(:options) do
|
9
9
|
{
|
10
|
-
environment: :sandbox
|
10
|
+
environment: :sandbox,
|
11
11
|
}
|
12
12
|
end
|
13
|
+
let(:dummy_verifier_class) do
|
14
|
+
Struct.new(:config) do
|
15
|
+
attr_reader :arguments
|
16
|
+
|
17
|
+
def verify(*arguments)
|
18
|
+
@arguments = arguments
|
19
|
+
{ result: :stubbed }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
13
23
|
|
14
24
|
before do
|
15
25
|
stub = proc do |*args|
|
16
|
-
@verifier =
|
26
|
+
@verifier = dummy_verifier_class.new(*args)
|
17
27
|
end
|
18
28
|
CandyCheck::AppStore::Verifier.stub :new, stub do
|
19
29
|
run_command!
|
20
30
|
end
|
21
31
|
end
|
22
32
|
|
23
|
-
describe
|
24
|
-
it
|
33
|
+
describe "default" do
|
34
|
+
it "uses the receipt and the options" do
|
25
35
|
_(@verifier.config.environment).must_equal :sandbox
|
26
36
|
_(@verifier.arguments).must_equal [receipt, nil]
|
27
|
-
_(out.lines).must_equal [
|
37
|
+
_(out.lines).must_equal ["Hash:", { result: :stubbed }]
|
28
38
|
end
|
29
39
|
end
|
30
40
|
|
31
|
-
describe
|
41
|
+
describe "with secret" do
|
32
42
|
let(:options) do
|
33
43
|
{
|
34
44
|
environment: :production,
|
35
|
-
secret:
|
45
|
+
secret: "notasecret",
|
36
46
|
}
|
37
47
|
end
|
38
48
|
|
39
|
-
it
|
49
|
+
it "uses the secret for verification" do
|
40
50
|
_(@verifier.config.environment).must_equal :production
|
41
|
-
_(@verifier.arguments).must_equal [receipt,
|
42
|
-
_(out.lines).must_equal [
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
DummyAppStoreVerifier = Struct.new(:config) do
|
49
|
-
attr_reader :arguments
|
50
|
-
|
51
|
-
def verify(*arguments)
|
52
|
-
@arguments = arguments
|
53
|
-
{ result: :stubbed }
|
51
|
+
_(@verifier.arguments).must_equal [receipt, "notasecret"]
|
52
|
+
_(out.lines).must_equal ["Hash:", { result: :stubbed }]
|
54
53
|
end
|
55
54
|
end
|
56
55
|
end
|
@@ -2,7 +2,9 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe CandyCheck::CLI::Commands::PlayStore do
|
4
4
|
include WithCommand
|
5
|
-
subject
|
5
|
+
subject do
|
6
|
+
CandyCheck::CLI::Commands::PlayStore.new(package_name, product_id, token, "json_key_file" => json_key_file)
|
7
|
+
end
|
6
8
|
let(:package_name) { "my_package_name" }
|
7
9
|
let(:product_id) { "my_product_id" }
|
8
10
|
let(:token) { "my_token" }
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::CLI::Commands::Version do
|
4
4
|
include WithCommand
|
5
5
|
subject { CandyCheck::CLI::Commands::Version }
|
6
6
|
|
7
|
-
it
|
7
|
+
it "prints the gem's version" do
|
8
8
|
run_command!
|
9
9
|
_(out.lines).must_equal [CandyCheck::VERSION]
|
10
10
|
end
|
data/spec/cli/out_spec.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CandyCheck::CLI::Out do
|
4
4
|
subject { CandyCheck::CLI::Out.new(out) }
|
5
5
|
let(:out) { StringIO.new }
|
6
6
|
|
7
|
-
it
|
7
|
+
it "defaults to use STDOUT" do
|
8
8
|
_(CandyCheck::CLI::Out.new.out).must_be_same_as $stdout
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it "holds the outlet" do
|
12
12
|
_(subject.out).must_be_same_as out
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
subject.print
|
17
|
-
subject.print
|
15
|
+
it "prints to outlet" do
|
16
|
+
subject.print "some text"
|
17
|
+
subject.print "another line"
|
18
18
|
close
|
19
19
|
_(out.readlines).must_equal [
|
20
20
|
"some text\n",
|
21
|
-
"another line\n"
|
21
|
+
"another line\n",
|
22
22
|
]
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it "pretty prints to outlet" do
|
26
26
|
subject.pretty dummy: 1
|
27
27
|
subject.pretty [1, 2, 3]
|
28
28
|
close
|
29
29
|
_(out.readlines).must_equal [
|
30
30
|
"{:dummy=>1}\n",
|
31
|
-
"[1, 2, 3]\n"
|
31
|
+
"[1, 2, 3]\n",
|
32
32
|
]
|
33
33
|
end
|
34
34
|
|
@@ -51,7 +51,7 @@ http_interactions:
|
|
51
51
|
recorded_at: Mon, 22 Jun 2020 11:38:56 GMT
|
52
52
|
- request:
|
53
53
|
method: post
|
54
|
-
uri: https://
|
54
|
+
uri: https://androidpublisher.googleapis.com/androidpublisher/v3/applications/fake_package_name/purchases/products/fake_product_id/tokens/fake_token:acknowledge
|
55
55
|
body:
|
56
56
|
encoding: UTF-8
|
57
57
|
string: ''
|
data/spec/fixtures/vcr_cassettes/play_store/product_acknowledgements/already_acknowledged.yml
CHANGED
@@ -51,7 +51,7 @@ http_interactions:
|
|
51
51
|
recorded_at: Mon, 22 Jun 2020 13:11:45 GMT
|
52
52
|
- request:
|
53
53
|
method: post
|
54
|
-
uri: https://
|
54
|
+
uri: https://androidpublisher.googleapis.com/androidpublisher/v3/applications/fake_package_name/purchases/products/fake_product_id/tokens/fake_token:acknowledge
|
55
55
|
body:
|
56
56
|
encoding: UTF-8
|
57
57
|
string: ''
|
@@ -51,7 +51,7 @@ http_interactions:
|
|
51
51
|
recorded_at: Mon, 22 Jun 2020 14:37:46 GMT
|
52
52
|
- request:
|
53
53
|
method: post
|
54
|
-
uri: https://
|
54
|
+
uri: https://androidpublisher.googleapis.com/androidpublisher/v3/applications/fake_package_name/purchases/products/fake_product_id/tokens/fake_token:acknowledge
|
55
55
|
body:
|
56
56
|
encoding: UTF-8
|
57
57
|
string: ''
|