forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed unit tests around routes in actions
- Loading branch information
Showing
25 changed files
with
1,180 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
x-pack/plugins/actions/server/extend_route_with_license_check.test.ts
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
x-pack/plugins/actions/server/extend_route_with_license_check.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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 Boom from 'boom'; | ||
import { LicenseState } from './license_state'; | ||
|
||
export function verifyApiAccess(licenseState: LicenseState) { | ||
const licenseCheckResults = licenseState.getLicenseInformation(); | ||
|
||
if (licenseCheckResults.showAppLink && licenseCheckResults.enableAppLink) { | ||
return null; | ||
} | ||
|
||
throw Boom.forbidden(licenseCheckResults.message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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 { of } from 'rxjs'; | ||
import { LicenseState } from './license_state'; | ||
import { LICENSE_CHECK_STATE, ILicense } from '../../../licensing/server'; | ||
|
||
export const mockLicenseState = () => { | ||
const license: ILicense = { | ||
uid: '123', | ||
status: 'active', | ||
isActive: true, | ||
signature: 'sig', | ||
isAvailable: true, | ||
toJSON: () => ({ | ||
signature: 'sig', | ||
}), | ||
getUnavailableReason: () => undefined, | ||
hasAtLeast() { | ||
return true; | ||
}, | ||
check() { | ||
return { | ||
state: LICENSE_CHECK_STATE.Valid, | ||
}; | ||
}, | ||
getFeature() { | ||
return { | ||
isAvailable: true, | ||
isEnabled: true, | ||
}; | ||
}, | ||
}; | ||
return new LicenseState(of(license)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/actions/server/routes/_mock_handler_arguments.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { RequestHandlerContext, KibanaRequest, KibanaResponseFactory } from 'kibana/server'; | ||
import { identity } from 'lodash'; | ||
|
||
export function mockHandlerArguments( | ||
{ actionsClient, listTypes: listTypesRes = [] }: any, | ||
req: any, | ||
res?: Array<MethodKeysOf<KibanaResponseFactory>> | ||
): [RequestHandlerContext, KibanaRequest<any, any, any, any>, KibanaResponseFactory] { | ||
const listTypes = jest.fn(() => listTypesRes); | ||
return [ | ||
({ | ||
actions: { | ||
listTypes, | ||
getActionsClient() { | ||
return ( | ||
actionsClient || { | ||
get: jest.fn(), | ||
delete: jest.fn(), | ||
update: jest.fn(), | ||
find: jest.fn(), | ||
create: jest.fn(), | ||
} | ||
); | ||
}, | ||
}, | ||
} as unknown) as RequestHandlerContext, | ||
req as KibanaRequest<any, any, any, any>, | ||
mockResponseFactory(res), | ||
]; | ||
} | ||
|
||
export const mockResponseFactory = (resToMock: Array<MethodKeysOf<KibanaResponseFactory>> = []) => { | ||
const factory: jest.Mocked<KibanaResponseFactory> = { | ||
ok: jest.fn(), | ||
accepted: jest.fn(), | ||
noContent: jest.fn(), | ||
redirected: jest.fn(), | ||
badRequest: jest.fn(), | ||
unauthorized: jest.fn(), | ||
forbidden: jest.fn(), | ||
notFound: jest.fn(), | ||
conflict: jest.fn(), | ||
internalError: jest.fn(), | ||
customError: jest.fn(), | ||
custom: jest.fn(), | ||
}; | ||
resToMock.forEach((key: string) => { | ||
if (key in factory) { | ||
Object.defineProperty(factory, key, { | ||
value: jest.fn(identity), | ||
}); | ||
} | ||
}); | ||
return (factory as unknown) as KibanaResponseFactory; | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.