-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into reporting/tests-serverless-improvements-ii
- Loading branch information
Showing
13 changed files
with
213 additions
and
53 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
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
96 changes: 96 additions & 0 deletions
96
x-pack/plugins/enterprise_search/common/utils/licensing.test.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,96 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { ILicense } from '@kbn/licensing-plugin/public'; | ||
|
||
import { hasEnterpriseLicense } from './licensing'; | ||
|
||
describe('licensing utils', () => { | ||
const baseLicense: ILicense = { | ||
isActive: true, | ||
type: 'trial', | ||
isAvailable: true, | ||
signature: 'fake', | ||
toJSON: jest.fn(), | ||
getUnavailableReason: jest.fn().mockReturnValue(undefined), | ||
hasAtLeast: jest.fn().mockReturnValue(false), | ||
check: jest.fn().mockReturnValue({ state: 'valid' }), | ||
getFeature: jest.fn().mockReturnValue({ isAvailable: false, isEnabled: false }), | ||
}; | ||
describe('hasEnterpriseLicense', () => { | ||
let license: ILicense; | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
license = { | ||
...baseLicense, | ||
}; | ||
}); | ||
it('returns true for active enterprise license', () => { | ||
license.type = 'enterprise'; | ||
|
||
expect(hasEnterpriseLicense(license)).toEqual(true); | ||
}); | ||
it('returns true for active trial license', () => { | ||
expect(hasEnterpriseLicense(license)).toEqual(true); | ||
}); | ||
it('returns false for active basic license', () => { | ||
license.type = 'basic'; | ||
|
||
expect(hasEnterpriseLicense(license)).toEqual(false); | ||
}); | ||
it('returns false for active gold license', () => { | ||
license.type = 'gold'; | ||
|
||
expect(hasEnterpriseLicense(license)).toEqual(false); | ||
}); | ||
it('returns false for active platinum license', () => { | ||
license.type = 'platinum'; | ||
|
||
expect(hasEnterpriseLicense(license)).toEqual(false); | ||
}); | ||
it('returns false for inactive enterprise license', () => { | ||
license.type = 'enterprise'; | ||
license.isActive = false; | ||
|
||
expect(hasEnterpriseLicense(license)).toEqual(false); | ||
}); | ||
it('returns false for inactive trial license', () => { | ||
license.isActive = false; | ||
|
||
expect(hasEnterpriseLicense(license)).toEqual(false); | ||
}); | ||
it('returns false for inactive basic license', () => { | ||
license.type = 'basic'; | ||
license.isActive = false; | ||
|
||
expect(hasEnterpriseLicense(license)).toEqual(false); | ||
}); | ||
it('returns false for inactive gold license', () => { | ||
license.type = 'gold'; | ||
license.isActive = false; | ||
|
||
expect(hasEnterpriseLicense(license)).toEqual(false); | ||
}); | ||
it('returns false for inactive platinum license', () => { | ||
license.type = 'platinum'; | ||
license.isActive = false; | ||
|
||
expect(hasEnterpriseLicense(license)).toEqual(false); | ||
}); | ||
it('returns false for active license is missing type', () => { | ||
delete license.type; | ||
|
||
expect(hasEnterpriseLicense(license)).toEqual(false); | ||
}); | ||
it('returns false for null license', () => { | ||
expect(hasEnterpriseLicense(null)).toEqual(false); | ||
}); | ||
it('returns false for undefined license', () => { | ||
expect(hasEnterpriseLicense(undefined)).toEqual(false); | ||
}); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/enterprise_search/common/utils/licensing.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,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { ILicense } from '@kbn/licensing-plugin/public'; | ||
|
||
/* hasEnterpriseLicense return if the given license is an active `enterprise` or `trial` license | ||
*/ | ||
export function hasEnterpriseLicense(license: ILicense | null | undefined): boolean { | ||
if (license === undefined || license === null) return false; | ||
const qualifyingLicenses = ['enterprise', 'trial']; | ||
return license.isActive && qualifyingLicenses.includes(license?.type ?? ''); | ||
} |
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
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
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
Oops, something went wrong.