Skip to content

Commit

Permalink
Add unit tests for proper access calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Sep 24, 2024
1 parent b1dd035 commit ac11af5
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import { usageCountersServiceMock } from '@kbn/usage-collection-plugin/server/usage_counters/usage_counters_service.mock';
import { findRulesRoute } from './find_rules_route';
import { findRulesRoute, findInternalRulesRoute } from './find_rules_route';
import { httpServiceMock } from '@kbn/core/server/mocks';
import { licenseStateMock } from '../../../../lib/license_state.mock';
import { verifyApiAccess } from '../../../../lib/license_api_access';
Expand All @@ -30,6 +30,18 @@ beforeEach(() => {
});

describe('findRulesRoute', () => {
it('registers the route with public access', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();

findRulesRoute(router, licenseState);
expect(router.get).toHaveBeenCalledWith(
expect.objectContaining({
options: expect.objectContaining({ access: 'public' }),
}),
expect.any(Function)
);
});
it('finds rules with proper parameters', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();
Expand Down Expand Up @@ -435,3 +447,18 @@ describe('findRulesRoute', () => {
});
});
});

describe('findInternalRulesRoute', () => {
it('registers the route without public access', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();

findInternalRulesRoute(router, licenseState);
expect(router.post).toHaveBeenCalledWith(
expect.not.objectContaining({
options: expect.objectContaining({ access: 'public' }),
}),
expect.any(Function)
);
});
});

0 comments on commit ac11af5

Please sign in to comment.