create(); $run = SuggestionRun::factory()->for($user)->create([ 'suggestions_count' => 2, ]); RuleSuggestion::factory()->count(2)->for($run, 'run')->create(); $run->refresh()->loadCount('suggestions'); expect($run->status)->toBe(SuggestionRunStatus::Completed) ->and($run->status->countsTowardThrottle())->toBeTrue() ->and($run->suggestions_count)->toBe(2) ->and($run->suggestions)->toHaveCount(2) ->and($run->suggestions->first()->status)->toBe(RuleSuggestionStatus::Pending) ->and($run->suggestions->first()->confidence)->toBeFloat() ->and($run->suggestions->first()->sample_descriptions)->toBeArray(); }); it('flags a suggestion that proposes a new category', function () { $suggestion = RuleSuggestion::factory()->proposesNewCategory('Pet care')->create(); expect($suggestion->proposesNewCategory())->toBeTrue() ->and($suggestion->new_category_name)->toBe('Pet care'); }); it('does not count empty or failed runs toward the throttle', function () { expect(SuggestionRunStatus::Empty->countsTowardThrottle())->toBeFalse() ->and(SuggestionRunStatus::Failed->countsTowardThrottle())->toBeFalse() ->and(SuggestionRunStatus::Pending->countsTowardThrottle())->toBeFalse(); });