Added corpusinfo endpoint
Change-Id: I81a24670e437dad5ac449566eac9460a0819ef18
diff --git a/t/corpus_info.t b/t/corpus_info.t
new file mode 100644
index 0000000..e245422
--- /dev/null
+++ b/t/corpus_info.t
@@ -0,0 +1,44 @@
+use Mojo::Base -strict;
+use Test::Mojo;
+use Test::More;
+use Mojo::File qw/path/;
+
+
+#####################
+# Start Fake server #
+#####################
+my $mount_point = '/api/';
+$ENV{KALAMAR_API} = $mount_point;
+
+my $t = Test::Mojo->new('Kalamar');
+
+# Mount fake backend
+# Get the fixture path
+my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'fixtures');
+my $fake_backend = $t->app->plugin(
+ Mount => {
+ $mount_point =>
+ $fixtures_path->child('fake_backend.pl')
+ }
+);
+# Configure fake backend
+$fake_backend->pattern->defaults->{app}->log($t->app->log);
+
+# Query passed
+$t->get_ok('/corpus2')
+ ->status_is(200)
+ ->json_is('/documents', 11)
+ ->json_is('/tokens', 665842)
+ ->json_is('/sentences', 25074)
+ ->json_is('/paragraphs', 772)
+ ;
+
+$t->get_ok('/corpus2?cq=docSigle+%3D+\"GOE/AGA\"')
+ ->json_is('/documents', 5)
+ ->json_is('/tokens', 108557)
+ ->json_is('/sentences', 3835)
+ ->json_is('/paragraphs', 124)
+ ;
+
+done_testing;
+__END__
diff --git a/t/fixtures/fake_backend.pl b/t/fixtures/fake_backend.pl
index a49b05f..89ad3c3 100644
--- a/t/fixtures/fake_backend.pl
+++ b/t/fixtures/fake_backend.pl
@@ -125,6 +125,23 @@
};
+# Statistics endpoint
+get '/statistics' => sub {
+ my $c = shift;
+ my $v = $c->validation;
+ $v->optional('corpusQuery');
+
+ my @list = 'corpusinfo';
+ if ($v->param('corpusQuery')) {
+ push @list, $v->param('corpusQuery');
+ };
+ my $slug = slugify(join('_', @list));
+
+ # Get response based on query parameter
+ my $response = $c->load_response($slug);
+ return $c->render(%$response);
+};
+
############
# Auth API #
############
diff --git a/t/fixtures/response_corpusinfo.json b/t/fixtures/response_corpusinfo.json
new file mode 100644
index 0000000..1918da5
--- /dev/null
+++ b/t/fixtures/response_corpusinfo.json
@@ -0,0 +1,9 @@
+{
+ "status" : 200,
+ "json" : {
+ "documents":11,
+ "tokens":665842,
+ "sentences":25074,
+ "paragraphs":772
+ }
+}
diff --git a/t/fixtures/response_corpusinfo_docsigle-goeaga.json b/t/fixtures/response_corpusinfo_docsigle-goeaga.json
new file mode 100644
index 0000000..9a65412
--- /dev/null
+++ b/t/fixtures/response_corpusinfo_docsigle-goeaga.json
@@ -0,0 +1,9 @@
+{
+ "status" : 200,
+ "json" : {
+ "documents":5,
+ "tokens":108557,
+ "sentences":3835,
+ "paragraphs":124
+ }
+}