Update Tiers functionality and enhance API documentation
- Changed the default value of the `$select` property in Tiers.php from `custid,custname` to `custid,name` to reflect valid column names. - Updated the tiers.blade.php view to align the placeholder for the select field with the new default value. - Enhanced the documentation for the `third_list` and `third_GetArtHistory` endpoints, detailing valid search columns, metadata, and response structures. - Added new tests in TiersPageTest.php to verify the default select value, API parameter handling, and metadata storage. - Overall, improved the user experience and API interaction for managing tiers.
This commit is contained in:
@@ -32,6 +32,11 @@ it('can switch between read and write modes', function () {
|
||||
->assertSet('mode', 'read');
|
||||
});
|
||||
|
||||
it('has correct default select value', function () {
|
||||
Livewire::test(Tiers::class)
|
||||
->assertSet('select', 'custid,name');
|
||||
});
|
||||
|
||||
it('shows validation error when search is empty', function () {
|
||||
Http::fake();
|
||||
|
||||
@@ -46,23 +51,48 @@ it('shows validation error when search is empty', function () {
|
||||
it('searches tiers via third_list', function () {
|
||||
Http::fake([
|
||||
'*/third_list' => Http::response([
|
||||
'data' => [['custid' => 'CUST001', 'custname' => 'Client Test']],
|
||||
'metadata' => ['rowcount' => 1, 'issuccess' => true],
|
||||
'data' => [['custid' => '0100002174', 'name' => 'ESI SPRL']],
|
||||
'metadata' => ['rowCount' => 1, 'source' => 'DBF', 'executionTimeMs' => 112, 'searchColumns' => 'name,groupid,vat', 'selectColumns' => 'custid,name', 'searchTerms' => 'ESI'],
|
||||
'error' => null,
|
||||
]),
|
||||
]);
|
||||
|
||||
Livewire::test(Tiers::class)
|
||||
->set('search', 'ESI')
|
||||
->set('select', 'custid,name')
|
||||
->call('searchTiers')
|
||||
->assertSet('hasSearched', true)
|
||||
->assertSet('data', [['custid' => '0100002174', 'name' => 'ESI SPRL']])
|
||||
->assertSet('errorMessage', null);
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return str_contains($request->url(), 'third_list')
|
||||
&& $request->data()['search'] === 'ESI';
|
||||
});
|
||||
});
|
||||
|
||||
it('sends select and results parameters to third_list', function () {
|
||||
Http::fake([
|
||||
'*/third_list' => Http::response([
|
||||
'data' => [['custid' => '0100002174', 'name' => 'ESI SPRL']],
|
||||
'metadata' => ['rowCount' => 1, 'source' => 'DBF', 'executionTimeMs' => 100, 'searchColumns' => 'name,groupid,vat', 'selectColumns' => 'custid,name', 'searchTerms' => 'test'],
|
||||
'error' => null,
|
||||
]),
|
||||
]);
|
||||
|
||||
Livewire::test(Tiers::class)
|
||||
->set('search', 'test')
|
||||
->set('select', 'custid,custname')
|
||||
->call('searchTiers')
|
||||
->assertSet('hasSearched', true)
|
||||
->assertSet('data', [['custid' => 'CUST001', 'custname' => 'Client Test']])
|
||||
->assertSet('errorMessage', null);
|
||||
->set('select', 'custid,name,vat')
|
||||
->set('results', 20)
|
||||
->call('searchTiers');
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
$data = $request->data();
|
||||
|
||||
return str_contains($request->url(), 'third_list')
|
||||
&& $request->data()['search'] === 'test';
|
||||
&& $data['search'] === 'test'
|
||||
&& $data['select'] === 'custid,name,vat'
|
||||
&& $data['results'] === 20;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -70,7 +100,7 @@ it('sets hasSearched even when no results', function () {
|
||||
Http::fake([
|
||||
'*/third_list' => Http::response([
|
||||
'data' => [],
|
||||
'metadata' => ['rowcount' => 0, 'issuccess' => true],
|
||||
'metadata' => ['rowCount' => 0, 'source' => 'DBF', 'executionTimeMs' => 100, 'searchColumns' => 'name,groupid,vat', 'selectColumns' => 'custid,name', 'searchTerms' => 'nonexistent'],
|
||||
'error' => null,
|
||||
]),
|
||||
]);
|
||||
@@ -82,6 +112,22 @@ it('sets hasSearched even when no results', function () {
|
||||
->assertSet('data', []);
|
||||
});
|
||||
|
||||
it('stores metadata from third_list response', function () {
|
||||
Http::fake([
|
||||
'*/third_list' => Http::response([
|
||||
'data' => [['custid' => '0100002174', 'name' => 'ESI SPRL']],
|
||||
'metadata' => ['rowCount' => 1, 'source' => 'DBF', 'executionTimeMs' => 112, 'searchColumns' => 'name,groupid,vat', 'selectColumns' => 'custid,name', 'searchTerms' => 'ESI'],
|
||||
'error' => null,
|
||||
]),
|
||||
]);
|
||||
|
||||
Livewire::test(Tiers::class)
|
||||
->set('search', 'ESI')
|
||||
->call('searchTiers')
|
||||
->assertSet('metadata.rowCount', 1)
|
||||
->assertSet('metadata.searchColumns', 'name,groupid,vat');
|
||||
});
|
||||
|
||||
it('shows validation error when historyThirdId is empty', function () {
|
||||
Http::fake();
|
||||
|
||||
@@ -96,8 +142,19 @@ it('shows validation error when historyThirdId is empty', function () {
|
||||
it('gets art history for a third party', function () {
|
||||
Http::fake([
|
||||
'*/third_GetArtHistory' => Http::response([
|
||||
'data' => [['artid' => 'ART001', 'qty' => 5]],
|
||||
'metadata' => ['rowcount' => 1, 'issuccess' => true],
|
||||
'data' => [
|
||||
[
|
||||
'artid' => 'ART001',
|
||||
'artname' => 'Article Test',
|
||||
'jnl' => '03VEN',
|
||||
'unitprice' => 220,
|
||||
'qty' => 1,
|
||||
'vatid' => '21',
|
||||
'vatpc' => 21,
|
||||
's_credate' => '2025-06-03',
|
||||
],
|
||||
],
|
||||
'metadata' => ['rowCount' => 1, 'source' => 'DBF'],
|
||||
'error' => null,
|
||||
]),
|
||||
]);
|
||||
@@ -106,23 +163,101 @@ it('gets art history for a third party', function () {
|
||||
->set('historyThirdId', 'CUST001')
|
||||
->call('getArtHistory')
|
||||
->assertSet('hasHistory', true)
|
||||
->assertSet('historyData', [['artid' => 'ART001', 'qty' => 5]])
|
||||
->assertSet('errorMessage', null);
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return str_contains($request->url(), 'third_GetArtHistory')
|
||||
&& $request->data()['thirdid'] === 'CUST001';
|
||||
});
|
||||
});
|
||||
|
||||
it('displays error message on API failure', function () {
|
||||
it('sends thirdid in lowercase key to third_GetArtHistory', function () {
|
||||
Http::fake([
|
||||
'*/third_GetArtHistory' => Http::response([
|
||||
'data' => [],
|
||||
'metadata' => ['rowCount' => 0, 'source' => 'DBF'],
|
||||
'error' => null,
|
||||
]),
|
||||
]);
|
||||
|
||||
Livewire::test(Tiers::class)
|
||||
->set('historyThirdId', '0100002174')
|
||||
->call('getArtHistory');
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return str_contains($request->url(), 'third_GetArtHistory')
|
||||
&& array_key_exists('thirdid', $request->data())
|
||||
&& ! array_key_exists('THIRDID', $request->data());
|
||||
});
|
||||
});
|
||||
|
||||
it('displays error message on third_list API failure', function () {
|
||||
Http::fake([
|
||||
'*/third_list' => Http::response([
|
||||
'data' => null,
|
||||
'metadata' => ['rowcount' => 0, 'issuccess' => false],
|
||||
'error' => 'Invalid API key',
|
||||
'error' => 'Search terms are required. Please provide a search query.',
|
||||
]),
|
||||
]);
|
||||
|
||||
Livewire::test(Tiers::class)
|
||||
->set('search', 'test')
|
||||
->call('searchTiers')
|
||||
->assertSet('hasSearched', true);
|
||||
|
||||
expect(true)->toBeTrue();
|
||||
->assertSet('hasSearched', true)
|
||||
->assertSet('data', []);
|
||||
});
|
||||
|
||||
it('displays error message on third_GetArtHistory API failure', function () {
|
||||
Http::fake([
|
||||
'*/third_GetArtHistory' => Http::response([
|
||||
'data' => null,
|
||||
'metadata' => ['isSuccess' => false],
|
||||
'error' => ['thirdid parameter is required.'],
|
||||
], 400),
|
||||
]);
|
||||
|
||||
Livewire::test(Tiers::class)
|
||||
->set('historyThirdId', 'INVALID')
|
||||
->call('getArtHistory')
|
||||
->assertSet('hasHistory', true)
|
||||
->assertSet('historyData', []);
|
||||
});
|
||||
|
||||
it('handles third_GetArtHistory returning empty data for unknown thirdid', function () {
|
||||
Http::fake([
|
||||
'*/third_GetArtHistory' => Http::response([
|
||||
'data' => [],
|
||||
'metadata' => ['rowCount' => 0, 'source' => 'DBF'],
|
||||
'error' => null,
|
||||
]),
|
||||
]);
|
||||
|
||||
Livewire::test(Tiers::class)
|
||||
->set('historyThirdId', 'XXXXXX')
|
||||
->call('getArtHistory')
|
||||
->assertSet('hasHistory', true)
|
||||
->assertSet('historyData', [])
|
||||
->assertSet('errorMessage', null);
|
||||
});
|
||||
|
||||
it('filters out empty select parameter', function () {
|
||||
Http::fake([
|
||||
'*/third_list' => Http::response([
|
||||
'data' => [['custid' => '0100002174', 'name' => 'ESI SPRL']],
|
||||
'metadata' => ['rowCount' => 1, 'source' => 'DBF', 'executionTimeMs' => 100, 'searchColumns' => 'name,groupid,vat', 'selectColumns' => 'custid,name', 'searchTerms' => 'test'],
|
||||
'error' => null,
|
||||
]),
|
||||
]);
|
||||
|
||||
Livewire::test(Tiers::class)
|
||||
->set('search', 'test')
|
||||
->set('select', '')
|
||||
->call('searchTiers');
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
$data = $request->data();
|
||||
|
||||
return str_contains($request->url(), 'third_list')
|
||||
&& ! array_key_exists('select', $data);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user