diff --git a/.rubocop.yml b/.rubocop.yml index c175484..2535525 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,10 +5,12 @@ AllCops: - 'vendor/**/*' Style/Documentation: Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/NumericPredicate: - Enabled: false +Metrics/BlockLength: + Exclude: + - 'spec/**/*' +Metrics/LineLength: + Exclude: + - 'spec/**/*' Lint/UnifiedInteger: Enabled: false Style/PercentLiteralDelimiters: diff --git a/.travis.yml b/.travis.yml index 3b54adf..bb6f1be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ + language: ruby sudo: false cache: bundler diff --git a/Gemfile b/Gemfile index f1d387a..bd2d86f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in candy_check.gemspec diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index 58f146b..f89d26f --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ #!/usr/bin/env rake +# frozen_string_literal: true require 'bundler/gem_tasks' require 'rake/testtask' diff --git a/candy_check.gemspec b/candy_check.gemspec index bf0a65a..cf4eecc 100644 --- a/candy_check.gemspec +++ b/candy_check.gemspec @@ -1,4 +1,5 @@ # coding: utf-8 +# frozen_string_literal: true lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) diff --git a/lib/candy_check.rb b/lib/candy_check.rb index ac8ff9c..bcfac86 100644 --- a/lib/candy_check.rb +++ b/lib/candy_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'candy_check/version' require 'candy_check/utils' require 'candy_check/app_store' diff --git a/lib/candy_check/app_store.rb b/lib/candy_check/app_store.rb index e4f1586..8f15933 100644 --- a/lib/candy_check/app_store.rb +++ b/lib/candy_check/app_store.rb @@ -1,9 +1,13 @@ +# frozen_string_literal: true + require 'candy_check/app_store/client' require 'candy_check/app_store/config' require 'candy_check/app_store/receipt' require 'candy_check/app_store/receipt_collection' require 'candy_check/app_store/verification' require 'candy_check/app_store/subscription_verification' +require 'candy_check/app_store/full_subscription_verification' +require 'candy_check/app_store/subscription_receipt' require 'candy_check/app_store/verification_failure' require 'candy_check/app_store/verifier' diff --git a/lib/candy_check/app_store/client.rb b/lib/candy_check/app_store/client.rb index a1b0bd0..5eba0c3 100644 --- a/lib/candy_check/app_store/client.rb +++ b/lib/candy_check/app_store/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'multi_json' require 'net/http' @@ -7,7 +9,7 @@ module AppStore # servers (either sandbox or production). class Client # Mimetype for JSON objects - JSON_MIME_TYPE = 'application/json'.freeze + JSON_MIME_TYPE = 'application/json' # Initialize a new client bound to an endpoint # @param endpoint_url [String] diff --git a/lib/candy_check/app_store/config.rb b/lib/candy_check/app_store/config.rb index 2f70c08..329bfad 100644 --- a/lib/candy_check/app_store/config.rb +++ b/lib/candy_check/app_store/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module AppStore # Configure the verifier diff --git a/lib/candy_check/app_store/full_subscription_verification.rb b/lib/candy_check/app_store/full_subscription_verification.rb new file mode 100644 index 0000000..fbb587b --- /dev/null +++ b/lib/candy_check/app_store/full_subscription_verification.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module CandyCheck + module AppStore + # Verifies a receipt and latest_receipt_info block + # The call return either a {SubscriptionReceipt} or a {VerificationFailure} + class FullSubscriptionVerification < CandyCheck::AppStore::Verification + # Performs the verification against the remote server + # @return [SubscriptionReceipt] if successful + # @return [VerificationFailure] otherwise + def call! + verify! + return VerificationFailure.fetch(@response['status']) unless valid? + subscription_receipt + end + + private + + def subscription_receipt + receipt = Receipt.new(@response['receipt']) + receipt_collection = ReceiptCollection.new( + @response['latest_receipt_info'] + ) + + SubscriptionReceipt.new(receipt, receipt_collection) + end + + def valid? + super && @response['latest_receipt_info'] + end + end + end +end diff --git a/lib/candy_check/app_store/receipt.rb b/lib/candy_check/app_store/receipt.rb index 423723d..353e22b 100644 --- a/lib/candy_check/app_store/receipt.rb +++ b/lib/candy_check/app_store/receipt.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module AppStore # Describes a successful response from the AppStore verification server diff --git a/lib/candy_check/app_store/receipt_collection.rb b/lib/candy_check/app_store/receipt_collection.rb index bcff3a3..054f653 100644 --- a/lib/candy_check/app_store/receipt_collection.rb +++ b/lib/candy_check/app_store/receipt_collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module AppStore # Store multiple {Receipt}s in order to perform collective operation on them diff --git a/lib/candy_check/app_store/subscription_receipt.rb b/lib/candy_check/app_store/subscription_receipt.rb new file mode 100644 index 0000000..818d75f --- /dev/null +++ b/lib/candy_check/app_store/subscription_receipt.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module CandyCheck + module AppStore + # Describes a successful response from the AppStore verification server + class SubscriptionReceipt + attr_reader :receipt, :receipt_collection + + # Initializes a new instance + def initialize(receipt, receipt_collection) + @receipt = receipt + @receipt_collection = receipt_collection + end + + def transactions + @receipt_collection.receipts + end + + def valid? + @receipt.is_a?(CandyCheck::AppStore::Receipt) && + @receipt_collection.is_a?(CandyCheck::AppStore::ReceiptCollection) + end + end + end +end diff --git a/lib/candy_check/app_store/subscription_verification.rb b/lib/candy_check/app_store/subscription_verification.rb index 9663639..cce180b 100644 --- a/lib/candy_check/app_store/subscription_verification.rb +++ b/lib/candy_check/app_store/subscription_verification.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module AppStore # Verifies a latest_receipt_info block against a verification server. diff --git a/lib/candy_check/app_store/verification.rb b/lib/candy_check/app_store/verification.rb index ed03727..cce8df5 100644 --- a/lib/candy_check/app_store/verification.rb +++ b/lib/candy_check/app_store/verification.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module AppStore # Verifies a receipt block against a verification server. @@ -37,8 +39,16 @@ def call! private + def response_status_ok? + @response && @response['status'] == STATUS_OK + end + + def response_has_receipt? + @response && @response['receipt'] + end + def valid? - @response && @response['status'] == STATUS_OK && @response['receipt'] + response_status_ok? && response_has_receipt? end def verify! diff --git a/lib/candy_check/app_store/verification_failure.rb b/lib/candy_check/app_store/verification_failure.rb index abc58cb..d1e0200 100644 --- a/lib/candy_check/app_store/verification_failure.rb +++ b/lib/candy_check/app_store/verification_failure.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module AppStore # Represents a failing call against the verification server @@ -64,6 +66,8 @@ def freeze! add 21_008, 'This receipt is from the production environment, but it' \ ' was sent to the test environment for verification.' \ ' Send it to the production environment instead.' + add 21_009, 'There was a problem with the (internal) receipt validation' \ + ' process. Please try again.' freeze! end end diff --git a/lib/candy_check/app_store/verifier.rb b/lib/candy_check/app_store/verifier.rb index 1ed9099..c69a0d8 100644 --- a/lib/candy_check/app_store/verifier.rb +++ b/lib/candy_check/app_store/verifier.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + module CandyCheck module AppStore # Verifies receipts against the verification servers. # The call return either an {Receipt} or a {VerificationFailure} class Verifier # HTTPS endpoint for production receipts - PRODUCTION_ENDPOINT = 'https://buy.itunes.apple.com/verifyReceipt'.freeze + PRODUCTION_ENDPOINT = 'https://buy.itunes.apple.com/verifyReceipt' # HTTPS endpoint for sandbox receipts - SANDBOX_ENDPOINT = 'https://sandbox.itunes.apple.com/verifyReceipt'.freeze + SANDBOX_ENDPOINT = 'https://sandbox.itunes.apple.com/verifyReceipt' # Status code from production endpoint when receiving a sandbox # receipt which occurs during the app's review process REDIRECT_TO_SANDBOX_CODE = 21_007 @@ -44,6 +46,16 @@ def verify_subscription(receipt_data, secret = nil) fetch_receipt_information(receipt_data, secret) end + # Calls a subscription verification for the given input + # @param receipt_data [String] the raw data to be verified + # @param secret [string] the optional shared secret + # @return [SubscriptionReceipt] if successful + # @return [VerificationFailure] otherwise + def verify_subscription_with_full_response(receipt_data, secret = nil) + @verifier = FullSubscriptionVerification + fetch_receipt_information(receipt_data, secret) + end + private def fetch_receipt_information(receipt_data, secret = nil) diff --git a/lib/candy_check/cli.rb b/lib/candy_check/cli.rb index 1e44346..eaed795 100644 --- a/lib/candy_check/cli.rb +++ b/lib/candy_check/cli.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'candy_check/cli/app' require 'candy_check/cli/commands' require 'candy_check/cli/out' diff --git a/lib/candy_check/cli/app.rb b/lib/candy_check/cli/app.rb index 6ee1ec2..cdab336 100644 --- a/lib/candy_check/cli/app.rb +++ b/lib/candy_check/cli/app.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'thor' module CandyCheck diff --git a/lib/candy_check/cli/commands.rb b/lib/candy_check/cli/commands.rb index 39907bc..c41f1fc 100644 --- a/lib/candy_check/cli/commands.rb +++ b/lib/candy_check/cli/commands.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'candy_check/cli/commands/base' require 'candy_check/cli/commands/app_store' require 'candy_check/cli/commands/play_store' diff --git a/lib/candy_check/cli/commands/app_store.rb b/lib/candy_check/cli/commands/app_store.rb index 12d43a4..83da955 100644 --- a/lib/candy_check/cli/commands/app_store.rb +++ b/lib/candy_check/cli/commands/app_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module CLI module Commands diff --git a/lib/candy_check/cli/commands/base.rb b/lib/candy_check/cli/commands/base.rb index 4f7e647..deb73ee 100644 --- a/lib/candy_check/cli/commands/base.rb +++ b/lib/candy_check/cli/commands/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module CLI module Commands diff --git a/lib/candy_check/cli/commands/play_store.rb b/lib/candy_check/cli/commands/play_store.rb index 3ea8b41..610905c 100644 --- a/lib/candy_check/cli/commands/play_store.rb +++ b/lib/candy_check/cli/commands/play_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module CLI module Commands diff --git a/lib/candy_check/cli/commands/version.rb b/lib/candy_check/cli/commands/version.rb index 464dd1c..f22b892 100644 --- a/lib/candy_check/cli/commands/version.rb +++ b/lib/candy_check/cli/commands/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module CLI module Commands diff --git a/lib/candy_check/cli/out.rb b/lib/candy_check/cli/out.rb index 24aeb38..03c8658 100644 --- a/lib/candy_check/cli/out.rb +++ b/lib/candy_check/cli/out.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pp' module CandyCheck diff --git a/lib/candy_check/play_store.rb b/lib/candy_check/play_store.rb index 3f40dde..eb39a5f 100644 --- a/lib/candy_check/play_store.rb +++ b/lib/candy_check/play_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'google/api_client' require 'candy_check/play_store/discovery_repository' diff --git a/lib/candy_check/play_store/client.rb b/lib/candy_check/play_store/client.rb index 6f6eedb..6406da9 100644 --- a/lib/candy_check/play_store/client.rb +++ b/lib/candy_check/play_store/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module PlayStore # A client which uses the official Google API SDK to authenticate @@ -15,13 +17,13 @@ class Client class DiscoveryError < RuntimeError; end # API endpoint - API_URL = 'https://accounts.google.com/o/oauth2/token'.freeze + API_URL = 'https://accounts.google.com/o/oauth2/token' # API scope for Android services - API_SCOPE = 'https://www.googleapis.com/auth/androidpublisher'.freeze + API_SCOPE = 'https://www.googleapis.com/auth/androidpublisher' # API discovery namespace - API_DISCOVER = 'androidpublisher'.freeze + API_DISCOVER = 'androidpublisher' # API version - API_VERSION = 'v2'.freeze + API_VERSION = 'v2' # Initializes a client using a configuration. # @param config [ClientConfig] diff --git a/lib/candy_check/play_store/config.rb b/lib/candy_check/play_store/config.rb index 649c755..9ad5c3f 100644 --- a/lib/candy_check/play_store/config.rb +++ b/lib/candy_check/play_store/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module PlayStore # Configure the usage of the official Google API SDK client diff --git a/lib/candy_check/play_store/discovery_repository.rb b/lib/candy_check/play_store/discovery_repository.rb index d1437b0..7d8d0d0 100644 --- a/lib/candy_check/play_store/discovery_repository.rb +++ b/lib/candy_check/play_store/discovery_repository.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module PlayStore # A file-based repository to cache a local copy of the Google API diff --git a/lib/candy_check/play_store/receipt.rb b/lib/candy_check/play_store/receipt.rb index 14d25b3..c0f2864 100644 --- a/lib/candy_check/play_store/receipt.rb +++ b/lib/candy_check/play_store/receipt.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module PlayStore # Describes a successful response from the Google verification server diff --git a/lib/candy_check/play_store/subscription.rb b/lib/candy_check/play_store/subscription.rb index 8398d00..a3239b6 100644 --- a/lib/candy_check/play_store/subscription.rb +++ b/lib/candy_check/play_store/subscription.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module PlayStore # Describes a successfully validated subscription @@ -25,17 +27,18 @@ def initialize(attributes) # Check if the expiration date is passed # @return [bool] + # rubocop:disable Style/NumericPredicate def expired? overdue_days > 0 end + # rubocop:enable Style/NumericPredicate # Check if in trial. This is actually not given by Google, but we assume # that it is a trial going on if the paid amount is 0 and # renewal is activated. # @return [bool] def trial? - price_is_zero = price_amount_micros == 0 - price_is_zero && payment_received? + price_amount_micros.zero? && payment_received? end # see if payment is ok diff --git a/lib/candy_check/play_store/subscription_verification.rb b/lib/candy_check/play_store/subscription_verification.rb index 3ecb56a..85ecc0a 100644 --- a/lib/candy_check/play_store/subscription_verification.rb +++ b/lib/candy_check/play_store/subscription_verification.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module PlayStore # Verifies a purchase token against the Google API diff --git a/lib/candy_check/play_store/verification.rb b/lib/candy_check/play_store/verification.rb index 4fe60de..fc5f961 100644 --- a/lib/candy_check/play_store/verification.rb +++ b/lib/candy_check/play_store/verification.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module PlayStore # Verifies a purchase token against the Google API diff --git a/lib/candy_check/play_store/verification_failure.rb b/lib/candy_check/play_store/verification_failure.rb index af89f88..5c44e41 100644 --- a/lib/candy_check/play_store/verification_failure.rb +++ b/lib/candy_check/play_store/verification_failure.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module PlayStore # Represents a failing call against the Google API server diff --git a/lib/candy_check/play_store/verifier.rb b/lib/candy_check/play_store/verifier.rb index 0e034c6..9793358 100644 --- a/lib/candy_check/play_store/verifier.rb +++ b/lib/candy_check/play_store/verifier.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module PlayStore # Verifies purchase tokens against the Google API. diff --git a/lib/candy_check/utils.rb b/lib/candy_check/utils.rb index f14f370..3db8007 100644 --- a/lib/candy_check/utils.rb +++ b/lib/candy_check/utils.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + require 'candy_check/utils/attribute_reader' require 'candy_check/utils/config' diff --git a/lib/candy_check/utils/attribute_reader.rb b/lib/candy_check/utils/attribute_reader.rb index ac5de3a..f02767d 100644 --- a/lib/candy_check/utils/attribute_reader.rb +++ b/lib/candy_check/utils/attribute_reader.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'date' module CandyCheck diff --git a/lib/candy_check/utils/config.rb b/lib/candy_check/utils/config.rb index 09e8794..b68297e 100644 --- a/lib/candy_check/utils/config.rb +++ b/lib/candy_check/utils/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CandyCheck module Utils # Very basic base implementation to store and validate a configuration diff --git a/lib/candy_check/version.rb b/lib/candy_check/version.rb index 5fd0163..0a495b1 100644 --- a/lib/candy_check/version.rb +++ b/lib/candy_check/version.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + module CandyCheck # The current gem's version - VERSION = '0.1.1'.freeze + VERSION = '0.1.2' end diff --git a/spec/app_store/client_spec.rb b/spec/app_store/client_spec.rb index c89f48c..0e82e00 100644 --- a/spec/app_store/client_spec.rb +++ b/spec/app_store/client_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::AppStore::Client do diff --git a/spec/app_store/config_spec.rb b/spec/app_store/config_spec.rb index a50702b..9ff8f69 100644 --- a/spec/app_store/config_spec.rb +++ b/spec/app_store/config_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::AppStore::Config do diff --git a/spec/app_store/full_subscription_verification_spec.rb b/spec/app_store/full_subscription_verification_spec.rb new file mode 100644 index 0000000..6960ab7 --- /dev/null +++ b/spec/app_store/full_subscription_verification_spec.rb @@ -0,0 +1,109 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe CandyCheck::AppStore::FullSubscriptionVerification do + subject do + CandyCheck::AppStore::FullSubscriptionVerification.new(endpoint, data, secret) + end + let(:endpoint) { 'https://some.endpoint' } + let(:data) { 'some_data' } + let(:secret) { 'some_secret' } + + it 'returns a verification failure for status != 0' do + with_mocked_response('status' => 21_000) do |client, recorded| + result = subject.call! + client.receipt_data.must_equal data + client.secret.must_equal secret + + recorded.first.must_equal [endpoint] + + result.must_be_instance_of CandyCheck::AppStore::VerificationFailure + result.code.must_equal 21_000 + end + end + + it 'returns a verification failure when receipt is missing' do + with_mocked_response({}) do |client, recorded| + result = subject.call! + client.receipt_data.must_equal data + client.secret.must_equal secret + + recorded.first.must_equal [endpoint] + + result.must_be_instance_of CandyCheck::AppStore::VerificationFailure + result.code.must_equal(-1) + end + end + + it 'returns a verification failure when status is 0 and receipt is missing' do + response = { + 'status' => 0, + 'latest_receipt_info' => [ + { 'item_id' => 'some_id' }, + { 'item_id' => 'some_other_id' } + ] + } + with_mocked_response(response) do + result = subject.call! + result.must_be_instance_of CandyCheck::AppStore::VerificationFailure + result.code.must_equal(0) + end + end + + it 'returns a verification failure when status is 0 and latest_receipt_info is missing' do + response = { + 'status' => 0, + 'receipt' => { 'item_id' => 'some_id' } + } + with_mocked_response(response) do + result = subject.call! + result.must_be_instance_of CandyCheck::AppStore::VerificationFailure + result.code.must_equal(0) + end + end + + it 'returns a struct containing a Receipt and a ReceiptCollection when status is 0 and receipt and latest_receipt_info is present' do + response = { + 'status' => 0, + 'receipt' => { 'item_id' => 'some_id' }, + 'latest_receipt_info' => [ + { 'item_id' => 'some_id' }, + { 'item_id' => 'some_other_id' } + ] + } + with_mocked_response(response) do + result = subject.call! + result.receipt_collection.must_be_instance_of CandyCheck::AppStore::ReceiptCollection + result.receipt_collection.receipts.must_be_instance_of Array + last = result.receipt_collection.receipts.last + last.must_be_instance_of CandyCheck::AppStore::Receipt + last.item_id.must_equal('some_other_id') + result.receipt.must_be_instance_of CandyCheck::AppStore::Receipt + end + end + + private + + DummyClient = Struct.new(:response) do + attr_reader :receipt_data, :secret + + def verify(receipt_data, secret) + @receipt_data = receipt_data + @secret = secret + response + end + end + + def with_mocked_response(response) + recorded = [] + dummy = DummyClient.new(response) + stub = proc do |*args| + recorded << args + dummy + end + CandyCheck::AppStore::Client.stub :new, stub do + yield dummy, recorded + end + end +end diff --git a/spec/app_store/receipt_collection_spec.rb b/spec/app_store/receipt_collection_spec.rb index 11af43b..77d4c59 100644 --- a/spec/app_store/receipt_collection_spec.rb +++ b/spec/app_store/receipt_collection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::AppStore::ReceiptCollection do @@ -26,7 +28,7 @@ it 'has positive overdue days' do overdue = subject.overdue_days - overdue.must_be_instance_of Fixnum + overdue.is_a?(Integer).must_be_true assert overdue > 0 end diff --git a/spec/app_store/receipt_spec.rb b/spec/app_store/receipt_spec.rb index 2ebe025..273241a 100644 --- a/spec/app_store/receipt_spec.rb +++ b/spec/app_store/receipt_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::AppStore::Receipt do diff --git a/spec/app_store/subscription_verification_spec.rb b/spec/app_store/subscription_verification_spec.rb index 2683eab..3e0623c 100644 --- a/spec/app_store/subscription_verification_spec.rb +++ b/spec/app_store/subscription_verification_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::AppStore::SubscriptionVerification do diff --git a/spec/app_store/verifcation_failure_spec.rb b/spec/app_store/verifcation_failure_spec.rb index 800587b..a0293ce 100644 --- a/spec/app_store/verifcation_failure_spec.rb +++ b/spec/app_store/verifcation_failure_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::AppStore::VerificationFailure do diff --git a/spec/app_store/verification_spec.rb b/spec/app_store/verification_spec.rb index c6b102e..e0132cb 100644 --- a/spec/app_store/verification_spec.rb +++ b/spec/app_store/verification_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::AppStore::Verification do diff --git a/spec/app_store/verifier_spec.rb b/spec/app_store/verifier_spec.rb index 01a4ec8..df32ab5 100644 --- a/spec/app_store/verifier_spec.rb +++ b/spec/app_store/verifier_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::AppStore::Verifier do @@ -113,6 +115,38 @@ end end + describe 'subscription' do + let(:environment) { :production } + + it 'uses production endpoint without retry on success' do + with_mocked_verifier(receipt_collection) do + subject.verify_subscription_with_full_response( + data, secret + ).must_be_same_as receipt_collection + assert_recorded([production_endpoint, data, secret]) + end + end + + it 'only uses production endpoint for normal failures' do + failure = get_failure(21_000) + with_mocked_verifier(failure) do + subject.verify_subscription_with_full_response(data, secret).must_be_same_as failure + assert_recorded([production_endpoint, data, secret]) + end + end + + it 'retries production endpoint for redirect error' do + failure = get_failure(21_007) + with_mocked_verifier(failure, receipt) do + subject.verify_subscription_with_full_response(data, secret).must_be_same_as receipt + assert_recorded( + [production_endpoint, data, secret], + [sandbox_endpoint, data, secret] + ) + end + end + end + private def with_mocked_verifier(*results) diff --git a/spec/candy_check_spec.rb b/spec/candy_check_spec.rb index c5a0c6f..2b1c139 100644 --- a/spec/candy_check_spec.rb +++ b/spec/candy_check_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck do diff --git a/spec/cli/app_spec.rb b/spec/cli/app_spec.rb index 7e81bbe..1e5580b 100644 --- a/spec/cli/app_spec.rb +++ b/spec/cli/app_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::CLI::App do diff --git a/spec/cli/commands/app_store_spec.rb b/spec/cli/commands/app_store_spec.rb index 9cfdb89..092ed23 100644 --- a/spec/cli/commands/app_store_spec.rb +++ b/spec/cli/commands/app_store_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::CLI::Commands::AppStore do diff --git a/spec/cli/commands/play_store_spec.rb b/spec/cli/commands/play_store_spec.rb index 6680f45..a1ee7d3 100644 --- a/spec/cli/commands/play_store_spec.rb +++ b/spec/cli/commands/play_store_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::CLI::Commands::PlayStore do diff --git a/spec/cli/commands/version_spec.rb b/spec/cli/commands/version_spec.rb index b45a0e4..2941e34 100644 --- a/spec/cli/commands/version_spec.rb +++ b/spec/cli/commands/version_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::CLI::Commands::Version do diff --git a/spec/cli/out_spec.rb b/spec/cli/out_spec.rb index bf85b08..ec4c396 100644 --- a/spec/cli/out_spec.rb +++ b/spec/cli/out_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::CLI::Out do diff --git a/spec/play_store/client_spec.rb b/spec/play_store/client_spec.rb index f5b97a2..9f3b4b6 100644 --- a/spec/play_store/client_spec.rb +++ b/spec/play_store/client_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::PlayStore::Client do diff --git a/spec/play_store/config_spec.rb b/spec/play_store/config_spec.rb index b4c43a4..15948a7 100644 --- a/spec/play_store/config_spec.rb +++ b/spec/play_store/config_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::PlayStore::Config do diff --git a/spec/play_store/discovery_respository_spec.rb b/spec/play_store/discovery_respository_spec.rb index c30f40a..2a337e4 100644 --- a/spec/play_store/discovery_respository_spec.rb +++ b/spec/play_store/discovery_respository_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::PlayStore::DiscoveryRepository do diff --git a/spec/play_store/receipt_spec.rb b/spec/play_store/receipt_spec.rb index 54d2ff0..55e5e36 100644 --- a/spec/play_store/receipt_spec.rb +++ b/spec/play_store/receipt_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::PlayStore::Receipt do diff --git a/spec/play_store/subscription_spec.rb b/spec/play_store/subscription_spec.rb index 0b210db..6850874 100644 --- a/spec/play_store/subscription_spec.rb +++ b/spec/play_store/subscription_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::PlayStore::Subscription do @@ -46,11 +48,11 @@ end it 'returns the start_time_millis' do - subject.start_time_millis.must_equal 145_954_011_324_4 + subject.start_time_millis.must_equal 1_459_540_113_244 end it 'returns the expiry_time_millis' do - subject.expiry_time_millis.must_equal 146_213_208_861_0 + subject.expiry_time_millis.must_equal 1_462_132_088_610 end it 'returns the starts_at' do diff --git a/spec/play_store/subscription_verification_spec.rb b/spec/play_store/subscription_verification_spec.rb index 496b2e3..0cff712 100644 --- a/spec/play_store/subscription_verification_spec.rb +++ b/spec/play_store/subscription_verification_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::PlayStore::SubscriptionVerification do diff --git a/spec/play_store/verification_failure_spec.rb b/spec/play_store/verification_failure_spec.rb index 4b3ba46..f3dd316 100644 --- a/spec/play_store/verification_failure_spec.rb +++ b/spec/play_store/verification_failure_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::PlayStore::VerificationFailure do diff --git a/spec/play_store/verification_spec.rb b/spec/play_store/verification_spec.rb index c469b8f..ea22a3e 100644 --- a/spec/play_store/verification_spec.rb +++ b/spec/play_store/verification_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::PlayStore::Verification do diff --git a/spec/play_store/verifier_spec.rb b/spec/play_store/verifier_spec.rb index a62e318..4b67025 100644 --- a/spec/play_store/verifier_spec.rb +++ b/spec/play_store/verifier_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CandyCheck::PlayStore::Verifier do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f0c7f22..5c1a4a1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'coveralls' Coveralls.wear!