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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +1 -0
  3. data/.rubocop.yml +10 -0
  4. data/.ruby-version +1 -1
  5. data/Gemfile +1 -1
  6. data/Guardfile +5 -3
  7. data/Rakefile +5 -5
  8. data/candy_check.gemspec +10 -10
  9. data/lib/candy_check/app_store/client.rb +7 -7
  10. data/lib/candy_check/app_store/config.rb +7 -9
  11. data/lib/candy_check/app_store/receipt.rb +16 -16
  12. data/lib/candy_check/app_store/receipt_collection.rb +2 -2
  13. data/lib/candy_check/app_store/subscription_verification.rb +5 -5
  14. data/lib/candy_check/app_store/verification.rb +3 -3
  15. data/lib/candy_check/app_store/verification_failure.rb +25 -21
  16. data/lib/candy_check/app_store/verifier.rb +4 -5
  17. data/lib/candy_check/app_store.rb +8 -8
  18. data/lib/candy_check/cli/app.rb +1 -1
  19. data/lib/candy_check/cli/commands/app_store.rb +1 -1
  20. data/lib/candy_check/cli/commands.rb +4 -4
  21. data/lib/candy_check/cli/out.rb +1 -3
  22. data/lib/candy_check/cli.rb +3 -3
  23. data/lib/candy_check/play_store/product_acknowledgements/acknowledgement.rb +2 -1
  24. data/lib/candy_check/play_store/product_purchases/product_purchase.rb +3 -3
  25. data/lib/candy_check/play_store/product_purchases/product_verification.rb +1 -1
  26. data/lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb +2 -1
  27. data/lib/candy_check/play_store/subscription_purchases/subscription_verification.rb +1 -0
  28. data/lib/candy_check/play_store/verification_failure.rb +2 -2
  29. data/lib/candy_check/utils/attribute_reader.rb +3 -2
  30. data/lib/candy_check/utils/config.rb +2 -0
  31. data/lib/candy_check/utils.rb +2 -2
  32. data/lib/candy_check/version.rb +1 -1
  33. data/lib/candy_check.rb +4 -4
  34. data/spec/app_store/client_spec.rb +18 -18
  35. data/spec/app_store/config_spec.rb +9 -9
  36. data/spec/app_store/receipt_collection_spec.rb +38 -40
  37. data/spec/app_store/receipt_spec.rb +47 -47
  38. data/spec/app_store/subscription_verification_spec.rb +35 -32
  39. data/spec/app_store/verifcation_failure_spec.rb +7 -7
  40. data/spec/app_store/verification_spec.rb +23 -11
  41. data/spec/app_store/verifier_spec.rb +40 -48
  42. data/spec/cli/app_spec.rb +11 -13
  43. data/spec/cli/commands/app_store_spec.rb +22 -23
  44. data/spec/cli/commands/play_store_spec.rb +3 -1
  45. data/spec/cli/commands/version_spec.rb +2 -2
  46. data/spec/cli/out_spec.rb +9 -9
  47. data/spec/play_store/acknowledger_spec.rb +4 -0
  48. data/spec/play_store/product_acknowledgements/acknowledgement_spec.rb +4 -0
  49. data/spec/play_store/product_acknowledgements/response_spec.rb +16 -15
  50. data/spec/play_store/product_purchases/product_purchase_spec.rb +6 -27
  51. data/spec/play_store/subscription_purchases/subscription_purchase_spec.rb +22 -46
  52. data/spec/play_store/verification_failure_spec.rb +6 -4
  53. data/spec/play_store/verifier_spec.rb +4 -2
  54. data/spec/spec_helper.rb +5 -7
  55. metadata +76 -76
@@ -1,13 +1,13 @@
1
- require 'spec_helper'
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) { 'https://some.endpoint' }
6
- let(:data) { 'some_data' }
7
- let(:secret) { 'some_secret' }
5
+ let(:endpoint) { "https://some.endpoint" }
6
+ let(:data) { "some_data" }
7
+ let(:secret) { "some_secret" }
8
8
 
