<?php

use Tricks\Monitoring\Http\Controllers\LastUpdatedController;

test('detects updates since last midnight', function () {
    $modelUpdatedOneHourAfterMidnight = getEloquentModelsMock();

    expect(LastUpdatedController::dataWasUpdatedSinceLastMidnight($modelUpdatedOneHourAfterMidnight))
        ->toBeTrue();
});

test('detects when data was not updated lately', function () {
    $modelUpdatedYesterday = getEloquentModelsMock([
        getMockedTestModel(now()->subDay()),
    ]);

    expect(LastUpdatedController::dataWasUpdatedSinceLastMidnight($modelUpdatedYesterday))
        ->toBeFalse();
});

test('it filters out models with no data', function () {
    $modelWithoutData = getEloquentModelsMock([]);

    expect(LastUpdatedController::dataWasUpdatedSinceLastMidnight($modelWithoutData))
        ->toBeFalse();
});

test('it filters out models with no timestamps', function () {
    $modelWithoutData = getEloquentModelsMock([
        getMockedTestModelWithoutTimestamps(),
    ]);

    expect(LastUpdatedController::dataWasUpdatedSinceLastMidnight($modelWithoutData))
        ->toBeTrue();
});
