Enforce a vendor contact

This commit is contained in:
David Bomba 2023-11-23 11:33:52 +11:00
parent 2fa010b42f
commit 6f3ad0e1f0
2 changed files with 21 additions and 13 deletions

View File

@ -55,19 +55,15 @@ class VendorRepository extends BaseRepository
if ($vendor->number == '' || ! $vendor->number) { if ($vendor->number == '' || ! $vendor->number) {
$vendor->number = $this->getNextVendorNumber($vendor); $vendor->number = $this->getNextVendorNumber($vendor);
} //todo write tests for this and make sure that custom vendor numbers also works as expected from here }
$vendor->saveQuietly(); $vendor->saveQuietly();
if (isset($data['contacts'])) { if (isset($data['contacts']) || $vendor->contacts()->count() == 0) {
$this->contact_repo->save($data, $vendor); $this->contact_repo->save($data, $vendor);
} }
if (empty($data['name'])) { if (array_key_exists('documents', $data) && count($data['documents']) >= 1) {
$data['name'] = $vendor->present()->name();
}
if (array_key_exists('documents', $data)) {
$this->saveDocuments($data['documents'], $vendor); $this->saveDocuments($data['documents'], $vendor);
} }

View File

@ -47,6 +47,24 @@ class VendorApiTest extends TestCase
Model::reguard(); Model::reguard();
} }
public function testVendorContactCreation()
{
$data = [
'name' => 'hewwo',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/vendors', $data);
$arr = $response->json();
$this->assertEquals('hewwo', $arr['data']['name']);
$this->assertEquals(1, count($arr['data']['contacts']));
}
public function testVendorLoggedInEvents() public function testVendorLoggedInEvents()
{ {
$v = \App\Models\Vendor::factory()->create([ $v = \App\Models\Vendor::factory()->create([
@ -69,12 +87,6 @@ class VendorApiTest extends TestCase
Event::assertDispatched(VendorContactLoggedIn::class); Event::assertDispatched(VendorContactLoggedIn::class);
// $vc->fresh();
// $v->fresh();
// $this->assertNotNull($vc->fresh()->last_login);
// $this->assertNotNull($v->fresh()->last_login);
} }
public function testVendorLocale() public function testVendorLocale()