/*! grafana - v3.1.0 - 2016-07-18
 * Copyright (c) 2016 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["test/lib/common","moment","angular","test/specs/helpers","../datasource"],function(a){var b,c,d,e,f;return{setters:[function(a){b=a},function(a){c=a},function(a){d=a},function(a){e=a},function(a){f=a}],execute:function(){b.describe("ElasticDatasource",function(){function a(a){a.jsonData=a.jsonData||{},g.ds=g.$injector.instantiate(f.ElasticDatasource,{instanceSettings:a})}var g=new e["default"].ServiceTestContext;b.beforeEach(b.angularMocks.module("grafana.core")),b.beforeEach(b.angularMocks.module("grafana.services")),b.beforeEach(g.providePhase(["templateSrv","backendSrv"])),b.beforeEach(b.angularMocks.inject(function(a,b,c,d){g.$q=a,g.$httpBackend=c,g.$rootScope=b,g.$injector=d,c.when("GET",/\.html$/).respond("")})),b.describe("When testing datasource with index pattern",function(){b.beforeEach(function(){a({url:"http://es.com",index:"[asd-]YYYY.MM.DD",jsonData:{interval:"Daily"}})}),b.it("should translate index pattern to current day",function(){var a;g.backendSrv.datasourceRequest=function(b){return a=b,g.$q.when({data:{}})},g.ds.testDatasource(),g.$rootScope.$apply();var d=c["default"].utc().format("YYYY.MM.DD");b.expect(a.url).to.be("http://es.com/asd-"+d+"/_stats")})}),b.describe("When issueing metric query with interval pattern",function(){var e,f,h;b.beforeEach(function(){a({url:"http://es.com",index:"[asd-]YYYY.MM.DD",jsonData:{interval:"Daily"}}),g.backendSrv.datasourceRequest=function(a){return e=a,g.$q.when({data:{responses:[]}})},g.ds.query({range:{from:c["default"]([2015,4,30,10]),to:c["default"]([2015,5,1,10])},targets:[{bucketAggs:[],metrics:[],query:"escape\\:test"}]}),g.$rootScope.$apply(),f=e.data.split("\n"),h=d["default"].fromJson(f[0])}),b.it("should translate index pattern to current day",function(){b.expect(h.index).to.eql(["asd-2015.05.30","asd-2015.05.31","asd-2015.06.01"])}),b.it("should json escape lucene query",function(){var a=d["default"].fromJson(f[1]);b.expect(a.query.filtered.query.query_string.query).to.be("escape\\:test")})}),b.describe("When issueing document query",function(){var e,f,h;b.beforeEach(function(){a({url:"http://es.com",index:"test"}),g.backendSrv.datasourceRequest=function(a){return e=a,g.$q.when({data:{responses:[]}})},g.ds.query({range:{from:c["default"]([2015,4,30,10]),to:c["default"]([2015,5,1,10])},targets:[{bucketAggs:[],metrics:[{type:"raw_document"}],query:"test"}]}),g.$rootScope.$apply(),f=e.data.split("\n"),h=d["default"].fromJson(f[0])}),b.it("should set search type to query_then_fetch",function(){b.expect(h.search_type).to.eql("query_then_fetch")}),b.it("should set size",function(){var a=d["default"].fromJson(f[1]);b.expect(a.size).to.be(500)})})})}}});