#!/usr/bin/env perl

# Copyright (C) 2006  Joshua Hoblitt
#
# $Id: 08_response.t,v 1.3 2007-09-25 23:37:44 jhoblitt Exp $

use strict;
use warnings;

use lib qw( ./lib ./t );

use Test::More tests => 8;

=head1 NAME

t/08_response.t - tests DataStore::Response

=head1 SYNOPSIS
    
    prove t/08_response.t

=cut

use CGI;
use DataStore::Product;
use DataStore::Response;

can_ok('DataStore::Response', qw(
    new
    is_success
    code
    status_line
    data
    request
));

# ->new()

{
    my $dsr = DataStore::Response->new(
        is_success  => undef,
        code        => 500,
        status_line => 'foo',
        data        => 'bar',
        request     => DataStore::Product->new( uri => 'http://example.org/index.txt' ),
    );

    isa_ok($dsr, 'DataStore::Response');
}

eval {
    my $dsr = DataStore::Response->new(
        is_success   => undef,
        code        => 500,
        status_line => 'foo',
        data        => 'bar',
        request     => DataStore::Product->new( uri => 'http://example.org/index.txt' ),
        foo         => 1,
    );
};
like($@, qr/not listed in the validation options/,
    '->new() fails whe passed extra params');

eval {
    my $dsr = DataStore::Response->new( is_success => 2 );
};
like($@, qr/is 0, 1, or undef/,
    '->new() fails when is_success is not valid');

eval {
    my $dsr = DataStore::Response->new( code => 5000 );
};
like($@, qr/did not pass regex check/,
    '->new() fails when code is not valid');

eval {
    my $dsr = DataStore::Response->new( status_line => '' );
};
like($@, qr/did not pass regex check/,
    '->new() fails when status_line is not valid');

eval {
    my $dsr = DataStore::Response->new(
        request => CGI->new,
    );
};
like($@, qr/was not a 'DataStore::Record' /,
    '->new() fails when response is not valid');

eval {
    my $dsr = DataStore::Response->new;
};
like($@, qr/Mandatory parameters/,
    '->new() fails when not passed all manadator params');

# accessor tests unneeded as they are all generated by Class::Accessor::Fast
