Skip to content

Commit

Permalink
Add Test for Customers API (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
maful authored Oct 26, 2021
1 parent 041622a commit 5755996
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/fixtures/customers/create.json
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": []
}
}
29 changes: 29 additions & 0 deletions test/fixtures/customers/list.json
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
}
}
13 changes: 13 additions & 0 deletions test/fixtures/customers/retrieve.json
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": []
}
}
13 changes: 13 additions & 0 deletions test/fixtures/customers/update.json
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": []
}
}
46 changes: 46 additions & 0 deletions test/versafleet/resources/customers_test.rb
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

0 comments on commit 5755996

Please sign in to comment.