9
- it 'returns a verification failure for status != 0' do
10
- with_mocked_response('status' => 21_000) do |client, recorded|
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 'returns a verification failure when receipt is missing' do
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 'returns a receipt when status is 0 and receipt exists' do
36
- response = { 'status' => 0, 'receipt' => { 'item_id' => 'some_id' } }
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('some_id')
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 = DummyClient.new(response)
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 'spec_helper'
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) { 'some_data' }
10
- let(:secret) { 'some_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
- 'https://buy.itunes.apple.com/verifyReceipt'
14
+ "https://buy.itunes.apple.com/verifyReceipt"
15
15
  end
16
16
  let(:sandbox_endpoint) do
17
- 'https://sandbox.itunes.apple.com/verifyReceipt'
17
+ "https://sandbox.itunes.apple.com/verifyReceipt"
18
18
  end
19
19
 
20
- it 'holds the config' do
20
+ it "holds the config" do
21
21
  _(subject.config).must_be_same_as config
22
22
  end
23
23
 
24
- describe 'sandbox' do
24
+ describe "sandbox" do
25
25
  let(:environment) { :sandbox }
26
26
 
27
- it 'uses sandbox endpoint without retry on success' do
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 'only uses sandbox endpoint for normal failures' do
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 'retries production endpoint for redirect error' do
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 'production' do
54
+ describe "production" do
55
55
  let(:environment) { :production }
56
56
 
57
- it 'uses production endpoint without retry on success' do
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 'only uses production endpoint for normal failures' do
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 'retries production endpoint for redirect error' do
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 'subscription' do
84
+ describe "subscription" do
85
85
  let(:environment) { :production }
86
86
 
87
- it 'uses production endpoint without retry on success' do
87
+ it "uses production endpoint without retry on success" do
88
88
  with_mocked_verifier(receipt_collection) do
89
89
  _(subject.verify_subscription(
90
- data, secret
91
- )).must_be_same_as receipt_collection
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 'only uses production endpoint for normal failures' do
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 'retries production endpoint for redirect error' do
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 'passed the product_ids' do
116
- product_ids = ['product_1']
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
- data, secret, product_ids
120
- )).must_be_same_as receipt_collection
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
- def with_mocked_verifier(*results)
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
- DummyAppStoreVerification.new(*args).tap { |v| v.results = results }
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 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe CandyCheck::CLI::App do
4
4
  subject { CandyCheck::CLI::App.new }
5
5
 
6
- it 'supports the version command' do
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 'supports the app_store command' do
13
+ it "supports the app_store command" do
14
14
  stub_command(CandyCheck::CLI::Commands::AppStore) do
15
- _(subject.app_store('receipt')).must_equal :stubbed
16
- _(@arguments).must_equal ['receipt']
15
+ _(subject.app_store("receipt")).must_equal :stubbed
16
+ _(@arguments).must_equal ["receipt"]
17
17
  end
18
18
  end
19
19
 
20
- it 'supports the play_store command' do
20
+ it "supports the play_store command" do
21
21
  stub_command(CandyCheck::CLI::Commands::PlayStore) do
22
- _(subject.play_store('package', 'id', 'token')).must_equal :stubbed
23
- _(@arguments).must_equal ['package', 'id', 'token']
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 'returns true when call .exit_on_failure?' do
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 do
39
- yield
40
- end
38
+ target.stub :run, stub, &block
41
39
  end
42
40
  end
@@ -1,56 +1,55 @@
1
- require 'spec_helper'
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) { 'data' }
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 = DummyAppStoreVerifier.new(*args)
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 'default' do
24
- it 'uses the receipt and the options' do
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 ['Hash:', { result: :stubbed }]
37
+ _(out.lines).must_equal ["Hash:", { result: :stubbed }]
28
38
  end
29
39
  end
30
40
 
31
- describe 'with secret' do
41
+ describe "with secret" do
32
42
  let(:options) do
33
43
  {
34
44
  environment: :production,
35
- secret: 'notasecret'
45
+ secret: "notasecret",
36
46
  }
37
47
  end
38
48
 
39
- it 'uses the secret for verification' do
49
+ it "uses the secret for verification" do
40
50
  _(@verifier.config.environment).must_equal :production
41
- _(@verifier.arguments).must_equal [receipt, 'notasecret']
42
- _(out.lines).must_equal ['Hash:', { result: :stubbed }]
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 { CandyCheck::CLI::Commands::PlayStore.new(package_name, product_id, token, "json_key_file" => json_key_file) }
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 'spec_helper'
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 'prints the gem\'s version' do
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 'spec_helper'
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 'defaults to use STDOUT' do
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 'holds the outlet' do
11
+ it "holds the outlet" do
12
12
  _(subject.out).must_be_same_as out
13
13
  end
14
14
 
15
- it 'prints to outlet' do
16
- subject.print 'some text'
17
- subject.print 'another line'
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 'pretty prints to outlet' do
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
 
