Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
fetzerch committed Nov 10, 2022
1 parent b4dcdb1 commit 7af2213
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 60 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -3,6 +3,8 @@

# Sun and Moon Datasource Plugin for Grafana



SunAndMoon is a Datasource Plugin for [Grafana](https://grafana.org) that
calculates the position of Sun and Moon as well as the Moon illumination using
[SunCalc](https://github.com/mourner/suncalc).
Expand Down
59 changes: 10 additions & 49 deletions src/DataSource.test.ts
Expand Up @@ -74,37 +74,6 @@ describe('SunAndMoonDatasource', () => {
});
});

it('query should not return data for hidden targets', () => {
const options = {
targets: [
{ refId: 'A', target: ['moon_illumination'] },
{ refId: 'B', target: ['moon_altitude'], hide: true },
],
maxDataPoints: 10,
range: {
from: dateTime('2019/03/26', 'YYYY/MM/DD'),
to: dateTime('2019/03/27', 'YYYY/MM/DD'),
},
} as DataQueryRequest<SunAndMoonQuery>;
return datasource.query(options).then((results) => {
expect(results.data).toHaveLength(1);
});
});

it('query should support position override', async () => {
const options = {
targets: [{ refId: 'A', target: ['sun_altitude'], latitude: '50', longitude: '20' }],
maxDataPoints: 10,
range: {
from: dateTime('2019/03/26', 'YYYY/MM/DD'),
to: dateTime('2019/03/27', 'YYYY/MM/DD'),
},
} as DataQueryRequest<SunAndMoonQuery>;
return datasource.query(options).then((results) => {
expect(results.data).toHaveLength(options.targets.length);
});
});

it('query should inform user about position override errors', () => {
const options = {
targets: [{ refId: 'A', target: ['moon_illumination'], latitude: 'xxx', longitude: 'yyy' }],
Expand All @@ -117,21 +86,7 @@ describe('SunAndMoonDatasource', () => {
return expect(datasource.query(options)).rejects.toThrow('Error in query');
});

it('query should support legacy single value metrics', () => {
const options = {
targets: [
{ refId: 'A', target: 'sun_altitude' },
],
maxDataPoints: 10,
range: {
from: dateTime('2019/03/26', 'YYYY/MM/DD'),
to: dateTime('2019/03/27', 'YYYY/MM/DD'),
},
} as any;
return datasource.query(options).then((results) => {
expect(results.data).toHaveLength(1);
});
});


it('query should support legacy annotation queries', () => {
const options = {
Expand All @@ -144,15 +99,21 @@ describe('SunAndMoonDatasource', () => {
to: dateTime('2019/03/27', 'YYYY/MM/DD'),
},
} as any;
return datasource.query(options).then((results) => {
expect(results.data).toHaveLength(2);
return datasource.query(


options).then((results) => {
expect(results.data).toHaveLength(
2);
});
});

it('testDatasource should return success for valid gps position', () => {
datasource.latitude = 0;
datasource.longitude = 0;
return datasource.testDatasource().then((results) => {
return datasource.testDatasource().then(

(results) => {
expect(results).toMatchObject({ status: 'success' });
});
});
Expand Down
17 changes: 6 additions & 11 deletions src/migrations.test.ts
@@ -1,23 +1,18 @@
import { migrateQuery } from './migrations'

describe('Migrations', () => {
it('should migrate single string queries', () => {
let query = {
target: "single_string"
};

migrateQuery(query);

expect(query).toStrictEqual({
target: ["single_string"]
})
});

it('should migrate legacy annotation queries', () => {
let query = {
query: "*, annotation1 ,annotation2"
};







migrateQuery(query);

expect(query).toStrictEqual({
Expand Down

0 comments on commit 7af2213

Please sign in to comment.