82 lines
2.1 KiB
PHP
82 lines
2.1 KiB
PHP
<?php
|
|
|
|
use App\Models\Post\PostBranch;
|
|
use App\Models\System\Settings\Location\Province;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Config;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
Config::set('ecommerce.api.token', 'test-token');
|
|
});
|
|
|
|
use App\Models\System\Settings\Location\Region;
|
|
|
|
test('can list provinces', function () {
|
|
// Arrange
|
|
Province::create(['name' => ['en' => 'Province 1'], 'region' => Region::AG]);
|
|
Province::create(['name' => ['en' => 'Province 2'], 'region' => Region::MR]);
|
|
|
|
// Act
|
|
$response = $this->withHeaders([
|
|
'Api-Token' => 'test-token',
|
|
'Accept' => 'application/json',
|
|
])->getJson('/api/v1/provinces');
|
|
|
|
// Assert
|
|
$response->assertOk()
|
|
->assertJsonStructure([
|
|
'data' => [
|
|
'*' => [
|
|
'id',
|
|
'name',
|
|
'region',
|
|
]
|
|
]
|
|
]);
|
|
|
|
$this->assertCount(2, $response->json('data'));
|
|
});
|
|
|
|
test('can list post branches', function () {
|
|
// Arrange
|
|
$province = Province::create(['name' => ['en' => 'Province 1'], 'region' => Region::AG]);
|
|
|
|
PostBranch::create([
|
|
'province_id' => $province->id,
|
|
'name' => ['en' => 'Branch 1'],
|
|
'address' => ['en' => 'Address 1'],
|
|
'description' => ['en' => 'Desc 1'],
|
|
]);
|
|
|
|
PostBranch::create([
|
|
'province_id' => $province->id,
|
|
'name' => ['en' => 'Branch 2'],
|
|
'address' => ['en' => 'Address 2'],
|
|
'description' => ['en' => 'Desc 2'],
|
|
]);
|
|
|
|
// Act
|
|
$response = $this->withHeaders([
|
|
'Api-Token' => 'test-token',
|
|
'Accept' => 'application/json',
|
|
])->getJson('/api/v1/post-branches');
|
|
|
|
// Assert
|
|
$response->assertOk()
|
|
->assertJsonStructure([
|
|
'data' => [
|
|
'*' => [
|
|
'id',
|
|
'province_id',
|
|
'name',
|
|
'address',
|
|
'description',
|
|
]
|
|
]
|
|
]);
|
|
|
|
$this->assertCount(2, $response->json('data'));
|
|
});
|