@@ -74,7 +74,6 @@ public static function getAvailableLocales()
7474
7575 // Test with valid data
7676 $ validData = [
77- 'year ' => (int ) date ('Y ' ),
7877 'code ' => '0101 ' ,
7978 'name ' => ['en ' => 'Live horses, asses, mules and hinnies ' ],
8079 'measure_unit ' => ['en ' => 'pcs ' ],
@@ -86,7 +85,6 @@ public static function getAvailableLocales()
8685
8786test ('new tariff code can be created ' , function () {
8887 $ data = [
89- 'year ' => (int ) date ('Y ' ),
9088 'code ' => '0101 ' ,
9189 'name ' => ['en ' => 'Live horses, asses, mules and hinnies ' ],
9290 'measure_unit ' => ['en ' => 'pcs ' ],
@@ -97,20 +95,18 @@ public static function getAvailableLocales()
9795 ->assertHasNoActionErrors ();
9896
9997 $ tariffCode = TariffCode::where ('code ' , $ data ['code ' ])
100- ->where ('year ' , $ data ['year ' ])
10198 ->first ();
10299
103100 expect ($ tariffCode )->toBeObject ();
104101
105- expect ($ tariffCode ->year )->toEqual ($ data [ ' year ' ] );
102+ expect ($ tariffCode ->year )->toEqual (( int ) date ( ' Y ' ) );
106103 expect ($ tariffCode ->code )->toEqual ($ data ['code ' ]);
107104 expect ($ tariffCode ->name )->toEqual ($ data ['name ' ]);
108105 expect ($ tariffCode ->measure_unit )->toEqual ($ data ['measure_unit ' ]);
109106});
110107
111108test ('existing tariff code can be updated ' , function () {
112109 $ tariffCode = TariffCode::factory ()->create ([
113- 'year ' => (int ) date ('Y ' ),
114110 'code ' => '0101 ' ,
115111 'name ' => ['en ' => 'Live horses, asses, mules and hinnies ' ],
116112 'measure_unit ' => ['en ' => 'pcs ' ],
@@ -172,14 +168,12 @@ public static function getAvailableLocales()
172168
173169 // Create first tariff code
174170 $ firstTariffCode = TariffCode::factory ()->create ([
175- 'year ' => $ year ,
176171 'code ' => '0101 ' ,
177172 'name ' => ['en ' => 'Live horses ' ],
178173 ]);
179174
180175 // Try to create duplicate year-code combination
181176 $ duplicateData = [
182- 'year ' => $ year ,
183177 'code ' => '0101 ' ,
184178 'name ' => ['en ' => 'Different name ' ],
185179 ];
@@ -197,50 +191,16 @@ public static function getAvailableLocales()
197191 ->toBe (1 );
198192});
199193
200- test ('can create same code for different years ' , function () {
201- $ year1 = (int ) date ('Y ' );
202- $ year2 = $ year1 - 1 ;
203-
204- // Create tariff code with same code for first year
205- $ tariffCode1Data = [
206- 'year ' => $ year1 ,
207- 'code ' => '0101 ' ,
208- 'name ' => ['en ' => 'Live horses ' ],
209- ];
210-
211- livewire (ListTariffCodes::class)
212- ->callAction ('create ' , $ tariffCode1Data )
213- ->assertHasNoActionErrors ();
214-
215- // Create tariff code with same code for second year (should work)
216- $ tariffCode2Data = [
217- 'year ' => $ year2 ,
218- 'code ' => '0101 ' ,
219- 'name ' => ['en ' => 'Live horses old ' ],
220- ];
221-
222- livewire (ListTariffCodes::class)
223- ->callAction ('create ' , $ tariffCode2Data )
224- ->assertHasNoActionErrors ();
225-
226- // Verify both tariff codes exist
227- expect (TariffCode::where ('code ' , '0101 ' )->count ())->toBe (2 );
228- expect (TariffCode::where ('year ' , $ year1 )->where ('code ' , '0101 ' )->count ())->toBe (1 );
229- expect (TariffCode::where ('year ' , $ year2 )->where ('code ' , '0101 ' )->count ())->toBe (1 );
230- });
231-
232194test ('updating tariff code respects unique constraint ' , function () {
233195 $ year = (int ) date ('Y ' );
234196
235197 // Create two tariff codes
236198 $ tariffCode1 = TariffCode::factory ()->create ([
237- 'year ' => $ year ,
238199 'code ' => '0101 ' ,
239200 'name ' => ['en ' => 'Live horses ' ],
240201 ]);
241202
242203 $ tariffCode2 = TariffCode::factory ()->create ([
243- 'year ' => $ year ,
244204 'code ' => '0102 ' ,
245205 'name ' => ['en ' => 'Live cattle ' ],
246206 ]);
@@ -256,7 +216,6 @@ public static function getAvailableLocales()
256216 $ year = (int ) date ('Y ' );
257217
258218 $ tariffCode = TariffCode::factory ()->create ([
259- 'year ' => $ year ,
260219 'code ' => '0101 ' ,
261220 'name ' => ['en ' => 'Live horses ' ],
262221 ]);
0 commit comments