Skip to content

Commit 7bf3233

Browse files
committed
feat: create-feature-test
1 parent c85856c commit 7bf3233

2 files changed

Lines changed: 150 additions & 0 deletions

File tree

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
3+
namespace App\Packages\Features\Tests;
4+
5+
use App\Models\WorldHeritage;
6+
use Illuminate\Support\Facades\DB;
7+
use Tests\TestCase;
8+
9+
class CreateManyWorldHeritagesTest extends TestCase
10+
{
11+
protected function setUp(): void
12+
{
13+
parent::setUp();
14+
$this->refresh();
15+
}
16+
17+
protected function tearDown(): void
18+
{
19+
$this->refresh();
20+
parent::tearDown();
21+
}
22+
23+
private function refresh(): void
24+
{
25+
if (env('APP_ENV') === 'testing') {
26+
DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=0;');
27+
WorldHeritage::truncate();
28+
DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=1;');
29+
}
30+
}
31+
32+
private static function arrayData(): array
33+
{
34+
return [
35+
[
36+
'unesco_id' => '660',
37+
'official_name' => 'Buddhist Monuments in the Horyu-ji Area',
38+
'name' => 'Buddhist Monuments in the Horyu-ji Area',
39+
'name_jp' => '法隆寺地域の仏教建造物',
40+
'country' => 'Japan',
41+
'region' => 'Asia',
42+
'state_party' => 'JP',
43+
'category' => 'cultural',
44+
'criteria' => ['ii', 'iii', 'v'],
45+
'year_inscribed' => 1993,
46+
'area_hectares' => 442.0,
47+
'buffer_zone_hectares' => 320.0,
48+
'is_endangered' => false,
49+
'latitude' => 34.6147,
50+
'longitude' => 135.7355,
51+
'short_description' => "Early Buddhist wooden structures including the world's oldest wooden building.",
52+
'image_url' => '',
53+
'unesco_site_url' => 'https://whc.unesco.org/en/list/660/',
54+
],
55+
[
56+
'unesco_id' => '661',
57+
'official_name' => 'Himeji-jo',
58+
'name' => 'Himeji-jo',
59+
'name_jp' => '姫路城',
60+
'country' => 'Japan',
61+
'region' => 'Asia',
62+
'state_party' => 'JP',
63+
'category' => 'cultural',
64+
'criteria' => ['ii', 'iii', 'v'],
65+
'year_inscribed' => 1993,
66+
'area_hectares' => 442.0,
67+
'buffer_zone_hectares' => 320.0,
68+
'is_endangered' => false,
69+
'latitude' => 34.8394,
70+
'longitude' => 134.6939,
71+
'short_description' => "A masterpiece of Japanese castle architecture in original form.",
72+
'image_url' => '',
73+
'unesco_site_url' => 'https://whc.unesco.org/en/list/661/',
74+
],
75+
[
76+
'unesco_id' => '662',
77+
'official_name' => 'Yakushima',
78+
'name' => 'Yakushima',
79+
'name_jp' => '屋久島',
80+
'country' => 'Japan',
81+
'region' => 'Asia',
82+
'state_party' => 'JP',
83+
'category' => 'natural',
84+
'criteria' => ['ii', 'iii', 'v'],
85+
'year_inscribed' => 1993,
86+
'area_hectares' => 442.0,
87+
'buffer_zone_hectares' => 320.0,
88+
'is_endangered' => false,
89+
'latitude' => 30.3581,
90+
'longitude' => 130.546,
91+
'short_description' => "A subtropical island with ancient cedar forests and diverse ecosystems.",
92+
'image_url' => '',
93+
'unesco_site_url' => 'https://whc.unesco.org/en/list/662/',
94+
],
95+
[
96+
'unesco_id' => '663',
97+
'official_name' => 'Shirakami-Sanchi',
98+
'name' => 'Shirakami-Sanchi',
99+
'name_jp' => '白神山地',
100+
'country' => 'Japan',
101+
'region' => 'Asia',
102+
'state_party' => 'JP',
103+
'category' => 'natural',
104+
'criteria' => ['ii', 'iii', 'v'],
105+
'year_inscribed' => 1993,
106+
'area_hectares' => 442.0,
107+
'buffer_zone_hectares' => 320.0,
108+
'is_endangered' => false,
109+
'latitude' => 40.5167,
110+
'longitude' => 140.05,
111+
'short_description' => "Pristine beech forest with minimal human impact.",
112+
'image_url' => '',
113+
'unesco_site_url' => 'https://whc.unesco.org/en/list/663/',
114+
]
115+
];
116+
}
117+
118+
public function test_feature(): void
119+
{
120+
$result = $this->postJson('/api/v1/heritages', self::arrayData());
121+
122+
$result->assertStatus(201)
123+
->assertJsonStructure([
124+
'data' => [
125+
'*' => [
126+
'id',
127+
'unesco_id',
128+
'official_name',
129+
'name',
130+
'name_jp',
131+
'country',
132+
'region',
133+
'state_party',
134+
'category',
135+
'criteria',
136+
'year_inscribed',
137+
'area_hectares',
138+
'buffer_zone_hectares',
139+
'is_endangered',
140+
'latitude',
141+
'longitude',
142+
'short_description',
143+
'image_url',
144+
'unesco_site_url',
145+
]
146+
]
147+
]);
148+
}
149+
}

src/routes/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
Route::get('/heritages/{id}', [WorldHeritageController::class, 'getWorldHeritageById']);
88
Route::get('heritages/', [WorldHeritageController::class, 'getWorldHeritagesByIds']);
99
Route::post('heritage', [WorldHeritageController::class, 'registerOneWorldHeritage']);
10+
Route::post('heritages', [WorldHeritageController::class, 'registerManyWorldHeritages']);
1011
});

0 commit comments

Comments
 (0)