App-karr
view release on metacpan or search on metacpan
t/242-delete-cross-board-warning.t view on Meta::CPAN
is( $r->{exit}, 0, 'delete succeeds' ) or diag $r->{stderr};
unlike( $r->{stderr}, qr/Warning/,
'nothing on STDERR: a JSON consumer would never see it there' );
my $data = eval { decode_json( $r->{stdout} ) };
ok( $data, 'STDOUT is still one decodable JSON object' )
or diag "stdout was: $r->{stdout}";
is( ref $data->{cross_board_warnings}, 'ARRAY',
'the cross-board warning rides in the result object' );
is( scalar @{ $data->{cross_board_warnings} }, 1, 'one far card' );
like( $data->{cross_board_warnings}[0], qr/was escalated from boardB#5/,
'and it is the sentence STDERR would have carried' );
is( scalar @{ $data->{dependent_warnings} }, 1,
'the board-local warning keeps its own key' );
like( $data->{dependent_warnings}[0], qr/task 2 \(Local dependent\) depends on task 1/,
'and its own sentence: this board is not the other board' );
};
subtest '--json omits the key entirely when there is nothing to say' => sub {
my $here = _board('boardA');
_create( $here, 'Plain card' );
my $r = _run_karr( $here, 'delete', '1', '--yes', '--json' );
my $data = eval { decode_json( $r->{stdout} ) };
ok( $data, 'STDOUT decodes' ) or diag "stdout was: $r->{stdout}";
ok( !exists $data->{cross_board_warnings},
'no empty array to make a consumer test for length' );
};
subtest '--quiet silences it' => sub {
my $here = _board('boardA');
_create( $here, 'Fix the API', '--escalated-from', 'boardB#5' );
my $r = _run_karr( $here, 'delete', '1', '--yes', '--quiet' );
is( $r->{exit}, 0, 'delete succeeds' ) or diag $r->{stderr};
unlike( $r->{stderr}, qr/Warning/, 'STDERR says nothing under --quiet' );
unlike( $r->{stdout}, qr/Warning/, 'and it did not move to STDOUT either' );
ok( !_task( $here, 1 ), 'the delete still happened' );
};
subtest 'it reaches the operator while the answer is still open' => sub {
my $here = _board('boardA');
_create( $here, 'Fix the API', '--escalated-from', 'boardB#5' );
my $r = _run_karr( $here, \"n\n", 'delete', '1' );
is( $r->{exit}, 0, 'answering no is an answer, not a failure' )
or diag $r->{stderr};
like( $r->{stderr}, qr/was escalated from boardB#5/,
'the warning was given before the confirmation was answered' );
like( $r->{stdout}, qr/Skipped task 1/, 'and the operator could act on it' );
ok( _task( $here, 1 ), 'so the card is still there' );
};
subtest 'the kept card carries them under --json too' => sub {
my $here = _board('boardA');
_create( $here, 'Fix the API', '--escalated-from', 'boardB#5' );
my $r = _run_karr( $here, \"n\n", 'delete', '1', '--json' );
# The confirmation prompt is printed to STDOUT whatever --json says, so the
# object is decoded from where it starts. That is a separate defect of the
# prompt (the neighbour of #241, which fixed its flushing and not its
# channel), not of the warning under test, and this test declines to pin it
# either way.
my ($json) = $r->{stdout} =~ /(\{.*\})/s;
my $data = eval { decode_json( $json // '' ) };
ok( $data, 'STDOUT carries the result object' )
or diag "stdout was: $r->{stdout}";
ok( !$data->{deleted},
'deleted:false says the delete the warning named did not happen' );
like( $data->{cross_board_warnings}[0], qr/was escalated from boardB#5/,
'and the warning is beside it, which under --json is its only channel' );
};
subtest 'a batch warns per deleted id' => sub {
my $here = _board('boardA');
_create( $here, 'First', '--escalated-from', 'boardB#5' );
_create( $here, 'Second', '--escalated-from', 'boardB#6' );
my $r = _run_karr( $here, 'delete', '1,2', '--yes' );
is( $r->{exit}, 0, 'both ids are deleted' ) or diag $r->{stderr};
like( $r->{stderr}, qr/task 1 \(First\) was escalated from boardB#5/,
'the first id warns' );
like( $r->{stderr}, qr/task 2 \(Second\) was escalated from boardB#6/,
'and so does the second' );
};
done_testing;
( run in 1.272 second using v1.01-cache-2.11-cpan-364913b4093 )