]> git.evergreen-ils.org Git - working/SIPServer.git/blob - t/04patron_status.t
Return proper renewal OK field on checkout fail
[working/SIPServer.git] / t / 04patron_status.t
1 #!/usr/bin/perl
2 #
3 # Copyright (C) 2006-2008  Georgia Public Library Service
4
5 # Author: David J. Fiander
6
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of version 2 of the GNU General Public
9 # License as published by the Free Software Foundation.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public
17 # License along with this program; if not, write to the Free
18 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 # MA 02111-1307 USA
20 #
21 # patron_status: test Patron Status Response
22
23 use strict;
24 use warnings;
25 use Clone qw(clone);
26
27 use Sip::Constants qw(:all);
28
29 use SIPtest qw($datepat $textpat $instid $user_barcode $password);
30
31 my $patron_status_test_template = {
32     id => 'Patron Status: valid patron, no patron password',
33     msg => "2300120060101    084237AO$instid|AA$user_barcode|AC$password|",
34     pat => qr/^24 [ Y]{13}001$datepat/,
35     fields => [
36                $SIPtest::field_specs{(FID_INST_ID)},
37                $SIPtest::field_specs{(FID_SCREEN_MSG)},
38                $SIPtest::field_specs{(FID_PRINT_LINE)},
39                { field    => FID_PATRON_ID,
40                  pat      => qr/^$user_barcode$/,
41                  required => 1, },
42                { field    => FID_PERSONAL_NAME,
43                  pat      => qr/^David J\. Fiander$/,
44                  required => 1, },
45                { field    => FID_VALID_PATRON,
46                  pat      => qr/^Y$/,
47                  # Not required by the spec, but by the test
48                  required => 1, },
49                $SIPtest::field_specs{(FID_CURRENCY)},
50                { field    => FID_FEE_AMT,
51                  pat      => $textpat,
52                  required => 0, },
53                ], };
54
55 my @tests = (
56              $SIPtest::login_test,
57              $SIPtest::sc_status_test,
58              clone($patron_status_test_template),
59              );
60
61 # Invalid patron
62 my $test = clone($patron_status_test_template);
63
64 $test->{id} = 'Patron Status: invalid id';
65 $test->{msg} =~ s/AA$user_barcode\|/AAbad_userid|/ or warn "Substitution failed on test clone";
66
67 # The test assumes that the language sent by the terminal is
68 # just echoed back for invalid patrons.
69 $test->{pat} = qr/^24Y[ Y]{13}001$datepat/; 
70
71 delete $test->{fields};
72 $test->{fields} = [
73                    $SIPtest::field_specs{(FID_INST_ID)},
74                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
75                    $SIPtest::field_specs{(FID_PRINT_LINE)},
76                    { field    => FID_PATRON_ID,
77                      pat      => qr/^bad_userid$/,
78                      required => 1, },
79                    { field    => FID_PERSONAL_NAME,
80                      pat      => qr/^$/,
81                      required => 1, },
82                    { field    => FID_VALID_PATRON,
83                      pat      => qr/^N$/,
84                      required => 1, },
85                    ];
86
87 push @tests, $test;
88
89 # Valid patron, invalid patron password
90 $test = clone($patron_status_test_template);
91 $test->{id} = 'Patron Status: Valid patron, invalid patron password';
92 $test->{msg} .= (FID_PATRON_PWD) . 'badpwd|';
93 $test->{pat} = qr/^24[ Y]{14}001$datepat/;
94 delete $test->{fields};
95 $test->{fields} = [
96                  $SIPtest::field_specs{(FID_INST_ID)},
97                  $SIPtest::field_specs{(FID_SCREEN_MSG)},
98                  $SIPtest::field_specs{(FID_PRINT_LINE)},
99                  { field    => FID_PATRON_ID,
100                    pat      => qr/^$user_barcode$/,
101                    required => 1, },
102                  { field    => FID_PERSONAL_NAME,
103                    pat      => qr/^David J\. Fiander$/,
104                    required => 1, },
105                  { field    => FID_VALID_PATRON,
106                    pat      => qr/^Y$/,
107                    required => 1, },
108                  { field    => FID_VALID_PATRON_PWD,
109                    pat      => qr/^N$/,
110                    required => 1, },
111                  ];
112 push @tests, $test;
113
114 # TODO: Need multiple patrons to test each individual 
115 # status field
116
117 SIPtest::run_sip_tests(@tests);
118
119 1;