server/src/tests/Controllers/GeoStatsControllerTest.php
changeset 320 0fce13da58af
parent 319 78990a8a069b
child 387 7fba86fa8604
--- a/server/src/tests/Controllers/GeoStatsControllerTest.php	Tue Oct 04 11:58:39 2016 +0200
+++ b/server/src/tests/Controllers/GeoStatsControllerTest.php	Tue Oct 04 13:53:56 2016 +0200
@@ -8,6 +8,9 @@
             'index' => env('ELASTICSEARCH_INDEX'),
             'body' => [
                 "size" => 0,
+                "query" => [
+                    'match_all' => []
+                ],
                 "aggs" => [
                     "geos" => [
                         "terms" => [
@@ -60,4 +63,105 @@
             '3027939' => 851
         ]]);
     }
+
+
+    public function testGetIndexEarth()
+    {
+        $query = [
+            'index' => env('ELASTICSEARCH_INDEX'),
+            'body' => [
+                "size" => 0,
+                "query" => [
+                    'match_all' => []
+                ],
+                "aggs" => [
+                    "geos" => [
+                        "terms" => [
+                            "size" => 0,
+                            "field" => "geonames_hierarchy"
+                        ]
+                    ]
+                ]
+            ]
+        ];
+
+        Es::shouldReceive('search')
+                ->once()
+                ->with($query)
+                ->andReturn(json_decode("{
+  \"took\" : 17,
+  \"timed_out\" : false,
+  \"_shards\" : {
+    \"total\" : 1,
+    \"successful\" : 1,
+    \"failed\" : 0
+  },
+  \"hits\" : {
+    \"total\" : 3011,
+    \"max_score\" : 0.0,
+    \"hits\" : [ ]
+  },
+  \"aggregations\" : {
+    \"geos\" : {
+      \"doc_count_error_upper_bound\" : 0,
+      \"sum_other_doc_count\" : 0,
+      \"buckets\" : []
+    }
+  }
+}", true));
+
+        $this->get('/api/v1/stats/geostats/?area='.config('corpusparole.geonames_earth_geonamesid'))->assertTrue($this->response->isOk(), $this->response->content());
+    }
+
+
+    public function testGetIndexArea()
+    {
+        $query = [
+            'index' => env('ELASTICSEARCH_INDEX'),
+            'body' => [
+                "size" => 0,
+                "query" => [
+                    'term' => [
+                        "geonames_hierarchy" => "code_area"
+                    ]
+                ],
+                "aggs" => [
+                    "geos" => [
+                        "terms" => [
+                            "size" => 0,
+                            "field" => "geonames_hierarchy"
+                        ]
+                    ]
+                ]
+            ]
+        ];
+
+        Es::shouldReceive('search')
+                ->once()
+                ->with($query)
+                ->andReturn(json_decode("{
+  \"took\" : 17,
+  \"timed_out\" : false,
+  \"_shards\" : {
+    \"total\" : 1,
+    \"successful\" : 1,
+    \"failed\" : 0
+  },
+  \"hits\" : {
+    \"total\" : 3011,
+    \"max_score\" : 0.0,
+    \"hits\" : [ ]
+  },
+  \"aggregations\" : {
+    \"geos\" : {
+      \"doc_count_error_upper_bound\" : 0,
+      \"sum_other_doc_count\" : 0,
+      \"buckets\" : []
+    }
+  }
+}", true));
+
+        $this->get('/api/v1/stats/geostats/?area=code_area')->assertTrue($this->response->isOk(), $this->response->content());
+    }
+
 }