'Тест', 'warmup_started_at' => now()]); } it('open заводит открытый эпизод канала', function () { $firm = episodeFirm(); (new WarmingEpisodeRecorder)->open($firm->id, 'yandex'); $ep = SalesAdAudienceWarmingEpisode::where('firm_id', $firm->id)->where('channel', 'yandex')->sole(); expect($ep->ended_at)->toBeNull(); }); it('повторный open уже открытого эпизода не плодит второй', function () { $firm = episodeFirm(); $rec = new WarmingEpisodeRecorder; $rec->open($firm->id, 'yandex'); $rec->open($firm->id, 'yandex'); expect(SalesAdAudienceWarmingEpisode::where('firm_id', $firm->id)->where('channel', 'yandex')->count())->toBe(1); }); it('close проставляет ended_at открытому эпизоду', function () { $firm = episodeFirm(); $rec = new WarmingEpisodeRecorder; $rec->open($firm->id, 'yandex'); $rec->close($firm->id, 'yandex'); $ep = SalesAdAudienceWarmingEpisode::where('firm_id', $firm->id)->where('channel', 'yandex')->sole(); expect($ep->ended_at)->not->toBeNull(); }); it('повторный open после close заводит второй эпизод (грели дважды)', function () { $firm = episodeFirm(); $rec = new WarmingEpisodeRecorder; $rec->open($firm->id, 'yandex'); $rec->close($firm->id, 'yandex'); $rec->open($firm->id, 'yandex'); expect(SalesAdAudienceWarmingEpisode::where('firm_id', $firm->id)->where('channel', 'yandex')->count())->toBe(2); }); it('record пишет мгновенный эпизод СМС (started_at = ended_at)', function () { $firm = episodeFirm(); (new WarmingEpisodeRecorder)->record($firm->id, 'sms'); $ep = SalesAdAudienceWarmingEpisode::where('firm_id', $firm->id)->where('channel', 'sms')->sole(); expect($ep->ended_at)->not->toBeNull() ->and($ep->started_at->timestamp)->toBe($ep->ended_at->timestamp); }); it('close без открытого эпизода — тихий no-op', function () { $firm = episodeFirm(); (new WarmingEpisodeRecorder)->close($firm->id, 'yandex'); expect(SalesAdAudienceWarmingEpisode::where('firm_id', $firm->id)->count())->toBe(0); });