import { describe , beforeEach , it , sinon , expect , angularMocks } from './lib/common' ; import DruidDatasource from '../src/datasource' ; import TemplateSrvStub from './lib/template_srv_stub' ; import Q from 'q' ; import moment from 'moment' ; describe ( 'ChangeMyNameDatasource' , function ( ) { let ctx = { backendSrv : { } , templateSrv : new TemplateSrvStub ( ) } ; beforeEach ( function ( ) { ctx . $q = Q ; ctx . instanceSettings = { } ; ctx . ds = new DruidDatasource ( ctx . instanceSettings , ctx . backendSrv , ctx . templateSrv , ctx . $q ) ; } ) ; describe ( 'When performing testDatasource' , function ( ) { describe ( 'and an error is returned' , function ( ) { const error = { data : { error : { code : 'Error Code' , message : `An error message.` } } , status : 400 , statusText : 'Bad Request' } ; beforeEach ( function ( ) { ctx . backendSrv . datasourceRequest = function ( options ) { return ctx . $q . reject ( error ) ; } ; } ) ; it ( 'should return error status and a detailed error message' , function ( ) { return ctx . ds . testDatasource ( ) . then ( function ( results ) { expect ( results . status ) . to . equal ( 'error' ) ; expect ( results . message ) . to . equal ( 'Data Source is just a template and has not been implemented yet.' ) ; } ) ; } ) ; } ) ; describe ( 'and the response works' , function ( ) { const response = { data : { } , status : 200 , statusText : 'OK' } ; beforeEach ( function ( ) { ctx . backendSrv . datasourceRequest = function ( options ) { return ctx . $q . when ( { data : response , status : 200 } ) ; } ; } ) ; it ( 'should return success status' , function ( ) { return ctx . ds . testDatasource ( ) . then ( function ( results ) { expect ( results . status ) . to . equal ( 'success' ) ; } ) ; } ) ; } ) ; } ) ; describe ( 'When performing query' , function ( ) { } ) ; } ) ;