ldc-cocotte/tests/Integration/WithApp/Infra/Adapters/Services/EloquentEmployeeStatisticsServiceTest.php

65 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
use Carbon\CarbonImmutable;
use Domain\Enums\OrderStatus;
use Domain\Models\ValueObjects\Matricule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Infrastructure\Adapters\Services\EloquentEmployeeStatisticsService;
use Ramsey\Uuid\Uuid;
beforeEach(function () {
if (! Schema::hasTable('orders')) {
Schema::create('orders', function (Blueprint $table) {
$table->string('id')->primary();
$table->unsignedBigInteger('shop_id');
$table->string('reference');
$table->json('employee');
$table->json('delivery_address');
$table->date('pickup_day');
$table->string('status');
$table->integer('total');
$table->string('employee_matricule')->nullable();
$table->timestamps();
});
}
DB::table('orders')->delete();
});
it('retrieves the weekly order total for a given employee', function () {
// GIVEN
DB::table('shops')->insertOrIgnore(['id' => 1, 'name' => 'Shop 1', 'postcode' => '75000', 'city' => 'Paris', 'address' => 'Addr']);
DB::table('orders')->insert([
'id' => '018e4567-e89b-72d3-a456-426614174000',
'shop_id' => 1,
'reference' => Uuid::uuid7()->toString(),
'employee' => json_encode([
'matricule' => '1234567',
'firstname' => 'Jean',
'lastname' => 'Dupont',
'facility' => 'Main Facility',
'site' => 'HQ',
'service' => 'IT',
]),
'delivery_address' => '{}',
'pickup_day' => '2023-01-05',
'status' => OrderStatus::VALIDATED->value,
'total' => 1500, // 15.00 EUR
]);
$service = new EloquentEmployeeStatisticsService();
$start = CarbonImmutable::parse('2023-01-01');
$end = CarbonImmutable::parse('2023-01-07');
// WHEN
$result = $service->getWeeklyTotalForEmployee(new Matricule('1234567'), $start, $end);
// THEN
expect($result->getAmount())->toBe('1500')
->and($result->getCurrency()->getCode())->toBe('EUR');
});