<?php
/**
 * @author Daniel J. Summers <daniel@bitbadger.solutions>
 * @license MIT
 */

declare(strict_types=1);

use BitBadger\PDODocument\{Exists, Field};
use Test\Integration\PostgreSQL\ThrowawayDb;

pest()->group('integration', 'postgresql');

describe('::byId()', function () {
    test('returns true when a document exists', function () {
        expect(Exists::byId(ThrowawayDb::TABLE, 'three'))->toBeTrue();
    });
    test('returns false when a document does not exist', function () {
        expect(Exists::byId(ThrowawayDb::TABLE, 'seven'))->toBeFalse();
    });
});

describe('::byFields()', function () {
    test('returns true when matching documents exist', function () {
        expect(Exists::byFields(ThrowawayDb::TABLE, [Field::equal('num_value', 10)]))->toBeTrue();
    });
    test('returns false when no matching documents exist', function () {
        expect(Exists::byFields(ThrowawayDb::TABLE, [Field::less('nothing', 'none')]))->toBeFalse();
    });
});

describe('::byContains()', function () {
    test('returns true when matching documents exist', function () {
        expect(Exists::byContains(ThrowawayDb::TABLE, ['value' => 'purple']))->toBeTrue();
    });
    test('returns false when no matching documents exist', function () {
        expect(Exists::byContains(ThrowawayDb::TABLE, ['value' => 'violet']))->toBeFalse();
    });
});

describe('::byJsonPath()', function () {
    test('returns true when matching documents exist', function () {
        expect(Exists::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10)'))->toBeTrue();
    });
    test('returns false when no matching documents exist', function () {
        expect(Exists::byJsonPath(ThrowawayDb::TABLE, '$.num_value ? (@ == 10.1)'))->toBeFalse();
    });
});