Tests for Vendor Locale

This commit is contained in:
David Bomba 2023-08-10 10:44:29 +10:00
parent 92336b7f05
commit c807ae864a
2 changed files with 51 additions and 10 deletions

View File

@ -172,12 +172,12 @@ class Vendor extends BaseModel
return $this->hasMany(VendorContact::class)->where('is_primary', true); return $this->hasMany(VendorContact::class)->where('is_primary', true);
} }
public function documents() public function documents(): \Illuminate\Database\Eloquent\Relations\MorphMany
{ {
return $this->morphMany(Document::class, 'documentable'); return $this->morphMany(Document::class, 'documentable');
} }
public function assigned_user() public function assigned_user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{ {
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed(); return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
} }
@ -214,12 +214,12 @@ class Vendor extends BaseModel
return $this->company->timezone(); return $this->company->timezone();
} }
public function company() public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{ {
return $this->belongsTo(Company::class); return $this->belongsTo(Company::class);
} }
public function user() public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{ {
return $this->belongsTo(User::class)->withTrashed(); return $this->belongsTo(User::class)->withTrashed();
} }
@ -268,24 +268,29 @@ class Vendor extends BaseModel
return $this->company->settings; return $this->company->settings;
} }
public function purchase_order_filepath($invitation) public function purchase_order_filepath($invitation): string
{ {
$contact_key = $invitation->contact->contact_key; $contact_key = $invitation->contact->contact_key;
return $this->company->company_key.'/'.$this->vendor_hash.'/'.$contact_key.'/purchase_orders/'; return $this->company->company_key.'/'.$this->vendor_hash.'/'.$contact_key.'/purchase_orders/';
} }
public function locale() public function locale(): string
{ {
return $this->company->locale(); return $this->language ? $this->language->locale : $this->company->locale();
} }
public function country() public function language(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Language::class);
}
public function country(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{ {
return $this->belongsTo(Country::class); return $this->belongsTo(Country::class);
} }
public function date_format() public function date_format(): string
{ {
return $this->company->date_format(); return $this->company->date_format();
} }

View File

@ -42,9 +42,45 @@ class VendorApiTest extends TestCase
$this->faker = \Faker\Factory::create(); $this->faker = \Faker\Factory::create();
Model::reguard(); Model::reguard();
}
// $this->withoutExceptionHandling(); public function testVendorLocale()
{
$v = \App\Models\Vendor::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id
]);
$this->assertNotNull($v->locale());
}
public function testVendorLocaleEn()
{
$v = \App\Models\Vendor::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'language_id' => '1'
]);
$this->assertEquals('en', $v->locale());
}
public function testVendorLocaleEnCompanyFallback()
{
$settings = $this->company->settings;
$settings->language_id = '2';
$c = \App\Models\Company::factory()->create([
'account_id' => $this->account->id,
'settings' => $settings,
]);
$v = \App\Models\Vendor::factory()->create([
'user_id' => $this->user->id,
'company_id' => $c->id
]);
$this->assertEquals('it', $v->locale());
} }
public function testVendorGetFilter() public function testVendorGetFilter()