-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from jaimeiniesta/customer_portal
- Loading branch information
Showing
13 changed files
with
800 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,7 @@ lemon_ex-*.tar | |
/tmp/ | ||
|
||
# ElixirLS compile folder | ||
.elixir_ls | ||
.elixir_ls | ||
|
||
# ENV vars | ||
.envrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
defmodule LemonEx.CustomersTest do | ||
use ExUnit.Case, async: false | ||
|
||
import Mock | ||
import Support.Fixtures, only: [load_json: 1] | ||
|
||
test "list" do | ||
with_mock HTTPoison, get: succesful_response("api/v1/customers_list") do | ||
assert LemonEx.Customers.list() == expected_customers_list() | ||
end | ||
end | ||
|
||
test "get" do | ||
with_mock HTTPoison, get: succesful_response("api/v1/customers_get") do | ||
assert LemonEx.Customers.get(1_406_556) == expected_customer() | ||
end | ||
end | ||
|
||
defp succesful_response(json_file) do | ||
fn _url, _params, _headers -> | ||
{:ok, | ||
%HTTPoison.Response{ | ||
status_code: 200, | ||
body: load_json(json_file) | ||
}} | ||
end | ||
end | ||
|
||
defp expected_customers_list do | ||
{ | ||
:ok, | ||
%LemonEx.PaginatedResponse{ | ||
data: [ | ||
%LemonEx.Customers.Customer{ | ||
city: nil, | ||
country: "ES", | ||
country_formatted: "Spain", | ||
created_at: "2023-10-14T17:52:43.000000Z", | ||
email: "[email protected]", | ||
id: "1406556", | ||
mrr: 3600, | ||
mrr_formatted: "$36.00", | ||
name: "Liza May", | ||
region: nil, | ||
status: "subscribed", | ||
status_formatted: "Subscribed", | ||
store_id: 48264, | ||
test_mode: true, | ||
total_revenue_currency: 0, | ||
total_revenue_currency_formatted: "$0.00", | ||
updated_at: "2023-10-14T17:52:44.000000Z", | ||
urls: %{ | ||
customer_portal: | ||
"https://mystore.lemonsqueezy.com/billing?expires=1698446369&user=1412358&signature=fed8b8bea09639c923353eeec8a5295471803f15a3bebc703b7b66bd8ebab862" | ||
} | ||
}, | ||
%LemonEx.Customers.Customer{ | ||
city: nil, | ||
country: nil, | ||
country_formatted: nil, | ||
created_at: "2023-10-14T17:35:40.000000Z", | ||
email: "[email protected]", | ||
id: "1406493", | ||
mrr: 14400, | ||
mrr_formatted: "$144.00", | ||
name: "Joe Burns", | ||
region: nil, | ||
status: "subscribed", | ||
status_formatted: "Subscribed", | ||
store_id: 48264, | ||
test_mode: true, | ||
total_revenue_currency: 0, | ||
total_revenue_currency_formatted: "$0.00", | ||
updated_at: "2023-10-27T07:32:25.000000Z", | ||
urls: %{ | ||
customer_portal: | ||
"https://mystore.lemonsqueezy.com/billing?expires=1698446369&user=1461055&signature=2b699e59adcf00238f503e722a6e8efbbba35849b47b71e6d94fcf7cce05b5f4" | ||
} | ||
} | ||
], | ||
links: %{ | ||
first: | ||
"https://api.lemonsqueezy.com/v1/customers?page%5Bnumber%5D=1&page%5Bsize%5D=10&sort=-createdAt", | ||
last: | ||
"https://api.lemonsqueezy.com/v1/customers?page%5Bnumber%5D=1&page%5Bsize%5D=10&sort=-createdAt", | ||
next: nil, | ||
prev: nil | ||
}, | ||
meta: %{ | ||
page: %{current_page: nil, from: 1, last_page: nil, per_page: nil, to: 2, total: 2} | ||
} | ||
} | ||
} | ||
end | ||
|
||
defp expected_customer() do | ||
{ | ||
:ok, | ||
%LemonEx.Customers.Customer{ | ||
city: nil, | ||
country: "ES", | ||
country_formatted: "Spain", | ||
created_at: "2023-10-14T17:52:43.000000Z", | ||
email: "[email protected]", | ||
id: "1406556", | ||
mrr: 3600, | ||
mrr_formatted: "$36.00", | ||
name: "Liza May", | ||
region: nil, | ||
status: "subscribed", | ||
status_formatted: "Subscribed", | ||
store_id: 48264, | ||
test_mode: true, | ||
total_revenue_currency: 0, | ||
total_revenue_currency_formatted: "$0.00", | ||
updated_at: "2023-10-14T17:52:44.000000Z", | ||
urls: %{ | ||
customer_portal: | ||
"https://mystore.lemonsqueezy.com/billing?expires=1698446663&user=1412358&signature=cb8dfe5c40dbec4af7082d8a1b082c07cc12d4ba0a91000d6280d2d5b9c2fdc3" | ||
} | ||
} | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
defmodule LemonEx.SubscriptionsTest do | ||
use ExUnit.Case, async: false | ||
|
||
import Mock | ||
import Support.Fixtures, only: [load_json: 1] | ||
|
||
test "list" do | ||
with_mock HTTPoison, get: succesful_response("api/v1/subscriptions_list") do | ||
assert LemonEx.Subscriptions.list() == expected_subscription_list() | ||
end | ||
end | ||
|
||
test "get" do | ||
with_mock HTTPoison, get: succesful_response("api/v1/subscriptions_get") do | ||
assert LemonEx.Subscriptions.get(169_590) == expected_subscription() | ||
end | ||
end | ||
|
||
defp succesful_response(json_file) do | ||
fn _url, _params, _headers -> | ||
{:ok, | ||
%HTTPoison.Response{ | ||
status_code: 200, | ||
body: load_json(json_file) | ||
}} | ||
end | ||
end | ||
|
||
defp expected_subscription_list do | ||
{:ok, | ||
%LemonEx.PaginatedResponse{ | ||
meta: %{ | ||
page: %{current_page: nil, from: 1, last_page: nil, per_page: nil, to: 2, total: 2} | ||
}, | ||
links: %{ | ||
first: | ||
"https:\\/\\/api.lemonsqueezy.com\\/v1\\/subscriptions?page%5Bnumber%5D=1&page%5Bsize%5D=10&sort=-createdAt", | ||
last: | ||
"https:\\/\\/api.lemonsqueezy.com\\/v1\\/subscriptions?page%5Bnumber%5D=1&page%5Bsize%5D=10&sort=-createdAt", | ||
next: nil, | ||
prev: nil | ||
}, | ||
data: [ | ||
%LemonEx.Subscriptions.Subscription{ | ||
id: "169590", | ||
store_id: 34567, | ||
order_id: 1_487_261, | ||
order_item_id: 1_450_500, | ||
product_id: 121_004, | ||
variant_id: 139_405, | ||
product_name: "App Pro", | ||
variant_name: "App Pro Monthly", | ||
user_name: "Liza May", | ||
user_email: "[email protected]", | ||
customer_id: 1_406_493, | ||
status: "active", | ||
status_formatted: "Active", | ||
pause: nil, | ||
cancelled: false, | ||
trial_ends_at: nil, | ||
billing_anchor: 27, | ||
urls: %{ | ||
customer_portal: | ||
"https:\\/\\/mystore.lemonsqueezy.com\\/billing?expires=1698434430&user=1461055&signature=27b0921cc4b6a37bc5caed624bc5dbaa44d374e26e892544421668561b8ff0f5", | ||
update_payment_method: | ||
"https:\\/\\/mystore.lemonsqueezy.com\\/subscription\\/169590\\/payment-details?expires=1698499230&signature=18cbb5bfc703292df67d0f3528e533e396115096a404bb1876c895805956a959" | ||
}, | ||
renews_at: "2023-11-27T07:32:22.000000Z", | ||
ends_at: nil, | ||
created_at: "2023-10-27T07:32:24.000000Z", | ||
updated_at: "2023-10-27T07:32:25.000000Z", | ||
test_mode: true, | ||
card_brand: "visa", | ||
card_last_four: "4242" | ||
}, | ||
%LemonEx.Subscriptions.Subscription{ | ||
id: "169586", | ||
store_id: 34567, | ||
order_id: 1_487_247, | ||
order_item_id: 1_450_485, | ||
product_id: 121_004, | ||
variant_id: 139_405, | ||
product_name: "App Pro", | ||
variant_name: "App Pro Monthly", | ||
user_name: "Liza May", | ||
user_email: "[email protected]", | ||
customer_id: 1_406_493, | ||
status: "active", | ||
status_formatted: "Active", | ||
pause: nil, | ||
cancelled: false, | ||
trial_ends_at: nil, | ||
billing_anchor: 27, | ||
urls: %{ | ||
customer_portal: | ||
"https:\\/\\/mystore.lemonsqueezy.com\\/billing?expires=1698434430&user=1461055&signature=27b0921cc4b6a37bc5caed624bc5dbaa44d374e26e892544421668561b8ff0f5", | ||
update_payment_method: | ||
"https:\\/\\/mystore.lemonsqueezy.com\\/subscription\\/169586\\/payment-details?expires=1698499230&signature=56a13a38f81e8d6592c2d28f379183add6b00f0034188437b919f97752f96ef8" | ||
}, | ||
renews_at: "2023-11-27T07:27:27.000000Z", | ||
ends_at: nil, | ||
created_at: "2023-10-27T07:27:29.000000Z", | ||
updated_at: "2023-10-27T07:27:31.000000Z", | ||
test_mode: true, | ||
card_brand: "visa", | ||
card_last_four: "4242" | ||
} | ||
] | ||
}} | ||
end | ||
|
||
defp expected_subscription() do | ||
{:ok, | ||
%LemonEx.Subscriptions.Subscription{ | ||
id: "169590", | ||
store_id: 34567, | ||
order_id: 1_487_261, | ||
order_item_id: 1_450_500, | ||
product_id: 121_004, | ||
variant_id: 139_405, | ||
product_name: "App Pro", | ||
variant_name: "App Pro Monthly", | ||
user_name: "Liza May", | ||
user_email: "[email protected]", | ||
customer_id: 1_406_493, | ||
status: "active", | ||
status_formatted: "Active", | ||
pause: nil, | ||
cancelled: false, | ||
trial_ends_at: nil, | ||
billing_anchor: 27, | ||
urls: %{ | ||
customer_portal: | ||
"https://mystore.lemonsqueezy.com/billing?expires=1698445809&user=1461055&signature=d0accab17db6cd5fbd9243dd5b57afd131972d61ad81284d26b0dbfcc5e91119", | ||
update_payment_method: | ||
"https://mystore.lemonsqueezy.com/subscription/169590/payment-details?expires=1698510609&signature=09c4d3759f6e0c5124e3ab9714e0c87ba0a9ca3f19d73d30c8f81622ac15d9f2" | ||
}, | ||
renews_at: "2023-11-27T07:32:22.000000Z", | ||
ends_at: nil, | ||
created_at: "2023-10-27T07:32:24.000000Z", | ||
updated_at: "2023-10-27T07:32:25.000000Z", | ||
test_mode: true, | ||
card_brand: "visa", | ||
card_last_four: "4242" | ||
}} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.