-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
114 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,13 @@ | ||
{ | ||
"customer": { | ||
"id": 3, | ||
"guid": "CT336003", | ||
"name": "John", | ||
"email": "[email protected]", | ||
"contact_person": null, | ||
"contact_number": null, | ||
"logo_url": null, | ||
"archived": false, | ||
"billing_accounts": [] | ||
} | ||
} |
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,29 @@ | ||
{ | ||
"customers": [ | ||
{ | ||
"id": 1, | ||
"guid": "CT336001", | ||
"name": "Bourne", | ||
"email": "[email protected]", | ||
"contact_person": null, | ||
"contact_number": null, | ||
"logo_url": null, | ||
"archived": false | ||
}, | ||
{ | ||
"id": 2, | ||
"guid": "CT336002", | ||
"name": "Jason", | ||
"email": "[email protected]", | ||
"contact_person": "Jason", | ||
"contact_number": "+6512121212", | ||
"logo_url": null, | ||
"archived": false | ||
} | ||
], | ||
"meta": { | ||
"page": 1, | ||
"per_page": 20, | ||
"total": 2 | ||
} | ||
} |
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,13 @@ | ||
{ | ||
"customer": { | ||
"id": 1, | ||
"guid": "CT336001", | ||
"name": "Bourne", | ||
"email": "[email protected]", | ||
"contact_person": null, | ||
"contact_number": null, | ||
"logo_url": null, | ||
"archived": false, | ||
"billing_accounts": [] | ||
} | ||
} |
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,13 @@ | ||
{ | ||
"customer": { | ||
"id": 3, | ||
"guid": "CT336003", | ||
"name": "Johhny", | ||
"email": "[email protected]", | ||
"contact_person": null, | ||
"contact_number": null, | ||
"logo_url": null, | ||
"archived": false, | ||
"billing_accounts": [] | ||
} | ||
} |
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,46 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class CustomersResourceTest < Minitest::Test | ||
def test_list | ||
stub = stub_request("customers", response: stub_response(fixture: "customers/list")) | ||
client = Versafleet::Client.new(client_id: "fake", client_secret: "fake", adapter: :test, stubs: stub) | ||
customers = client.customers.list | ||
|
||
assert_equal Versafleet::Collection, customers.class | ||
assert_equal Versafleet::Customer, customers.data.first.class | ||
assert_equal 2, customers.total | ||
end | ||
|
||
def test_retrieve | ||
customer_id = 1 | ||
stub = stub_request("customers/#{customer_id}", response: stub_response(fixture: "customers/retrieve")) | ||
client = Versafleet::Client.new(client_id: "fake", client_secret: "fake", adapter: :test, stubs: stub) | ||
customer = client.customers.retrieve(customer_id: customer_id) | ||
|
||
assert_equal Versafleet::Customer, customer.class | ||
assert_equal customer_id, customer.id | ||
end | ||
|
||
def test_create | ||
body = {name: "John", email: "[email protected]"} | ||
stub = stub_request("customers", method: :post, body: {customer: body}, response: stub_response(fixture: "customers/create")) | ||
client = Versafleet::Client.new(client_id: "fake", client_secret: "fake", adapter: :test, stubs: stub) | ||
customer = client.customers.create(customer: body) | ||
|
||
assert_equal Versafleet::Customer, customer.class | ||
assert_equal body[:email], customer.email | ||
end | ||
|
||
def test_update | ||
customer_id = 3 | ||
body = {name: "Johhny"} | ||
stub = stub_request("customers/#{customer_id}", method: :put, body: {customer: body}, response: stub_response(fixture: "customers/update")) | ||
client = Versafleet::Client.new(client_id: "fake", client_secret: "fake", adapter: :test, stubs: stub) | ||
customer = client.customers.update(customer_id: customer_id, customer: body) | ||
|
||
assert_equal Versafleet::Customer, customer.class | ||
assert_equal body[:name], customer.name | ||
end | ||
end |