* add skeleton for global_search plugin * base implementation of the server-side service * add utils tests * add server-side mocks * move take_in_array to common folder * implements base of client-side plugin * add tests for server-side service * fix server plugin tests * implement `navigateToUrl` core API * extract processResults for the client-side * fetch server results from the client side * factorize process_results * fix plugin start params * move things around * move all server types to single file * fix types imports * add basic FTR tests * add client-side service tests * add tests for addNavigate * add getDefaultPreference & tests * use optional for RequestHandlerContext * add registerRoutes test * add base test for context * resolve TODO * common nits/doc * common nits/doc on public * update CODEOWNERS * add import for declare statement * add license check on the server-side * add license check on the client-side * eslint * address some review comments * use properly typed errors for obs * add integration tests for the find endpoint * fix unit tests * use licensing start contract * translate the error message * fix eslint rule for test_utils * fix test_utils imports * remove NavigableGlobalSearchResult, use `application.navigateToUrl` instead. * use coreProvider plugin in FTR tests * nits * fix service start params * fix service start params, bis * I really need to fix this typecheck oom error * add README, update missing jsdoc * nits on doc # Conflicts: # .github/CODEOWNERS # rfcs/text/0011_global_search.md
63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
/*
|
|
* 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 { Observable, of, BehaviorSubject } from 'rxjs';
|
|
import { licenseMock } from '../../licensing/common/licensing.mock';
|
|
import { ILicense, LicenseCheck } from '../../licensing/common/types';
|
|
import { LicenseChecker } from './license_checker';
|
|
|
|
describe('LicenseChecker', () => {
|
|
const createLicense = (check: LicenseCheck): ILicense => {
|
|
const license = licenseMock.createLicenseMock();
|
|
license.check.mockReturnValue(check);
|
|
return license;
|
|
};
|
|
|
|
const createLicense$ = (check: LicenseCheck): Observable<ILicense> => of(createLicense(check));
|
|
|
|
it('returns the correct state of the license', () => {
|
|
let checker = new LicenseChecker(createLicense$({ state: 'valid' }));
|
|
expect(checker.getState()).toEqual({ valid: true });
|
|
|
|
checker = new LicenseChecker(createLicense$({ state: 'expired' }));
|
|
expect(checker.getState()).toEqual({ valid: false, message: 'expired' });
|
|
|
|
checker = new LicenseChecker(createLicense$({ state: 'invalid' }));
|
|
expect(checker.getState()).toEqual({ valid: false, message: 'invalid' });
|
|
|
|
checker = new LicenseChecker(createLicense$({ state: 'unavailable' }));
|
|
expect(checker.getState()).toEqual({ valid: false, message: 'unavailable' });
|
|
});
|
|
|
|
it('updates the state when the license changes', () => {
|
|
const license$ = new BehaviorSubject<ILicense>(createLicense({ state: 'valid' }));
|
|
|
|
const checker = new LicenseChecker(license$);
|
|
expect(checker.getState()).toEqual({ valid: true });
|
|
|
|
license$.next(createLicense({ state: 'expired' }));
|
|
expect(checker.getState()).toEqual({ valid: false, message: 'expired' });
|
|
|
|
license$.next(createLicense({ state: 'valid' }));
|
|
expect(checker.getState()).toEqual({ valid: true });
|
|
});
|
|
|
|
it('removes the subscription when calling `clean`', () => {
|
|
const mockUnsubscribe = jest.fn();
|
|
const mockObs = {
|
|
subscribe: jest.fn().mockReturnValue({ unsubscribe: mockUnsubscribe }),
|
|
};
|
|
|
|
const checker = new LicenseChecker(mockObs as any);
|
|
|
|
expect(mockObs.subscribe).toHaveBeenCalledTimes(1);
|
|
expect(mockUnsubscribe).not.toHaveBeenCalled();
|
|
|
|
checker.clean();
|
|
|
|
expect(mockUnsubscribe).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|