-
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.
adds tests for current implementation of Customers
- Loading branch information
1 parent
2880313
commit f8b71f5
Showing
3 changed files
with
303 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
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{ | ||
created_at: "2023-10-14T17:52:43.000000Z", | ||
id: "1406556", | ||
status: "subscribed", | ||
status_formatted: "Subscribed", | ||
store_id: 48264, | ||
test_mode: true, | ||
updated_at: "2023-10-14T17:52:44.000000Z", | ||
city: nil, | ||
country: "ES", | ||
country_formatted: "Spain", | ||
email: "[email protected]", | ||
mrr: 3600, | ||
mrr_formatted: "$36.00", | ||
name: "Liza May", | ||
region: nil, | ||
total_revenue_currency: 0, | ||
total_revenue_currency_formatted: "$0.00" | ||
}, | ||
%LemonEx.Customers.Customer{ | ||
created_at: "2023-10-14T17:35:40.000000Z", | ||
id: "1406493", | ||
status: "subscribed", | ||
status_formatted: "Subscribed", | ||
store_id: 48264, | ||
test_mode: true, | ||
updated_at: "2023-10-27T07:32:25.000000Z", | ||
city: nil, | ||
country: nil, | ||
country_formatted: nil, | ||
email: "[email protected]", | ||
mrr: 14400, | ||
mrr_formatted: "$144.00", | ||
name: "Joe Burns", | ||
region: nil, | ||
total_revenue_currency: 0, | ||
total_revenue_currency_formatted: "$0.00" | ||
} | ||
], | ||
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{ | ||
created_at: "2023-10-14T17:52:43.000000Z", | ||
id: "1406556", | ||
status: "subscribed", | ||
status_formatted: "Subscribed", | ||
store_id: 48264, | ||
test_mode: true, | ||
updated_at: "2023-10-14T17:52:44.000000Z", | ||
city: nil, | ||
country: "ES", | ||
country_formatted: "Spain", | ||
email: "[email protected]", | ||
mrr: 3600, | ||
mrr_formatted: "$36.00", | ||
name: "Liza May", | ||
region: nil, | ||
total_revenue_currency: 0, | ||
total_revenue_currency_formatted: "$0.00" | ||
} | ||
} | ||
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,62 @@ | ||
{ | ||
"jsonapi": { | ||
"version": "1.0" | ||
}, | ||
"links": { | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556" | ||
}, | ||
"data": { | ||
"type": "customers", | ||
"id": "1406556", | ||
"attributes": { | ||
"store_id": 48264, | ||
"name": "Liza May", | ||
"email": "[email protected]", | ||
"status": "subscribed", | ||
"city": null, | ||
"region": null, | ||
"country": "ES", | ||
"total_revenue_currency": 0, | ||
"mrr": 3600, | ||
"status_formatted": "Subscribed", | ||
"country_formatted": "Spain", | ||
"total_revenue_currency_formatted": "$0.00", | ||
"mrr_formatted": "$36.00", | ||
"urls": { | ||
"customer_portal": "https:\/\/mystore.lemonsqueezy.com\/billing?expires=1698446663&user=1412358&signature=cb8dfe5c40dbec4af7082d8a1b082c07cc12d4ba0a91000d6280d2d5b9c2fdc3" | ||
}, | ||
"created_at": "2023-10-14T17:52:43.000000Z", | ||
"updated_at": "2023-10-14T17:52:44.000000Z", | ||
"test_mode": true | ||
}, | ||
"relationships": { | ||
"store": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/store", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/relationships\/store" | ||
} | ||
}, | ||
"orders": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/orders", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/relationships\/orders" | ||
} | ||
}, | ||
"subscriptions": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/subscriptions", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/relationships\/subscriptions" | ||
} | ||
}, | ||
"license-keys": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/license-keys", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/relationships\/license-keys" | ||
} | ||
} | ||
}, | ||
"links": { | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556" | ||
} | ||
} | ||
} |
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,129 @@ | ||
{ | ||
"meta": { | ||
"page": { | ||
"currentPage": 1, | ||
"from": 1, | ||
"lastPage": 1, | ||
"perPage": 10, | ||
"to": 2, | ||
"total": 2 | ||
} | ||
}, | ||
"jsonapi": { | ||
"version": "1.0" | ||
}, | ||
"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" | ||
}, | ||
"data": [ | ||
{ | ||
"type": "customers", | ||
"id": "1406556", | ||
"attributes": { | ||
"store_id": 48264, | ||
"name": "Liza May", | ||
"email": "[email protected]", | ||
"status": "subscribed", | ||
"city": null, | ||
"region": null, | ||
"country": "ES", | ||
"total_revenue_currency": 0, | ||
"mrr": 3600, | ||
"status_formatted": "Subscribed", | ||
"country_formatted": "Spain", | ||
"total_revenue_currency_formatted": "$0.00", | ||
"mrr_formatted": "$36.00", | ||
"urls": { | ||
"customer_portal": "https:\/\/mystore.lemonsqueezy.com\/billing?expires=1698446369&user=1412358&signature=fed8b8bea09639c923353eeec8a5295471803f15a3bebc703b7b66bd8ebab862" | ||
}, | ||
"created_at": "2023-10-14T17:52:43.000000Z", | ||
"updated_at": "2023-10-14T17:52:44.000000Z", | ||
"test_mode": true | ||
}, | ||
"relationships": { | ||
"store": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/store", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/relationships\/store" | ||
} | ||
}, | ||
"orders": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/orders", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/relationships\/orders" | ||
} | ||
}, | ||
"subscriptions": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/subscriptions", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/relationships\/subscriptions" | ||
} | ||
}, | ||
"license-keys": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/license-keys", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556\/relationships\/license-keys" | ||
} | ||
} | ||
}, | ||
"links": { | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406556" | ||
} | ||
}, | ||
{ | ||
"type": "customers", | ||
"id": "1406493", | ||
"attributes": { | ||
"store_id": 48264, | ||
"name": "Joe Burns", | ||
"email": "[email protected]", | ||
"status": "subscribed", | ||
"city": null, | ||
"region": null, | ||
"country": null, | ||
"total_revenue_currency": 0, | ||
"mrr": 14400, | ||
"status_formatted": "Subscribed", | ||
"country_formatted": null, | ||
"total_revenue_currency_formatted": "$0.00", | ||
"mrr_formatted": "$144.00", | ||
"urls": { | ||
"customer_portal": "https:\/\/mystore.lemonsqueezy.com\/billing?expires=1698446369&user=1461055&signature=2b699e59adcf00238f503e722a6e8efbbba35849b47b71e6d94fcf7cce05b5f4" | ||
}, | ||
"created_at": "2023-10-14T17:35:40.000000Z", | ||
"updated_at": "2023-10-27T07:32:25.000000Z", | ||
"test_mode": true | ||
}, | ||
"relationships": { | ||
"store": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406493\/store", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406493\/relationships\/store" | ||
} | ||
}, | ||
"orders": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406493\/orders", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406493\/relationships\/orders" | ||
} | ||
}, | ||
"subscriptions": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406493\/subscriptions", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406493\/relationships\/subscriptions" | ||
} | ||
}, | ||
"license-keys": { | ||
"links": { | ||
"related": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406493\/license-keys", | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406493\/relationships\/license-keys" | ||
} | ||
} | ||
}, | ||
"links": { | ||
"self": "https:\/\/api.lemonsqueezy.com\/v1\/customers\/1406493" | ||
} | ||
} | ||
] | ||
} |