ArangoDB
view release on metacpan or search on metacpan
t/03_document.t view on Meta::CPAN
use strict;
use Test::More;
use Test::Fatal qw(lives_ok dies_ok exception);
use Test::Mock::Guard;
use Test::Deep;
use ArangoDB;
use JSON;
if ( !$ENV{TEST_ARANGODB_PORT} ) {
plan skip_all => 'Can"t find port of arangod';
}
my $port = $ENV{TEST_ARANGODB_PORT};
my $config = {
host => 'localhost',
port => $port,
};
init();
sub init {
my $db = ArangoDB->new($config);
map { $_->drop } @{ $db->collections };
}
subtest 'Failed to get document' => sub {
my $db = ArangoDB->new($config);
like exception { $db->document() }, qr/^Failed to get the document/;
};
subtest 'create document' => sub {
my $db = ArangoDB->new($config);
my $coll = $db->create('foo');
my $doc1 = $coll->save( { foo => 'bar', baz => 10 } );
isa_ok $doc1, 'ArangoDB::Document';
is "$doc1", $doc1->document_handle, 'Test for ArangoDB::Document overload';
ok defined $doc1->revision;
is $doc1->document_handle, $doc1->collection_id . '/' . $doc1->id;
is_deeply $doc1->content, { foo => 'bar', baz => 10 };
is $doc1->get('foo'), 'bar';
my $doc2 = $db->document($doc1);
is_deeply $doc1, $doc2;
my $doc3 = $coll->save();
is_deeply $doc3->content, {};
my $e = exception {
my $guard = mock_guard(
'ArangoDB::Connection' => {
http_post => sub {die}
}
);
$coll->save( { foo => 'bar' } );
};
like $e, qr/^Failed to save the new document/;
};
subtest 'Delete document' => sub {
my $db = ArangoDB->new($config);
my $coll = $db->collection('foo');
my $doc = $coll->save( { foo => 'bar' } );
( run in 1.129 second using v1.01-cache-2.11-cpan-54e63673c56 )