Files
portal/app/tests/Unit/Advertising/CreativeIdMatcherTest.php
T

41 lines
1.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
use App\Exceptions\Advertising\CreativeMatchFailedException;
use App\Services\Advertising\CreativeIdMatcher;
it('matches new creatives to expected sizes', function () {
$before = [111 => [300, 250]];
$after = [111 => [300, 250], 222 => [300, 250], 333 => [728, 90]];
$matched = (new CreativeIdMatcher)->match($before, $after, [[300, 250], [728, 90]]);
expect($matched)->toBe(['300x250' => 222, '728x90' => 333]);
});
it('fails when a expected size did not appear', function () {
$before = [];
$after = [222 => [300, 250]];
expect(fn () => (new CreativeIdMatcher)->match($before, $after, [[300, 250], [728, 90]]))
->toThrow(CreativeMatchFailedException::class, '728x90');
});
it('fails when two new creatives share one size', function () {
$before = [];
$after = [222 => [300, 250], 223 => [300, 250]];
expect(fn () => (new CreativeIdMatcher)->match($before, $after, [[300, 250]]))
->toThrow(CreativeMatchFailedException::class, '300x250');
});
it('ignores new creatives of sizes we did not ask for', function () {
$before = [];
$after = [222 => [300, 250], 999 => [160, 600]];
$matched = (new CreativeIdMatcher)->match($before, $after, [[300, 250]]);
expect($matched)->toBe(['300x250' => 222]);
});