root/veekun/trunk/t/dex-search-moves.t

Revision 406, 2.2 kB (checked in by eevee, 10 months ago)

Database refactoring. Renamed columns and tables to be more consistent and more readable. (#58)

Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use lib 'lib';
6
7use Test::More tests => 16;
8
9BEGIN { $ENV{CATALYST_DEBUG} = 0; }
10BEGIN { use_ok 'Catalyst::Test', 'Vee' }
11BEGIN { use_ok 'Vee::Controller::Dex::Search' }
12
13sub search_ok;
14
15### Same idea as Pokemon search tests
16
17ok request('/dex/moves/search')->is_success, "Move search page loads";
18
19search_ok { name => 'fire' },
20    [qw/ 7 83 126 221 424 /],
21    "Name substring";
22
23search_ok { name => '???' },
24    [qw/ 15 19 91 /],
25    "Name with wildcards";
26
27search_ok { name => 'fire', class => 'physical' },
28    [qw/ 7 221 424 /],
29    "Damage class (+ name)";
30
31search_ok { class => 'special', type => 'dark' },
32    [qw/ 399 /],
33    "Type (+ damage class)";
34
35search_ok { type => 'dragon', generation => 1 },
36    [qw/ 200 225 239/],
37    "Generation (+ type)";
38
39search_ok { type => 'steel', generation => 0 },
40    [qw/ /],
41    "Impossible generation + type";
42
43search_ok { pokemon => [qw/ flareon charizard /], move_method => 'level' },
44    [qw/ 43 52 53 83 99 184 424 /],
45    "Multiple Pokemon, by level";
46
47search_ok { pokemon => 'ditto' },
48    [qw/ 144 /],
49    "Single Pokemon";
50
51search_ok { pokemon => 'charizard', move_method => 'tutor', move_version => 'c' },
52    [qw/ 53 /],
53    "Single Pokemon, via tutor, in Crystal";
54
55search_ok { power_lb => 200 },
56    [qw/ 120 153 /],
57    "Lower bound on power";
58
59search_ok { power_lb => 14, power_ub => 16 },
60    [qw/ 3 20 31 35 40 42 83 140 250 292 328 /],
61    "Lower and upper bounds on power";
62
63search_ok { accuracy_lb => 30, accuracy_ub => 30 },
64    [qw/ 12 32 90 329 /],
65    "Exact accuracy";
66
67search_ok { name => 'fire', sort => 'name' },
68    [qw/ 126 424 7 83 221 /],
69    "Sorting (+ name)";
70
71# TODO: This is remarkably similar to the Pokemon search sub!  Generalize and
72# throw it in Veekun::Test::*.
73sub search_ok {
74    my ($params, $expected, $test_name) = @_;
75
76    if (not $params->{sort}) {
77        # sort by id for simplicity
78        $params->{sort} = 'id';
79        delete $params->{sort_desc};
80    }
81
82    my $context = Vee->prepare;
83    $context->req->params($params);
84    Vee::Controller::Dex::Search->move_search($context);
85
86    my $move_rows = $context->stash->{results} || [];
87    my @moves = map { $_->id } @$move_rows;
88
89    is_deeply \@moves, $expected, $test_name;
90}
Note: See TracBrowser for help on using the browser.