published $permanent = new Discount(); $permanent->type = DiscountType::PERCENT; $permanent->value = DiscountValue::fromPercentage(10); $permanent->is_old_price_displayed = true; $permanent->date_start = null; $permanent->date_end = null; $permanent->save(); // 2. Immediate discount with end date in future -> published $immediate = new Discount(); $immediate->type = DiscountType::PERCENT; $immediate->value = DiscountValue::fromPercentage(15); $immediate->is_old_price_displayed = true; $immediate->date_start = null; $immediate->date_end = Carbon::parse('2026-06-20 23:59:59'); $immediate->save(); // 3. Started discount with no end date -> published $ongoing = new Discount(); $ongoing->type = DiscountType::PERCENT; $ongoing->value = DiscountValue::fromPercentage(20); $ongoing->is_old_price_displayed = true; $ongoing->date_start = Carbon::parse('2026-06-10 00:00:00'); $ongoing->date_end = null; $ongoing->save(); // 4. Bounded active discount -> published $bounded = new Discount(); $bounded->type = DiscountType::PERCENT; $bounded->value = DiscountValue::fromPercentage(25); $bounded->is_old_price_displayed = true; $bounded->date_start = Carbon::parse('2026-06-10 00:00:00'); $bounded->date_end = Carbon::parse('2026-06-20 23:59:59'); $bounded->save(); // 5. Future discount -> not published $future = new Discount(); $future->type = DiscountType::PERCENT; $future->value = DiscountValue::fromPercentage(30); $future->is_old_price_displayed = true; $future->date_start = Carbon::parse('2026-06-20 00:00:00'); $future->date_end = Carbon::parse('2026-06-25 23:59:59'); $future->save(); // 6. Expired discount -> not published $expired = new Discount(); $expired->type = DiscountType::PERCENT; $expired->value = DiscountValue::fromPercentage(35); $expired->is_old_price_displayed = true; $expired->date_start = Carbon::parse('2026-06-01 00:00:00'); $expired->date_end = Carbon::parse('2026-06-10 23:59:59'); $expired->save(); // WHEN $publishedDiscounts = Discount::query()->published()->get(); // THEN $publishedIds = $publishedDiscounts->pluck('id')->all(); expect($publishedIds)->toContain($permanent->id) ->and($publishedIds)->toContain($immediate->id) ->and($publishedIds)->toContain($ongoing->id) ->and($publishedIds)->toContain($bounded->id) ->and($publishedIds)->not->toContain($future->id) ->and($publishedIds)->not->toContain($expired->id); Carbon::setTestNow(); }); });