Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require datetime string for special price dates #26

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Data/PriceData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class PriceData extends Data
'special_prices' => ['nullable', 'array'],
'special_prices.*.store_id' => ['required', 'integer'],
'special_prices.*.price' => ['required', 'numeric'],
'special_prices.*.price_from' => ['required', 'string'],
'special_prices.*.price_to' => ['required', 'string'],
'special_prices.*.price_from' => ['required', 'date_format:Y-m-d H:i:s'],
'special_prices.*.price_to' => ['required', 'date_format:Y-m-d H:i:s'],
];

public function checksum(): string
Expand Down
18 changes: 9 additions & 9 deletions tests/Actions/Retrieval/SavePriceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function it_saves_fields(): void
[
'store_id' => 0,
'price' => 5,
'price_from' => now()->subWeek()->toDateString(),
'price_to' => now()->addWeek()->toDateString(),
'price_from' => now()->subWeek()->toDateTimeString(),
'price_to' => now()->addWeek()->toDateTimeString(),
],
],
]);
Expand Down Expand Up @@ -68,16 +68,16 @@ public function it_saves_fields(): void
[
'store_id' => 0,
'price' => 5,
'price_from' => now()->subWeek()->toDateString(),
'price_to' => now()->addWeek()->toDateString(),
'price_from' => now()->subWeek()->toDateTimeString(),
'price_to' => now()->addWeek()->toDateTimeString(),
],
], $model->special_prices);

$this->assertTrue($model->sync);
$this->assertFalse($model->retrieve);
$this->assertTrue($model->update);
$this->assertNotNull($model->last_retrieved);
$this->assertEquals('27f10836349f35baf9aa229f963e4ddf', $model->checksum);
$this->assertEquals('c3a03f76b7189c896e25eb6335141c96', $model->checksum);

}

Expand Down Expand Up @@ -105,8 +105,8 @@ public function it_does_not_set_update_when_unchanged(): void
[
'store_id' => 0,
'price' => 5,
'price_from' => now()->subWeek()->toDateString(),
'price_to' => now()->addWeek()->toDateString(),
'price_from' => now()->subWeek()->toDateTimeString(),
'price_to' => now()->addWeek()->toDateTimeString(),
],
],
]);
Expand Down Expand Up @@ -151,8 +151,8 @@ public function it_can_force_update(): void
[
'store_id' => 0,
'price' => 5,
'price_from' => now()->subWeek()->toDateString(),
'price_to' => now()->addWeek()->toDateString(),
'price_from' => now()->subWeek()->toDateTimeString(),
'price_to' => now()->addWeek()->toDateTimeString(),
],
],
]);
Expand Down
18 changes: 18 additions & 0 deletions tests/Data/PriceDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,22 @@ public function it_handles_array_operations(): void

$this->assertNull($data['base_prices']);
}

#[Test]
public function it_throws_exception_on_failing_special_price(): void
{
$this->expectException(ValidationException::class);

PriceData::of([
'sku' => '::sku::',
'special_prices' => [
[
'price' => 10,
'price_from' => '2024-01-01',
'price_to' => '2025-01-01',
]
]
]);

}
}
4 changes: 2 additions & 2 deletions tests/Fakes/FakeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function retrieve(string $sku): ?PriceData
[
'store_id' => 0,
'price' => 5,
'price_from' => now()->subWeek()->toDateString(),
'price_to' => now()->addWeek()->toDateString(),
'price_from' => now()->subWeek()->toDateTimeString(),
'price_to' => now()->addWeek()->toDateTimeString(),
],
],
]);
Expand Down
2 changes: 2 additions & 0 deletions tests/Listeners/BulkOperationStatusListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function it_handles_complete_status(): void
/** @var BulkRequest $request */
$request = BulkRequest::query()->create([
'magento_connection' => 'default',
'method' => 'POST',
'store_code' => 'store',
'path' => 'products',
'bulk_uuid' => '::uuid::',
Expand Down Expand Up @@ -64,6 +65,7 @@ public function it_handles_failed_status(): void
/** @var BulkRequest $request */
$request = BulkRequest::query()->create([
'magento_connection' => 'default',
'method' => 'POST',
'store_code' => 'store',
'path' => 'products',
'bulk_uuid' => '::uuid::',
Expand Down