import DatabaseService from './databases' ; import api from 'teleport/services/api' ; test ( 'correct formatting of database fetch response' , async ( ) => { jest . spyOn ( api , 'get' ) . mockResolvedValue ( mockResponse ) ; const database = new DatabaseService ( ) ; const response = await database . fetchDatabases ( 'im-a-cluster' ) ; expect ( response ) . toEqual ( [ { name : 'aurora' , desc : 'PostgreSQL 11.6: AWS Aurora' , title : 'RDS PostgreSQL' , protocol : 'postgres' , tags : [ 'cluster: root' , 'env: aws' ] , } , ] ) ; } ) ; test ( 'null response from database fetch' , async ( ) => { jest . spyOn ( api , 'get' ) . mockResolvedValue ( null ) ; const database = new DatabaseService ( ) ; const response = await database . fetchDatabases ( 'im-a-cluster' ) ; expect ( response ) . toEqual ( [ ] ) ; } ) ; describe ( 'correct formatting of all type and protocol combos' , ( ) => { test . each `
    type                 | protocol                 | combined
    ${ 'self-hosted' }     | ${ 'mysql' }               | ${ 'Self-hosted MySQL' }
    ${ 'rds' }             | ${ 'mysql' }               | ${ 'RDS MySQL' }
    ${ 'self-hosted' }     | ${ 'postgres' }            | ${ 'Self-hosted PostgreSQL' }
    ${ 'rds' }             | ${ 'postgres' }            | ${ 'RDS PostgreSQL' }
    ${ 'gcp' }             | ${ 'postgres' }            | ${ 'Cloud SQL PostgreSQL' }
    ${ 'redshift' }        | ${ 'postgres' }            | ${ 'Redshift' }
    ${ 'some other type' } | ${ 'some other protocol' } | ${ 'some other type some other protocol' }
  ` ( 'should combine type: $type and protocol: $protocol correctly' , async ( { type , protocol , combined } ) => { jest . spyOn ( api , 'get' ) . mockResolvedValue ( [ { type , protocol } ] ) ; const database = new DatabaseService ( ) ; const response = await database . fetchDatabases ( 'im-a-cluster' ) ; expect ( response [ 0 ] . title ) . toBe ( combined ) ; } ) ; } ) ; test ( 'null labels field in database fetch response' , async ( ) => { jest . spyOn ( api , 'get' ) . mockResolvedValue ( [ { labels : null } ] ) ; const database = new DatabaseService ( ) ; const response = await database . fetchDatabases ( 'im-a-cluster' ) ; expect ( response [ 0 ] . tags ) . toEqual ( [ ] ) ; } ) ; const mockResponse = [ { name : 'aurora' , desc : 'PostgreSQL 11.6: AWS Aurora' , protocol : 'postgres' , type : 'rds' , uri : 'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432' , labels : [ { name : 'cluster' , value : 'root' } , { name : 'env' , value : 'aws' } , ] , } , ] ;