<commit_before>use Test::More; # tests => 1;
use strict;
use warnings;

use JSON qw(encode_json);
use Log::Report;
use GADS::Layout;
use GADS::Record;
use GADS::Records;
use GADS::Schema;

use t::lib::DataSheet;

my $data = [
    {
        string1    => '',
        date1      => '2014-10-10',
        daterange1 => ['2014-03-21', '2015-03-01'],
        enum1      => 1,
        tree1      => 4,
    },{
        string1    => 'Foo',
        date1      => '2014-10-10',
        daterange1 => ['2010-01-04', '2011-06-03'],
        enum1      => 1,
        tree1      => 4,
    },{
        string1    => 'FooBar',
        date1      => '2015-10-10',
        daterange1 => ['2009-01-04', '2017-06-03'],
        enum1      => 1,
        tree1      => 4,
    },{
        string1    => 'Disappear',
    },
];

my $sheet = t::lib::DataSheet->new(data => $data);

my $schema = $sheet->schema;
my $layout = $sheet->layout;
my $columns = $sheet->columns;
$sheet->create_records;

$schema->resultset('User')->populate([
    {
        id       => 1,
        username => '<EMAIL>',
        email    => '<EMAIL>',
    },
]);

my @filters = (
    {
        name       => 'Update of record in no filter view',
        rules      => undef,
        columns    => [],
        current_id => 1,
        update     => [
            {
                column => 'string1',
                value  => 'xyz',
            },
        ],
        alerts => 1,
    },
    {
        name  => 'Record appears in view',
        rules => [{
            id       => $columns->{string1}->id,
            type     => 'string',
            value    => 'Nothing to see here',
            operator => 'equal',
        }],
        columns => [$columns->{string1}->id],
        current_id => 1,
        update => [
            {
                column => 'string1',
                value  => 'Nothing to see here',
            },
        ],
        alerts => 2, # new record and updated record
    },
    {
        name  => 'Update to row in view',
        rules => [
            {
                id       => $columns->{string1}->id,
                type     => 'string',
                value    => 'Foo',
                operator => 'equal',
            },
            {
                id       => $columns->{date1}->id,
                type     => 'date',
                value    => '2000-01-04',
                operator => 'greater',
            },
        ],
        columns => [$columns->{date1}->id],
        current_id => 2,
        update => [
            {
                column => 'date1',
                value  => '2014-10-15',
            },
            {
                column => 'string1',
                value  => 'Foo',
            },
        ],
        alerts => 2, # New record and updated record
    },
    {
        name  => 'Update to row not in view',
        rules => [
            {
                id       => $columns->{string1}->id,
                type     => 'string',
                value    => 'FooBar',
                operator => 'equal',
            },
        ],
        columns => [$columns->{string1}->id],
        current_id => 3,
        update => [
            {
                column => 'date1',
                value  => '2014-10-15',
            },
        ],
        alerts => 0, # Neither update nor new appear/change in view
    },
    {
        name  => 'Disappears from view',
        rules => [{
            id       => $columns->{string1}->id,
            type     => 'string',
            value    => 'Disappear',
            operator => 'equal',
        }],
        columns => [$columns->{string1}->id],
        current_id => 4,
        update => [
            {
                column => 'string1',
                value  => 'Gone',
            },
        ],
        alerts => 1, # Disappears
    },
);

my $user = { id => 1 };