@@ -21,7 +21,9 @@ describe CandyCheck::PlayStore::Acknowledger do
21
21
  end
22
22
  end
23
23
  it "when already acknowledged" do
24
+ # rubocop:disable Layout/LineLength
24
25
  error_body = "{\n \"error\": {\n \"code\": 400,\n \"message\": \"The purchase is not in a valid state to perform the desired operation.\",\n \"errors\": [\n {\n \"message\": \"The purchase is not in a valid state to perform the desired operation.\",\n \"domain\": \"androidpublisher\",\n \"reason\": \"invalidPurchaseState\",\n \"location\": \"token\",\n \"locationType\": \"parameter\"\n }\n ]\n }\n}\n"
26
+ # rubocop:enable Layout/LineLength
25
27
 
26
28
  VCR.use_cassette("play_store/product_acknowledgements/already_acknowledged") do
27
29
  result = subject.acknowledge_product_purchase(package_name: package_name, product_id: product_id, token: token)
@@ -33,7 +35,9 @@ describe CandyCheck::PlayStore::Acknowledger do
33
35
  end
34
36
  end
35
37
  it "when it has been refunded" do
38
+ # rubocop:disable Layout/LineLength
36
39
  error_body = "{\n \"error\": {\n \"code\": 400,\n \"message\": \"The product purchase is not owned by the user.\",\n \"errors\": [\n {\n \"message\": \"The product purchase is not owned by the user.\",\n \"domain\": \"androidpublisher\",\n \"reason\": \"productNotOwnedByUser\"\n }\n ]\n }\n}\n"
40
+ # rubocop:enable Layout/LineLength
37
41
 
38
42
  VCR.use_cassette("play_store/product_acknowledgements/refunded") do
39
43
  result = subject.acknowledge_product_purchase(package_name: package_name, product_id: product_id, token: token)
@@ -27,7 +27,9 @@ describe CandyCheck::PlayStore::ProductAcknowledgements::Acknowledgement do
27
27
  end
28
28
  end
29
29
  it "when already acknowledged" do
30
+ # rubocop:disable Layout/LineLength
30
31
  error_body = "{\n \"error\": {\n \"code\": 400,\n \"message\": \"The purchase is not in a valid state to perform the desired operation.\",\n \"errors\": [\n {\n \"message\": \"The purchase is not in a valid state to perform the desired operation.\",\n \"domain\": \"androidpublisher\",\n \"reason\": \"invalidPurchaseState\",\n \"location\": \"token\",\n \"locationType\": \"parameter\"\n }\n ]\n }\n}\n"
32
+ # rubocop:enable Layout/LineLength
31
33
 
32
34
  VCR.use_cassette("play_store/product_acknowledgements/already_acknowledged") do
33
35
  result = subject.call!
@@ -39,7 +41,9 @@ describe CandyCheck::PlayStore::ProductAcknowledgements::Acknowledgement do
39
41
  end
40
42
  end
41
43
  it "when it has been refunded" do
44
+ # rubocop:disable Layout/LineLength
42
45
  error_body = "{\n \"error\": {\n \"code\": 400,\n \"message\": \"The product purchase is not owned by the user.\",\n \"errors\": [\n {\n \"message\": \"The product purchase is not owned by the user.\",\n \"domain\": \"androidpublisher\",\n \"reason\": \"productNotOwnedByUser\"\n }\n ]\n }\n}\n"
46
+ # rubocop:enable Layout/LineLength
43
47
 
44
48
  VCR.use_cassette("play_store/product_acknowledgements/refunded") do
45
49
  result = subject.call!
@@ -5,23 +5,23 @@ describe CandyCheck::PlayStore::ProductAcknowledgements::Response do
5
5
  CandyCheck::PlayStore::ProductAcknowledgements::Response.new(result: result, error_data: error_data)
6
6
  end
7
7
 
8
- describe '#acknowledged?' do
9
- context 'when result present' do
10
- let(:result) { '' }
8
+ describe "#acknowledged?" do
9
+ context "when result present" do
10
+ let(:result) { "" }
11
11
  let(:error_data) { nil }
12
12
 
13
- it 'returns true' do
13
+ it "returns true" do
14
14
  result = subject.acknowledged?
15
15
 
16
16
  _(result).must_be_true
17
17
  end
18
18
  end
19
19
 
20
- context 'when result is not present' do
20
+ context "when result is not present" do
21
21
  let(:result) { nil }
