Skip to content

Commit

Permalink
fix jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Jan 22, 2020
1 parent 77f91bf commit 94ebeeb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
ExecuteJobFactory,
ImmediateExecuteFn,
JobDocOutput,
ServerFacade,
Logger,
RequestFacade,
ServerFacade,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ beforeEach(() => {

afterEach(() => generatePngObservableFactory.mockReset());

const getMockLogger = () => new LevelLogger();

const encryptHeaders = async headers => {
const crypto = cryptoFactory(mockServer);
return await crypto.encrypt(headers);
Expand All @@ -68,7 +70,7 @@ test(`passes browserTimezone to generatePng`, async () => {
const generatePngObservable = generatePngObservableFactory();
generatePngObservable.mockReturnValue(Rx.of(Buffer.from('')));

const executeJob = executeJobFactory(mockServer, { browserDriverFactory: {} });
const executeJob = executeJobFactory(mockServer, getMockLogger(), { browserDriverFactory: {} });
const browserTimezone = 'UTC';
await executeJob(
'pngJobId',
Expand All @@ -86,7 +88,7 @@ test(`passes browserTimezone to generatePng`, async () => {
});

test(`returns content_type of application/png`, async () => {
const executeJob = executeJobFactory(mockServer, { browserDriverFactory: {} });
const executeJob = executeJobFactory(mockServer, getMockLogger(), { browserDriverFactory: {} });
const encryptedHeaders = await encryptHeaders({});

const generatePngObservable = generatePngObservableFactory();
Expand All @@ -106,7 +108,7 @@ test(`returns content of generatePng getBuffer base64 encoded`, async () => {
const generatePngObservable = generatePngObservableFactory();
generatePngObservable.mockReturnValue(Rx.of(Buffer.from(testContent)));

const executeJob = executeJobFactory(mockServer, { browserDriverFactory: {} });
const executeJob = executeJobFactory(mockServer, getMockLogger(), { browserDriverFactory: {} });
const encryptedHeaders = await encryptHeaders({});
const { content } = await executeJob(
'pngJobId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ beforeEach(() => {

afterEach(() => generatePdfObservableFactory.mockReset());

const getMockLogger = () => new LevelLogger();

const encryptHeaders = async headers => {
const crypto = cryptoFactory(mockServer);
return await crypto.encrypt(headers);
Expand All @@ -68,7 +70,7 @@ test(`passes browserTimezone to generatePdf`, async () => {
const generatePdfObservable = generatePdfObservableFactory();
generatePdfObservable.mockReturnValue(Rx.of(Buffer.from('')));

const executeJob = executeJobFactory(mockServer, { browserDriverFactory: {} });
const executeJob = executeJobFactory(mockServer, getMockLogger(), { browserDriverFactory: {} });
const browserTimezone = 'UTC';
await executeJob(
'pdfJobId',
Expand All @@ -89,7 +91,7 @@ test(`passes browserTimezone to generatePdf`, async () => {
});

test(`returns content_type of application/pdf`, async () => {
const executeJob = executeJobFactory(mockServer, { browserDriverFactory: {} });
const executeJob = executeJobFactory(mockServer, getMockLogger(), { browserDriverFactory: {} });
const encryptedHeaders = await encryptHeaders({});

const generatePdfObservable = generatePdfObservableFactory();
Expand All @@ -109,7 +111,7 @@ test(`returns content of generatePdf getBuffer base64 encoded`, async () => {
const generatePdfObservable = generatePdfObservableFactory();
generatePdfObservable.mockReturnValue(Rx.of(Buffer.from(testContent)));

const executeJob = executeJobFactory(mockServer, { browserDriverFactory: {} });
const executeJob = executeJobFactory(mockServer, getMockLogger(), { browserDriverFactory: {} });
const encryptedHeaders = await encryptHeaders({});
const { content } = await executeJob(
'pdfJobId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ describe('authorized_user_pre_routing', function() {
return mockServer;
};
})();
const getMockLogger = () => ({ warn: jest.fn() });

it('should return with boom notFound when xpackInfo is undefined', async function() {
const mockServer = createMockServer({ xpackInfoUndefined: true });

const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer);
const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer, getMockLogger());
const response = await authorizedUserPreRouting({});
expect(response.isBoom).to.be(true);
expect(response.output.statusCode).to.be(404);
Expand All @@ -73,7 +74,7 @@ describe('authorized_user_pre_routing', function() {
it(`should return with boom notFound when xpackInfo isn't available`, async function() {
const mockServer = createMockServer({ xpackInfoAvailable: false });

const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer);
const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer, getMockLogger());
const response = await authorizedUserPreRouting();
expect(response.isBoom).to.be(true);
expect(response.output.statusCode).to.be(404);
Expand All @@ -82,15 +83,15 @@ describe('authorized_user_pre_routing', function() {
it('should return with null user when security is disabled in Elasticsearch', async function() {
const mockServer = createMockServer({ securityEnabled: false });

const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer);
const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer, getMockLogger());
const response = await authorizedUserPreRouting();
expect(response).to.be(null);
});

it('should return with boom unauthenticated when security is enabled but no authenticated user', async function() {
const mockServer = createMockServer({ user: null });

const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer);
const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer, getMockLogger());
const response = await authorizedUserPreRouting();
expect(response.isBoom).to.be(true);
expect(response.output.statusCode).to.be(401);
Expand All @@ -102,7 +103,7 @@ describe('authorized_user_pre_routing', function() {
config: { 'xpack.reporting.roles.allow': ['.reporting_user'] },
});

const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer);
const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer, getMockLogger());
const response = await authorizedUserPreRouting();
expect(response.isBoom).to.be(true);
expect(response.output.statusCode).to.be(403);
Expand All @@ -115,7 +116,7 @@ describe('authorized_user_pre_routing', function() {
config: { 'xpack.reporting.roles.allow': ['.reporting_user'] },
});

const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer);
const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer, getMockLogger());
const response = await authorizedUserPreRouting();
expect(response).to.be(user);
});
Expand All @@ -127,7 +128,7 @@ describe('authorized_user_pre_routing', function() {
config: { 'xpack.reporting.roles.allow': [] },
});

const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer);
const authorizedUserPreRouting = authorizedUserPreRoutingFactory(mockServer, getMockLogger());
const response = await authorizedUserPreRouting();
expect(response).to.be(user);
});
Expand Down

0 comments on commit 94ebeeb

Please sign in to comment.