#!/usr/bin/env perl
use strict;
use warnings;

use Test::More;
use Test::Exception;
use DBI;

use PUC::Module::WebApp::SQLiteStore;
## no critic (ProhibitConstantPragma)
use constant CLASS => 'PUC::Module::WebApp::SQLiteStore';
## use critic

my $store;
lives_ok {
    $store = CLASS->new( dbfile => ':memory:' );
}
'New memory store';

subtest 'Create the database table' => sub {
    $store->create_local_store;
    my $dbh;
    note 'Connecting to ' . $store->dsn;
    lives_ok {
        $dbh = DBI->connect_cached( $store->dsn );
    }
    'Connection to in-memory database';

    my $r = $dbh->selectrow_hashref( <<'SQL', { RaiseError => 1 } );
        PRAGMA main.table_info('webapps')
SQL

    ok exists( $r->{name} ),
      'First column defined';
    ok $r->{pk},
      'First column is part of primary key';
    ok $r->{notnull},
      'First column is NOT NULL';
};

done_testing;