22
- let(:error_data) { nil }
22
+ let(:error_data) { nil }
23
23
 
24
- it 'returns false' do
24
+ it "returns false" do
25
25
  result = subject.acknowledged?
26
26
 
27
27
  _(result).must_be_false
@@ -29,34 +29,35 @@ describe CandyCheck::PlayStore::ProductAcknowledgements::Response do
29
29
  end
30
30
  end
31
31
 
32
- describe '#error' do
33
- context 'when error present' do
32
+ describe "#error" do
33
+ context "when error present" do
34
34
  let(:result) { nil }
35
35
  let(:error_data) do
36
36
  Module.new do
37
37
  def status_code
38
38
  400
39
39
  end
40
+
40
41
  def body
41
- 'A String describing the issue'
42
+ "A String describing the issue"
42
43
  end
43
44
  module_function :status_code, :body
44
45
  end
45
46
  end
46
47
 
47
- it 'returns the expected data' do
48
+ it "returns the expected data" do
48
49
  result = subject.error
49
50
 
50
51
  _(result[:status_code]).must_equal(400)
51
- _(result[:body]).must_equal('A String describing the issue')
52
+ _(result[:body]).must_equal("A String describing the issue")
52
53
  end
53
54
  end
54
55
 
55
- context 'when error is not present' do
56
- let(:result) { '' }
56
+ context "when error is not present" do
57
+ let(:result) { "" }
57
58
  let(:error_data) { nil }
58
59
 
59
- it 'returns false' do
60
+ it "returns false" do
60
61
  result = subject.error
61
62
 
62
63
  _(result).must_be_nil
@@ -5,13 +5,13 @@ describe CandyCheck::PlayStore::ProductPurchases::ProductPurchase do
5
5
 
6
6
  describe "valid and non-consumed product" do
7
7
  let(:fake_product_purchase) do
8
- FakeProductPurchase.new(
8
+ OpenStruct.new(
9
9
  consumption_state: 0,
10
10
  developer_payload: "payload that gets stored and returned",
11
11
  kind: "androidpublisher#productPurchase",
12
12
  order_id: "ABC123",
13
13
  purchase_state: 0,
14
- purchase_time_millis: 1421676237413,
14
+ purchase_time_millis: 1_421_676_237_413,
15
15
  )
16
16
  end
17
17
 
@@ -51,13 +51,13 @@ describe CandyCheck::PlayStore::ProductPurchases::ProductPurchase do
51
51
 
52
52
  describe "valid and consumed product" do
53
53
  let(:fake_product_purchase) do
54
- FakeProductPurchase.new(
54
+ OpenStruct.new(
55
55
  consumption_state: 1,
56
56
  developer_payload: "payload that gets stored and returned",
57
57
  kind: "androidpublisher#productPurchase",
58
58
  order_id: "ABC123",
59
59
  purchase_state: 0,
60
- purchase_time_millis: 1421676237413,
60
+ purchase_time_millis: 1_421_676_237_413,
61
61
  )
62
62
  end
63
63
 
@@ -72,13 +72,13 @@ describe CandyCheck::PlayStore::ProductPurchases::ProductPurchase do
72
72
 
73
73
  describe "non-valid product" do
74
74
  let(:fake_product_purchase) do
75
- FakeProductPurchase.new(
75
+ OpenStruct.new(
76
76
  consumption_state: 0,
77
77
  developer_payload: "payload that gets stored and returned",
78
78
  kind: "androidpublisher#productPurchase",
79
79
  order_id: "ABC123",
80
80
  purchase_state: 1,
81
- purchase_time_millis: 1421676237413,
81
+ purchase_time_millis: 1_421_676_237_413,
82
82
  )
83
83
  end
84
84
 
@@ -86,25 +86,4 @@ describe CandyCheck::PlayStore::ProductPurchases::ProductPurchase do
86
86
  _(subject.valid?).must_be_false
87
87
  end
88
88
  end
89
-
90
- private
91
-
92
- class FakeProductPurchase
93
- FIELDS = [
94
- :consumption_state,
95
- :developer_payload,
96
- :kind,
97
- :order_id,
98
- :purchase_state,
99
- :purchase_time_millis,
100
- ].freeze
101
-
102
- attr_accessor(*FIELDS)
103
-
104
- def initialize(hash)
105
- FIELDS.each do |key|
106
- self.public_send("#{key}=", hash[key])
107
- end
108
- end
109
- end
110
89
  end