# First all all the filters and alerts#
foreach my $filter (@filters)
{
    my $rules = $filter->{rules} ? {
        rules     => $filter->{rules},
        condition => $filter->{condition},
    } : {};<commit_msg>Add test for alert on filter column not in view<commit_after>use Test::More; # tests => 1;
use strict;
use warnings;

use JSON qw(encode_json);
use Log::Report;
use GADS::Layout;
use GADS::Record;
use GADS::Records;
use GADS::Schema;

use t::lib::DataSheet;

my $data = [
    {
        string1    => '',
        date1      => '2014-10-10',
        daterange1 => ['2014-03-21', '2015-03-01'],
        enum1      => 1,
        tree1      => 4,
    },{
        string1    => 'Foo',
        date1      => '2014-10-10',
        daterange1 => ['2010-01-04', '2011-06-03'],
        enum1      => 1,
        tree1      => 4,
    },{
        string1    => 'FooBar',
        date1      => '2015-10-10',
        daterange1 => ['2009-01-04', '2017-06-03'],
        enum1      => 1,
        tree1      => 4,
    },{
        string1    => 'Disappear',
    },{
        string1    => 'FooFooBar',
        date1      => '2010-10-10',
    }
];

my $sheet = t::lib::DataSheet->new(data => $data);

my $schema = $sheet->schema;
my $layout = $sheet->layout;
my $columns = $sheet->columns;
$sheet->create_records;

$schema->resultset('User')->populate([
    {
        id       => 1,
        username => 'user<EMAIL>',
        email    => '<EMAIL>',
    },
]);

my @filters = (
    {
        name       => 'Update of record in no filter view',
        rules      => undef,
        columns    => [],
        current_id => 1,
        update     => [
            {
                column => 'string1',
                value  => 'xyz',
            },
        ],
        alerts => 1,
    },
    {
        name  => 'Record appears in view',
        rules => [{
            id       => $columns->{string1}->id,
            type     => 'string',
            value    => 'Nothing to see here',
            operator => 'equal',
        }],
        columns => [$columns->{string1}->id],
        current_id => 1,
        update => [
            {
                column => 'string1',
                value  => 'Nothing to see here',
            },
        ],
        alerts => 2, # new record and updated record
    },
    {
        name  => 'Update to row in view',
        rules => [
            {
                id       => $columns->{string1}->id,
                type     => 'string',
                value    => 'Foo',
                operator => 'equal',
            },
            {
                id       => $columns->{date1}->id,
                type     => 'date',
                value    => '2000-01-04',
                operator => 'greater',
            },
        ],
        columns => [$columns->{date1}->id],
        current_id => 2,
        update => [
            {
                column => 'date1',
                value  => '2014-10-15',
            },
            {
                column => 'string1',
                value  => 'Foo',
            },
        ],
        alerts => 2, # New record and updated record
    },
    {
        name  => 'Update to row not in view',
        rules => [
            {
                id       => $columns->{string1}->id,
                type     => 'string',
                value    => 'FooBar',
                operator => 'equal',
            },
        ],
        columns => [$columns->{string1}->id],
        current_id => 3,
        update => [
            {
                column => 'date1',
                value  => '2014-10-15',
            },
        ],
        alerts => 0, # Neither update nor new appear/change in view
    },
    {
        name  => 'Disappears from view',
        rules => [{
            id       => $columns->{string1}->id,
            type     => 'string',
            value    => 'Disappear',
            operator => 'equal',
        }],
        columns => [$columns->{string1}->id],
        current_id => 4,
        update => [
            {
                column => 'string1',
                value  => 'Gone',
            },
        ],
        alerts => 1, # Disappears
    },
    {
        name  => 'Change of filter of column not in view',
        rules => [{
            id       => $columns->{string1}->id,
            type     => 'string',
            value    => 'FooFooBar',
            operator => 'equal',
        }],
        columns => [$columns->{date1}->id],
        current_id => 5,
        update => [
            {
                column => 'string1',
                value  => 'Gone',
            },
        ],
        alerts => 1, # Disappears
    },
);

my $user = { id => 1 };

# First all all the filters and alerts#
foreach my $filter (@filters)
{
    my $rules = $filter->{rules} ? {
        rules     => $filter->{rules},
        condition => $filter->{condition},
    } : {};
{'fraction_non_alphanumeric': 0.16389875157484823, 'fraction_numerical': 0.03516206620089337, 'mean_word_length': 1.1271619975639464, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 253, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2588305', 'n_tokens_mistral': 2786, 'n_tokens_neox': 2528, 'n_words': 567}