Skip to content

Commit

Permalink
Working + added test
Browse files Browse the repository at this point in the history
  • Loading branch information
forsbergplustwo committed Aug 26, 2023
1 parent 4234bae commit 12f88dc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/models/graphql/transactions_query.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TransactionsQuery = ShopifyPartnerAPI.client.parse <<-'GRAPHQL'
Graphql::TransactionsQuery = ShopifyPartnerAPI.client.parse <<-'GRAPHQL'
query($createdAtMin: DateTime, $cursor: String) {
transactions(createdAtMin: $createdAtMin, after: $cursor, first: 100) {
edges {
Expand Down
7 changes: 1 addition & 6 deletions app/models/payment_history/api_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def import_new_payments

created_at = Date.parse(node.created_at)

next if created_at <= last_calculated_metric_date
next if created_at <= user.calculate_from_date
charge_type = lookup_charge_type(node.__typename)
next if charge_type.nil?

Expand All @@ -86,11 +86,6 @@ def import_new_payments
payment_date: created_at
)

# STUPID: For my apps, I want Usage charges counted as "recurring" and not "one_time", others's don't
if USAGE_CHARGE_TYPES.include?(node.__typename) && user.count_usage_charges_as_recurring == true
record.charge_type = "recurring_revenue"
end

record.revenue = case node.__typename
when "ReferralAdjustment", "ReferralTransaction"
node.amount.amount
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def oldest_metric_date
end

def calculate_from_date
newest_metric_date || PaymentHistory.default_start_date
@calculate_from_date ||= newest_metric_date.presence || PaymentHistory.default_start_date
end

def clear_old_payments
Expand Down
31 changes: 31 additions & 0 deletions test/models/payment_history/api_importer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "test_helper"

class PaymentHistory::ApiImporterTest < ActiveSupport::TestCase
setup do
@user = users(:regular)
end

test "new" do
importer = PaymentHistory::ApiImporter.new(user: @user)

assert importer.user == @user
end

# test "import!" do
# # TODO: Work out how to stub the API call
# importer = PaymentHistory::ApiImporter.new(user: @user)

# assert_difference "PaymentHistory.count", X do
# importer.import!
# end
# end

test "import! fails with no api credentials" do
importer = PaymentHistory::ApiImporter.new(user: @user)

assert_raise StandardError do
importer.import!
end
end

end
4 changes: 2 additions & 2 deletions test/models/payment_history/csv_importer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PaymentHistory::CsvImporterTest < ActiveSupport::TestCase
assert importer.calculate_from_date == @user.calculate_from_date
end

test "can import csv files" do
test "import! of csv files" do
file = fixture_csv_file_for(@filename)

importer = PaymentHistory::CsvImporter.new(user: @user, filename: @filename)
Expand All @@ -27,7 +27,7 @@ class PaymentHistory::CsvImporterTest < ActiveSupport::TestCase
assert_correct_last_payment
end

test "can import zip files" do
test "import! of zip files" do
zip_file = fixture_zip_file_for(@filename)

importer = PaymentHistory::CsvImporter.new(user: @user, filename: zip_file.path)
Expand Down

0 comments on commit 12f88dc

Please sign in to comment.