123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import EventView from 'sentry/utils/discover/eventView';
- import {ALL_VIEWS} from 'sentry/views/discover/data';
- import {
- handleCreateQuery,
- handleDeleteQuery,
- handleUpdateQuery,
- handleUpdateQueryName,
- } from 'sentry/views/discover/savedQuery/utils';
- describe('SavedQueries API helpers', () => {
- const api = new MockApiClient();
- const organization = TestStubs.Organization();
- const errorsQuery = ALL_VIEWS.find(view => view.name === 'Errors by Title')!;
- const errorsView = EventView.fromSavedQuery(errorsQuery);
- errorsView.id = '1'; // set id manually as errorsView.id is undefined
- const yAxis = ['count()', 'failure_count()'];
- let mockCall;
- afterEach(() => {
- MockApiClient.clearMockResponses();
- });
- describe('handleCreateQuery', () => {
- beforeEach(() => {
- mockCall = MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/discover/saved/`,
- body: {data: {}, fromBody: {}},
- });
- });
- it('calls the correct API endpoint', async () => {
- const response = await handleCreateQuery(api, organization, errorsView, yAxis);
- expect(mockCall).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- data: expect.objectContaining({yAxis}),
- })
- );
- expect(response).toEqual({data: {}, fromBody: {}});
- });
- });
- describe('handleUpdateQuery', () => {
- beforeEach(() => {
- mockCall = MockApiClient.addMockResponse({
- method: 'PUT',
- url: `/organizations/${organization.slug}/discover/saved/${errorsView.id}/`,
- body: {data: {}, fromBody: {}},
- });
- });
- it('calls the correct API endpoint', async () => {
- const response = await handleUpdateQuery(api, organization, errorsView, yAxis);
- expect(mockCall).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- data: expect.objectContaining({yAxis}),
- })
- );
- expect(response).toEqual({data: {}, fromBody: {}});
- });
- });
- describe('handleUpdateQueryName', () => {
- beforeEach(() => {
- MockApiClient.addMockResponse({
- method: 'PUT',
- url: `/organizations/${organization.slug}/discover/saved/${errorsView.id}/`,
- body: {data: {}, fromBody: {}},
- });
- });
- it('calls the correct API endpoint', async () => {
- const response = await handleUpdateQueryName(api, organization, errorsView);
- expect(response).toEqual({data: {}, fromBody: {}});
- });
- });
- describe('handleDeleteQuery', () => {
- beforeEach(() => {
- MockApiClient.addMockResponse({
- method: 'DELETE',
- url: `/organizations/${organization.slug}/discover/saved/${errorsView.id}/`,
- body: {data: {}, fromBody: {}},
- });
- });
- it('calls the correct API endpoint', async () => {
- const response = await handleDeleteQuery(api, organization, errorsView);
- expect(response).toEqual({data: {}, fromBody: {}});
- });
- });
- });
|