Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
itssharmasandeep committed Sep 13, 2023
1 parent 66844f4 commit 18207cc
Showing 1 changed file with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ import { TopologyMetricCategoryModel } from './metrics/topology-metric-category.
import { TopologyMetricWithCategoryModel } from './metrics/topology-metric-with-category.model';
import { TopologyMetricsModel } from './metrics/topology-metrics.model';
import { TopologyDataSourceModel } from './topology-data-source.model';
import { GraphQlFieldFilter } from '../../../../graphql/model/schema/filter/field/graphql-field-filter';
import { GraphQlOperatorType } from '../../../../graphql/model/schema/filter/graphql-filter';

describe('topology data source model', () => {
const testTimeRange = { startTime: new Date(1568907645141), endTime: new Date(1568911245141) };
let model!: TopologyDataSourceModel;
let totalQueries: number = 0;
let lastEmittedQuery: unknown;
let lastEmittedQueryRequestOption: GraphQlRequestOptions | undefined;

const filters = [
new GraphQlFieldFilter('service_id', GraphQlOperatorType.Equals, 'test-id'),
new GraphQlFieldFilter('backend_id', GraphQlOperatorType.Equals, 'test-backend-id')
];

const createCategoryModel = (
name: string,
minValue: number,
Expand Down Expand Up @@ -81,17 +89,24 @@ describe('topology data source model', () => {
model.entityType = ObservabilityEntityType.Service;
model.nodeMetricsModel = createTopologyMetricsModel('numCalls', MetricAggregationType.Average);
model.edgeMetricsModel = createTopologyMetricsModel('duration', MetricAggregationType.Average);
model.edgeFilterConfig = { entityType: ObservabilityEntityType.Backend, fields: ['backend_id'] };

model.api = mockApi as ModelApi;
model.query$.subscribe(query => {
lastEmittedQuery = query.buildRequest([]);
if (totalQueries === 0) {
// Without filters
lastEmittedQuery = query.buildRequest([]);
} else {
// With filters
lastEmittedQuery = query.buildRequest(filters);
}
lastEmittedQueryRequestOption = query.requestOptions;
totalQueries += 1;
});
model.getData();
});

test('builds expected request', () => {
model.getData();
test('builds expected request without filters', () => {
expect(lastEmittedQuery).toEqual({
requestType: ENTITY_TOPOLOGY_GQL_REQUEST,
rootNodeType: ObservabilityEntityType.Service,
Expand All @@ -102,6 +117,7 @@ describe('topology data source model', () => {
]
},
rootNodeFilters: [],
edgeFilters: [],
rootNodeLimit: 100,
timeRange: new GraphQlTimeRange(testTimeRange.startTime, testTimeRange.endTime),
downstreamNodeSpecifications: new Map<ObservabilityEntityType, TopologyNodeSpecification>([
Expand Down Expand Up @@ -147,4 +163,38 @@ describe('topology data source model', () => {
isolated: true
});
});

test('builds expected request with filters', () => {
expect(lastEmittedQuery).toEqual({
requestType: ENTITY_TOPOLOGY_GQL_REQUEST,
rootNodeType: ObservabilityEntityType.Service,
rootNodeSpecification: {
titleSpecification: expect.objectContaining({ name: 'name' }),
metricSpecifications: [
expect.objectContaining({ metric: 'numCalls', aggregation: MetricAggregationType.Average })
]
},
rootNodeFilters: [filters[0]],
edgeFilters: [filters[1]],
rootNodeLimit: 100,
timeRange: new GraphQlTimeRange(testTimeRange.startTime, testTimeRange.endTime),
downstreamNodeSpecifications: new Map<ObservabilityEntityType, TopologyNodeSpecification>([
[
ObservabilityEntityType.Backend,
{
titleSpecification: expect.objectContaining({ name: 'name' }),
metricSpecifications: [
expect.objectContaining({ metric: 'numCalls', aggregation: MetricAggregationType.Average })
]
}
]
]),
upstreamNodeSpecifications: new Map(),
edgeSpecification: {
metricSpecifications: [
expect.objectContaining({ metric: 'duration', aggregation: MetricAggregationType.Average })
]
}
});
});
});

0 comments on commit 18207cc

Please sign in to comment.