Added customer all and get

This commit is contained in:
mathiaspalmqvist committed 2025-06-30 10:59:53 +02:00
1 parent 4a2b1b6a44
commit 410906b2cd
7 files changed
+140 -7

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
<?php
use Illuminate\Support\Facades\Http;
use Mattitja\BokioApiLaravel\BokioClient;
use Mattitja\BokioApiLaravel\Resources\Customer;
function loadFixture(string $path): array
{
$json = file_get_contents(__DIR__."/Responses/{$path}");
return json_decode($json, true);
}
beforeEach(function () {
Http::fake(function ($request) {
if ($request->method() === 'GET' && preg_match('#/customers/\w+#', $request->url())) {
return Http::response(loadFixture('Customer/get.200.json'), 200);
}
if ($request->method() === 'GET' && str_contains($request->url(), '/customers')) {
return Http::response(loadFixture('Customer/all.200.json'), 200);
}
// fallback
return Http::response([], 404);
});
$this->client = new BokioClient('fake-token', '123456');
});
it('can fetch a list of customers from Bokio', function () {
$response = (new Customer($this->client))->all();
expect($response->items)->toHaveCount(1);
expect($response->items[0]->name)->toBe('customer 1');
});
it('can fetch a single customer from Bokio', function () {
$customerId = '55c899c5-82b2-47fa-9c51-e35fc9b26443';
$response = (new Customer($this->client))->get($customerId);
expect($response->id)->toBe($customerId);
expect($response->name)->toBe('customer 1');
});
-5
View File
@@ -1,5 +0,0 @@
<?php
it('can test', function () {
expect(true)->toBeTrue();
});
+31
View File
@@ -0,0 +1,31 @@
{
"totalItems": 0,
"totalPages": 0,
"currentPage": 0,
"items": [
{
"id": "55c899c5-82b2-47fa-9c51-e35fc9b26443",
"name": "customer 1",
"type": "company",
"vatNumber": "SE1234567890",
"orgNumber": "123456-7890",
"paymentTerms": "30",
"contactsDetails": [
{
"name": "John Doe",
"email": "john@email.com",
"phone": "0927-5631505",
"isDefault": true
}
],
"address": {
"line1": "Älvsborgsvägen 10",
"line2": null,
"city": "Göteborg",
"postalCode": "123 45",
"country": "SE"
},
"language": "sv"
}
]
}
+25
View File
@@ -0,0 +1,25 @@
{
"id": "55c899c5-82b2-47fa-9c51-e35fc9b26443",
"name": "customer 1",
"type": "company",
"vatNumber": "SE1234567890",
"orgNumber": "123456-7890",
"paymentTerms": "30",
"contactsDetails": [
{
"id": "240a4af0-edfd-47b1-b4ab-f30450eaac19",
"name": "John Doe",
"email": "john@email.com",
"phone": "0927-5631505",
"isDefault": true
}
],
"address": {
"line1": "Älvsborgsvägen 10",
"line2": null,
"city": "Göteborg",
"postalCode": "123 45",
"country": "SE"
},
"language": "sv"
}