Handle merges in the diff view.
[catagits/Gitalist.git] / t / json_view.t
CommitLineData
5f79e33f 1#!/usr/bin/env perl
cce03a80 2
3use FindBin qw/$Bin/;
4BEGIN { do "$FindBin::Bin/../script/env" or die $@ }
5
5f79e33f 6use strict;
7use warnings;
8use Test::More;
9use HTTP::Request::Common;
5f79e33f 10use JSON::Any;
11
cce03a80 12
5f79e33f 13BEGIN {
14 $ENV{GITALIST_CONFIG} = $Bin;
15 $ENV{GITALIST_REPO_DIR} = '';
16 use_ok 'Catalyst::Test', 'Gitalist';
17}
18
19my $j = JSON::Any->new;
20
cce03a80 21my $res = request(GET 'http://localhost/repo1', 'Content-Type' => 'application/json');
5f79e33f 22is $res->code, 200;
23my $data = $j->decode($res->content);
24is ref($data), 'HASH';
cce03a80 25delete $data->{owner}
26 if $data && exists $data->{owner};
5f79e33f 27is_deeply $data, {
5f79e33f 28 'is_bare' => 1,
29 '__CLASS__' => 'Gitalist::Git::Repository',
30 'last_change' => '2009-11-12T19:00:34Z',
5f79e33f 31 'name' => 'repo1',
32 'description' => 'some test repository'
33 };
34
53bb75da 35$res = request(GET 'http://localhost/repo1/3f7567c7bdf7e7ebf410926493b92d398333116e/commit', 'Content-Type' => 'application/json');
36is $res->code, 200;
37$data = $j->decode($res->content);
38is ref($data), 'HASH';
39delete $data->{repository}{owner}
40 if $data && exists $data->{repository}{owner};
41is_deeply $data, {
42 'repository' => {
43 'is_bare' => 1,
44 '__CLASS__' => 'Gitalist::Git::Repository',
45 'last_change' => '2009-11-12T19:00:34Z',
46 'name' => 'repo1',
47 'description' => 'some test repository'
48 },
49 '__CLASS__' => 'Gitalist::Git::Object::Commit',
50 'sha1' => '3f7567c7bdf7e7ebf410926493b92d398333116e',
51 'mode' => 0,
52 'type' => 'commit',
53 'modestr' => '----------',
54 'size' => '218'
55};
56
5f79e33f 57done_testing;
58
59