#!/bin/env perl
use strict;
use warnings;
use Test::More qw(no_plan);

# Same as "use RegistrarDB;", but traps errors
BEGIN { 
  use_ok('RegistrarDB'); 
}

`./init_db`;  # make sure database is in initial state.

ok( my ($albert) 
    = Person->search( name => 'A. Einstein'),     'found a person Einstein');
ok( $albert->name  eq 'A. Einstein',              '  and his name $al->name ');
ok( $albert->phone eq '222-9999',                 '  and his phone $al->phone');

ok( my ($faculty) 
    = Status->search( name => 'faculty'),         'got a status $faculty');

ok( my @al_regs = 
    $albert->registrations( status => $faculty ), 'found courses Al is teaching');

ok( scalar(@al_regs) == 1,                        '  which is exactly one course');
my $al_reg = pop @al_regs;
ok( $al_reg->course->name eq 'physics',           '  which is physics');
ok( $al_reg->status->name eq 'faculty',           '  which he is teaching');

my $newPerson = Person->create({ name=>"Santa", phone=>"000-0000"});
ok($newPerson, 'created a new person');

my @people = Person->retrieve_all;
#print " number of people : " . scalar @people . "\n";
#foreach my $person (@people){
#  print "  " . $person->name . "\n";
#}
ok(scalar @people == 9,                           '9 people in database ');
