Created
November 20, 2013 18:13
-
-
Save willert/7568152 to your computer and use it in GitHub Desktop.
Test with stash instead of content_lacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Search::Autocomplete; | |
use 5.014; | |
use Test::Able; | |
use Test::More; | |
use Data::Dumper; | |
use JSON::XS qw/ decode_json /; | |
use utf8; | |
# order is important! | |
with 'Bofrost::Test::Schema::WithFixtures'; | |
with 'Bofrost::Test::Catalyst'; | |
test plan => 'no_plan', users => sub{ | |
my $self = shift; | |
my $schema = $self->schema; | |
my @suggestions; | |
$self->mech->get_ok( '/autocomplete/ingredient/kartoffel' ); | |
@suggestions = @{ decode_json( $self->mech->content )}; | |
cmp_ok scalar @suggestions, '>', 2, 'Found a few suggestions'; | |
$self->mech->get_ok( '/autocomplete/ingredient//' ); | |
@suggestions = @{ decode_json( $self->mech->content )}; | |
cmp_ok scalar @suggestions, '==', 0, 'Empty suggestion list for invalid searches'; | |
like $self->mech->content, qr/ \s* \[ \s* \] \s* /x, 'Correct JSON string for empty list'; | |
$self->mech->get_ok( '/autocomplete/ingredient/kartoffel/brei' ); | |
@suggestions = @{ decode_json( $self->mech->content )}; | |
cmp_ok scalar @suggestions, '>', 2, 'Found a few suggestions for valid search with invalid chars'; | |
$self->mech->get_ok( '/autocomplete/ingredient/7kartoffel/bre}i' ); | |
@suggestions = @{ decode_json( $self->mech->content )}; | |
cmp_ok scalar @suggestions, '>', 2, 'Found a few suggestions for valid search with invalid chars'; | |
$self->mech->get_ok( '/autocomplete/recipe/kartoffel' ); | |
@suggestions = @{ decode_json( $self->mech->content )}; | |
cmp_ok scalar @suggestions, '>', 2, 'Found a few suggestions'; | |
$self->mech->get_ok( '/autocomplete/recipe//' ); | |
@suggestions = @{ decode_json( $self->mech->content )}; | |
cmp_ok scalar @suggestions, '==', 0, 'Empty suggestion list for invalid searches'; | |
like $self->mech->content, qr/ \s* \[ \s* \] \s* /x, 'Correct JSON string for empty list'; | |
$self->mech->get_ok( '/autocomplete/recipe/7erbsen/möh}ren' ); | |
@suggestions = @{ decode_json( $self->mech->content )}; | |
cmp_ok scalar @suggestions, '>', 2, 'Found a few suggestions for valid search with invalid chars'; | |
$self->mech->get_ok( '/rezepte?query=kartoffel' ); | |
note "Found: " . @{ $self->mech->ctx->stash->{recipes} }; | |
cmp_ok @{ $self->mech->ctx->stash->{recipes} }, '>', 2, 'Found recipes for valid query'; | |
$self->mech->get_ok( '/rezepte?query=7erb/sen' ); | |
note "Found: " . @{ $self->mech->ctx->stash->{recipes} }; | |
cmp_ok @{ $self->mech->ctx->stash->{recipes} }, '>', 2, 'Found recipes for valid query with invalid chars'; | |
$self->mech->get_ok( '/rezepte?query=dashierfindestdubestimmtnicht' ); | |
note "Found: " . @{ $self->mech->ctx->stash->{recipes} }; | |
cmp_ok @{ $self->mech->ctx->stash->{recipes} }, '==', 0, 'Found no recipes for strange query'; | |
$self->mech->get_ok( '/rezepte?query=/' ); | |
cmp_ok @{ $self->mech->ctx->stash->{recipes} }, '>', 2, 'Single / returns all recipes'; | |
$self->mech->get_ok( '/rezepte?query=(kartoffel' ); | |
cmp_ok @{ $self->mech->ctx->stash->{recipes} }, '>', 2, 'Found suggestions for an invalid query with ('; | |
}; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment