Skip to content

Commit

Permalink
Refactor to Jest test
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Mar 17, 2020
1 parent a38eeb4 commit ca2cd89
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { kibanaResponseFactory } from '../../../../../../../../../src/core/server';
import { licensePreRoutingFactory } from '../license_pre_routing_factory';

describe('license_pre_routing_factory', () => {
describe('#reportingFeaturePreRoutingFactory', () => {
let mockDeps;
let mockLicenseCheckResults;

beforeEach(() => {
mockDeps = {
__LEGACY: {
server: {
plugins: {
xpack_main: {
info: {
feature: () => ({
getLicenseCheckResults: () => mockLicenseCheckResults,
}),
},
},
},
},
},
requestHandler: jest.fn(),
};
});

describe('isAvailable is false', () => {
beforeEach(() => {
mockLicenseCheckResults = {
isAvailable: false,
};
});

it('replies with 403', async () => {
const licensePreRouting = licensePreRoutingFactory(mockDeps);
const response = await licensePreRouting({}, {}, kibanaResponseFactory);
expect(response.status).toBe(403);
});
});

describe('isAvailable is true', () => {
beforeEach(() => {
mockLicenseCheckResults = {
isAvailable: true,
};
});

it('it calls the wrapped handler', async () => {
const licensePreRouting = licensePreRoutingFactory(mockDeps);
await licensePreRouting({}, {}, kibanaResponseFactory);
expect(mockDeps.requestHandler).toHaveBeenCalledTimes(1);
});
});
});
});

This file was deleted.

0 comments on commit ca2cd89

Please sign in to comment.