This repository has been archived by the owner on Jan 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from CorpGlory/kentik-custom-dimensions-suppor…
…t-#46 Kentik custom dimensions support #46
- Loading branch information
Showing
6 changed files
with
174 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,60 @@ | ||
import { Datasource } from '../../src/datasource/module'; | ||
import {Datasource} from '../../src/datasource/module'; | ||
import {KentikAPI} from '../../src/datasource/kentikAPI'; | ||
import {KentikProxy} from '../../src/datasource/kentikProxy'; | ||
|
||
describe('KentikDatasource', () => { | ||
let ctx: any = {}; | ||
|
||
beforeEach(function () { | ||
ctx.kentikProxySrv = {}; | ||
ctx.templateSrv = {}; | ||
|
||
let instanceSettings = {}; | ||
ctx.ds = new Datasource(instanceSettings, {}, ctx.templateSrv); | ||
}); | ||
const data = { | ||
customDimensions: [ | ||
{ | ||
display_name: 'just-testing', name: 'c_test', | ||
populators: [ | ||
{ value: 'value1' }, { value: 'value2' } | ||
] | ||
}, | ||
{ | ||
display_name: 'just-testing-2', name: 'c_test_2', | ||
populators: [ | ||
{ value: 'value3' }, { value: 'value4' } | ||
] | ||
} | ||
], | ||
rows: [ | ||
{ src_geo_city: 'city' } | ||
] | ||
}; | ||
beforeEach(() => createDatasourceInstance(ctx, data)); | ||
|
||
describe('When querying Kentik data', () => { | ||
it('pass', (done) => { | ||
done(); | ||
it('Should return tag values for default dimensions', async () => { | ||
const tagValues = await ctx.ds.getTagValues({ key: 'Source City' }); | ||
expect(tagValues).toHaveLength(1); | ||
expect(tagValues[0]).toEqual({ text: 'city' }); | ||
}); | ||
|
||
it('Should return tag values for custom dimensions', async () => { | ||
const tagValues = await ctx.ds.getTagValues({ key: 'Custom just-testing-2' }); | ||
expect(tagValues).toHaveLength(2); | ||
expect(tagValues[0]).toEqual({ text: 'value3' }); | ||
expect(tagValues[1]).toEqual({ text: 'value4' }); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
function createDatasourceInstance(ctx, data) { | ||
ctx.instanceSettings = {}; | ||
ctx.templateSrv = {}; | ||
ctx.backendSrv = { | ||
datasourceRequest: function () { | ||
return Promise.resolve({ | ||
status: 200, data | ||
}); | ||
} | ||
}; | ||
|
||
ctx.kentikAPI = new KentikAPI(ctx.backendSrv); | ||
ctx.kentikProxy = new KentikProxy({}, ctx.kentikAPI); | ||
|
||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.kentikProxy); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {KentikAPI} from '../../src/datasource/kentikAPI'; | ||
import {KentikProxy} from '../../src/datasource/kentikProxy'; | ||
|
||
describe('KentikProxy', () => { | ||
let ctx: any = {}; | ||
|
||
describe('When getting custom dimensions', () => { | ||
const data = { | ||
customDimensions: [ | ||
{ | ||
display_name: 'just-testing', name: 'c_test', | ||
populators: [ | ||
{ value: 'value1' }, { value: 'value2' } | ||
] | ||
}, | ||
{ | ||
display_name: 'just-testing-2', name: 'c_test_2', | ||
populators: [ | ||
{ value: 'value3' }, { value: 'value4' } | ||
] | ||
} | ||
] | ||
}; | ||
beforeEach(() => getKentikProxyInstance(ctx, data)); | ||
|
||
it('Should parse it properly', async () => { | ||
const dimensions = await ctx.kentikProxy.getCustomDimensions(); | ||
expect(dimensions).toHaveLength(2); | ||
expect(dimensions[0]).toEqual({ | ||
text: 'Custom just-testing', | ||
value: 'c_test', | ||
field: 'c_test', | ||
values: ['value1', 'value2'], | ||
}); | ||
expect(dimensions[1]).toEqual({ | ||
text: 'Custom just-testing-2', | ||
value: 'c_test_2', | ||
field: 'c_test_2', | ||
values: ['value3', 'value4'], | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
function getKentikProxyInstance(ctx, data) { | ||
ctx.backendSrv = { | ||
datasourceRequest: function () { | ||
return Promise.resolve({ | ||
status: 200, data | ||
}); | ||
} | ||
}; | ||
|
||
ctx.kentikAPI = new KentikAPI(ctx.backendSrv); | ||
ctx.kentikProxy = new KentikProxy({}, ctx.kentikAPI); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters