123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- import {doMetricsRequest} from 'sentry/actionCreators/metrics';
- import {Client} from 'sentry/api';
- import {SessionMetric} from 'sentry/utils/metrics/fields';
- describe('Metrics ActionCreator', function () {
- const api = new Client();
- const orgSlug = TestStubs.Organization().slug;
- describe('doMetricsRequest', function () {
- const options = {
- field: [SessionMetric.SESSION],
- orgSlug,
- cursor: undefined,
- environment: [],
- groupBy: ['session.status'],
- interval: '1h',
- limit: 5,
- orderBy: SessionMetric.SESSION,
- project: [TestStubs.Project().id],
- query: 'release:123',
- statsPeriod: '14d',
- };
- let mock;
- beforeEach(function () {
- MockApiClient.clearMockResponses();
- mock = MockApiClient.addMockResponse({
- url: `/organizations/${orgSlug}/metrics/data/`,
- body: {
- data: [],
- },
- });
- });
- it('requests metrics data', function () {
- doMetricsRequest(api, options);
- expect(mock).toHaveBeenCalledTimes(1);
- expect(mock).toHaveBeenLastCalledWith(
- `/organizations/${orgSlug}/metrics/data/`,
- expect.objectContaining({
- query: {
- environment: [],
- field: ['sentry.sessions.session'],
- groupBy: ['session.status'],
- interval: '1h',
- orderBy: 'sentry.sessions.session',
- per_page: 5,
- project: ['2'],
- query: 'release:123',
- statsPeriod: '14d',
- },
- })
- );
- });
- it('fills in interval based on start and end', function () {
- doMetricsRequest(api, {
- ...options,
- statsPeriod: undefined,
- interval: undefined,
- start: '2022-01-01T00:00:00',
- end: '2022-03-01T00:00:00',
- });
- expect(mock).toHaveBeenCalledTimes(1);
- expect(mock).toHaveBeenLastCalledWith(
- `/organizations/${orgSlug}/metrics/data/`,
- expect.objectContaining({
- query: {
- environment: [],
- field: ['sentry.sessions.session'],
- groupBy: ['session.status'],
- interval: '4h',
- orderBy: 'sentry.sessions.session',
- per_page: 5,
- project: ['2'],
- query: 'release:123',
- start: '2022-01-01T00:00:00.000',
- end: '2022-03-01T00:00:00.000',
- },
- })
- );
- });
- it('ignores falsy fields and groupBys', function () {
- doMetricsRequest(api, {
- ...options,
- field: [SessionMetric.SESSION, ''],
- groupBy: ['session.status', ''],
- });
- expect(mock).toHaveBeenCalledTimes(1);
- expect(mock).toHaveBeenLastCalledWith(
- `/organizations/${orgSlug}/metrics/data/`,
- expect.objectContaining({
- query: expect.objectContaining({
- field: ['sentry.sessions.session'],
- groupBy: ['session.status'],
- }),
- })
- );
- });
- });
- });
|