From d0ca1b40870ab373225212f2cabb3b169c060257 Mon Sep 17 00:00:00 2001 From: Miki Date: Tue, 3 Oct 2023 06:38:09 -0700 Subject: [PATCH] [Console] Enhance support for JSON with long numerals (#5130) * Improve testing of clients with long numerals support * Work around serializer inheritance in the JS client Signed-off-by: Miki --- .../opensearch/client/cluster_client.test.ts | 268 ++++++++++-------- .../opensearch/client/cluster_client.ts | 31 +- .../opensearch/client/configure_client.ts | 8 +- src/core/server/opensearch/client/mocks.ts | 25 +- .../client/scoped_cluster_client.test.ts | 20 +- 5 files changed, 200 insertions(+), 152 deletions(-) diff --git a/src/core/server/opensearch/client/cluster_client.test.ts b/src/core/server/opensearch/client/cluster_client.test.ts index 81f55b987805..046939072710 100644 --- a/src/core/server/opensearch/client/cluster_client.test.ts +++ b/src/core/server/opensearch/client/cluster_client.test.ts @@ -55,19 +55,32 @@ describe('ClusterClient', () => { let getAuthHeaders: jest.MockedFunction; let internalClient: ReturnType; let scopedClient: ReturnType; + let internalClientWithLongNumeralsSupport: ReturnType; + let scopedClientWithLongNumeralsSupport: ReturnType; beforeEach(() => { logger = loggingSystemMock.createLogger(); internalClient = opensearchClientMock.createInternalClient(); scopedClient = opensearchClientMock.createInternalClient(); + internalClientWithLongNumeralsSupport = opensearchClientMock.createInternalClient(true); + scopedClientWithLongNumeralsSupport = opensearchClientMock.createInternalClient(true); getAuthHeaders = jest.fn().mockImplementation(() => ({ authorization: 'auth', foo: 'bar', })); - configureClientMock.mockImplementation((config, { scoped = false }) => { - return scoped ? scopedClient : internalClient; - }); + configureClientMock.mockImplementation( + (config, { scoped = false, withLongNumeralsSupport = false }) => { + // prettier-ignore + return withLongNumeralsSupport + ? scoped + ? scopedClientWithLongNumeralsSupport + : internalClientWithLongNumeralsSupport + : scoped + ? scopedClient + : internalClient; + } + ); }); afterEach(() => { @@ -79,7 +92,7 @@ describe('ClusterClient', () => { new ClusterClient(config, logger, getAuthHeaders); - expect(configureClientMock).toHaveBeenCalledTimes(2); + expect(configureClientMock).toHaveBeenCalledTimes(4); expect(configureClientMock).toHaveBeenCalledWith(config, { logger }); expect(configureClientMock).toHaveBeenCalledWith(config, { logger, scoped: true }); }); @@ -100,18 +113,22 @@ describe('ClusterClient', () => { const scopedClusterClient = clusterClient.asScoped(request); const expected = { headers: expect.any(Object) }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); expect(scopedClusterClient.asInternalUser).toBe(clusterClient.asInternalUser); expect(scopedClusterClient.asCurrentUser).toBe(scopedClient.child.mock.results[0].value); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); + + expect(scopedClusterClient.asInternalUserWithLongNumeralsSupport).toBe( + clusterClient.asInternalUserWithLongNumeralsSupport + ); + expect(scopedClusterClient.asCurrentUserWithLongNumeralsSupport).toBe( + scopedClientWithLongNumeralsSupport.child.mock.results[0].value + ); }); it('returns a distinct scoped cluster client on each call', () => { @@ -121,10 +138,14 @@ describe('ClusterClient', () => { const scopedClusterClient1 = clusterClient.asScoped(request); const scopedClusterClient2 = clusterClient.asScoped(request); - expect(scopedClient.child).toHaveBeenCalledTimes(2 * 2); + expect(scopedClient.child).toHaveBeenCalledTimes(2); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(2); expect(scopedClusterClient1).not.toBe(scopedClusterClient2); expect(scopedClusterClient1.asInternalUser).toBe(scopedClusterClient2.asInternalUser); + expect(scopedClusterClient1.asInternalUserWithLongNumeralsSupport).toBe( + scopedClusterClient2.asInternalUserWithLongNumeralsSupport + ); }); it('creates a scoped client with filtered request headers', () => { @@ -146,15 +167,12 @@ describe('ClusterClient', () => { const expected = { headers: { ...DEFAULT_HEADERS, foo: 'bar', 'x-opaque-id': expect.any(String) }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('creates a scoped facade with filtered auth headers', () => { @@ -174,15 +192,12 @@ describe('ClusterClient', () => { const expected = { headers: { ...DEFAULT_HEADERS, authorization: 'auth', 'x-opaque-id': expect.any(String) }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('respects auth headers precedence', () => { @@ -206,15 +221,12 @@ describe('ClusterClient', () => { const expected = { headers: { ...DEFAULT_HEADERS, authorization: 'auth', 'x-opaque-id': expect.any(String) }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('includes the `customHeaders` from the config without filtering them', () => { @@ -240,15 +252,12 @@ describe('ClusterClient', () => { 'x-opaque-id': expect.any(String), }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('adds the x-opaque-id header based on the request id', () => { @@ -271,15 +280,12 @@ describe('ClusterClient', () => { 'x-opaque-id': 'my-fake-id', }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('respect the precedence of auth headers over config headers', () => { @@ -307,15 +313,12 @@ describe('ClusterClient', () => { 'x-opaque-id': expect.any(String), }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('respect the precedence of request headers over config headers', () => { @@ -343,15 +346,12 @@ describe('ClusterClient', () => { 'x-opaque-id': expect.any(String), }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('respect the precedence of config headers over default headers', () => { @@ -374,15 +374,12 @@ describe('ClusterClient', () => { 'x-opaque-id': expect.any(String), }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('respect the precedence of request headers over default headers', () => { @@ -405,15 +402,12 @@ describe('ClusterClient', () => { 'x-opaque-id': expect.any(String), }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('respect the precedence of x-opaque-id header over config headers', () => { @@ -441,15 +435,12 @@ describe('ClusterClient', () => { 'x-opaque-id': 'from request', }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('filter headers when called with a `FakeRequest`', () => { @@ -471,15 +462,12 @@ describe('ClusterClient', () => { const expected = { headers: { ...DEFAULT_HEADERS, authorization: 'auth' }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); it('does not add auth headers when called with a `FakeRequest`', () => { @@ -503,39 +491,43 @@ describe('ClusterClient', () => { const expected = { headers: { ...DEFAULT_HEADERS, foo: 'bar' }, }; - expect(scopedClient.child).toHaveBeenCalledTimes(2); - expect(scopedClient.child).toHaveBeenNthCalledWith(1, expect.objectContaining(expected)); - expect(scopedClient.child).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - ...expected, - enableLongNumeralSupport: true, - }) - ); + + expect(scopedClient.child).toHaveBeenCalledTimes(1); + expect(scopedClient.child).toHaveBeenCalledWith(expected); + + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.child).toHaveBeenCalledWith(expected); }); }); describe('#close', () => { - it('closes both underlying clients', async () => { + it('closes all underlying clients', async () => { const clusterClient = new ClusterClient(createConfig(), logger, getAuthHeaders); await clusterClient.close(); expect(internalClient.close).toHaveBeenCalledTimes(1); expect(scopedClient.close).toHaveBeenCalledTimes(1); + + expect(internalClientWithLongNumeralsSupport.close).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.close).toHaveBeenCalledTimes(1); }); - it('waits for both clients to close', (done) => { - expect.assertions(4); + it('waits for all clients to close', (done) => { + expect.assertions(8); const clusterClient = new ClusterClient(createConfig(), logger, getAuthHeaders); let internalClientClosed = false; let scopedClientClosed = false; + let internalClientWithLongNumeralsSupportClosed = false; + let scopedClientWithLongNumeralsSupportClosed = false; let clusterClientClosed = false; let closeInternalClient: () => void; let closeScopedClient: () => void; + let closeInternalClientWithLongNumeralsSupport: () => void; + let closeScopedClientWithLongNumeralsSupport: () => void; internalClient.close.mockReturnValue( new Promise((resolve) => { @@ -553,16 +545,36 @@ describe('ClusterClient', () => { scopedClientClosed = true; }) ); + internalClientWithLongNumeralsSupport.close.mockReturnValue( + new Promise((resolve) => { + closeInternalClientWithLongNumeralsSupport = resolve; + }).then(() => { + expect(clusterClientClosed).toBe(false); + internalClientWithLongNumeralsSupportClosed = true; + }) + ); + scopedClientWithLongNumeralsSupport.close.mockReturnValue( + new Promise((resolve) => { + closeScopedClientWithLongNumeralsSupport = resolve; + }).then(() => { + expect(clusterClientClosed).toBe(false); + scopedClientWithLongNumeralsSupportClosed = true; + }) + ); clusterClient.close().then(() => { clusterClientClosed = true; expect(internalClientClosed).toBe(true); expect(scopedClientClosed).toBe(true); + expect(internalClientWithLongNumeralsSupportClosed).toBe(true); + expect(scopedClientWithLongNumeralsSupportClosed).toBe(true); done(); }); closeInternalClient!(); closeScopedClient!(); + closeInternalClientWithLongNumeralsSupport!(); + closeScopedClientWithLongNumeralsSupport!(); }); it('return a rejected promise is any client rejects', async () => { @@ -583,11 +595,17 @@ describe('ClusterClient', () => { expect(internalClient.close).toHaveBeenCalledTimes(1); expect(scopedClient.close).toHaveBeenCalledTimes(1); + expect(internalClientWithLongNumeralsSupport.close).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.close).toHaveBeenCalledTimes(1); + await clusterClient.close(); await clusterClient.close(); expect(internalClient.close).toHaveBeenCalledTimes(1); expect(scopedClient.close).toHaveBeenCalledTimes(1); + + expect(internalClientWithLongNumeralsSupport.close).toHaveBeenCalledTimes(1); + expect(scopedClientWithLongNumeralsSupport.close).toHaveBeenCalledTimes(1); }); }); }); diff --git a/src/core/server/opensearch/client/cluster_client.ts b/src/core/server/opensearch/client/cluster_client.ts index 8ea87bb910f7..58de097a3c2e 100644 --- a/src/core/server/opensearch/client/cluster_client.ts +++ b/src/core/server/opensearch/client/cluster_client.ts @@ -76,6 +76,8 @@ export interface ICustomClusterClient extends IClusterClient { export class ClusterClient implements ICustomClusterClient { public readonly asInternalUser: Client; private readonly rootScopedClient: Client; + public readonly asInternalUserWithLongNumeralsSupport: Client; + private readonly rootScopedClientWithLongNumeralsSupport: Client; private isClosed = false; @@ -86,6 +88,16 @@ export class ClusterClient implements ICustomClusterClient { ) { this.asInternalUser = configureClient(config, { logger }); this.rootScopedClient = configureClient(config, { logger, scoped: true }); + + this.asInternalUserWithLongNumeralsSupport = configureClient(config, { + logger, + withLongNumeralsSupport: true, + }); + this.rootScopedClientWithLongNumeralsSupport = configureClient(config, { + logger, + scoped: true, + withLongNumeralsSupport: true, + }); } asScoped(request: ScopeableRequest) { @@ -95,20 +107,14 @@ export class ClusterClient implements ICustomClusterClient { headers: scopedHeaders, }); - const asInternalUserWithLongNumeralsSupport = this.asInternalUser.child({ - // @ts-expect-error - Remove ignoring after https://github.com/opensearch-project/opensearch-js/pull/598 is included in a release - enableLongNumeralSupport: true, - }); - - const scopedClientWithLongNumeralsSupport = this.rootScopedClient.child({ + const scopedClientWithLongNumeralsSupport = this.rootScopedClientWithLongNumeralsSupport.child({ headers: scopedHeaders, - // @ts-expect-error - Remove ignoring after https://github.com/opensearch-project/opensearch-js/pull/598 is included in a release - enableLongNumeralSupport: true, }); + return new ScopedClusterClient( this.asInternalUser, scopedClient, - asInternalUserWithLongNumeralsSupport, + this.asInternalUserWithLongNumeralsSupport, scopedClientWithLongNumeralsSupport ); } @@ -118,7 +124,12 @@ export class ClusterClient implements ICustomClusterClient { return; } this.isClosed = true; - await Promise.all([this.asInternalUser.close(noop), this.rootScopedClient.close(noop)]); + await Promise.all([ + this.asInternalUser.close(noop), + this.rootScopedClient.close(noop), + this.asInternalUserWithLongNumeralsSupport.close(noop), + this.rootScopedClientWithLongNumeralsSupport.close(noop), + ]); } private getScopedHeaders(request: ScopeableRequest): Headers { diff --git a/src/core/server/opensearch/client/configure_client.ts b/src/core/server/opensearch/client/configure_client.ts index 3a13120966b7..339f6a6ca8e7 100644 --- a/src/core/server/opensearch/client/configure_client.ts +++ b/src/core/server/opensearch/client/configure_client.ts @@ -38,9 +38,15 @@ import { parseClientOptions, OpenSearchClientConfig } from './client_config'; export const configureClient = ( config: OpenSearchClientConfig, - { logger, scoped = false }: { logger: Logger; scoped?: boolean } + { + logger, + scoped = false, + withLongNumeralsSupport = false, + }: { logger: Logger; scoped?: boolean; withLongNumeralsSupport?: boolean } ): Client => { const clientOptions = parseClientOptions(config, scoped); + // @ts-expect-error - ToDo: Remove ignoring after https://github.com/opensearch-project/opensearch-js/pull/598 is included in a release + if (withLongNumeralsSupport) clientOptions.enableLongNumeralSupport = true; const client = new Client(clientOptions); addLogging(client, logger, config.logQueries); diff --git a/src/core/server/opensearch/client/mocks.ts b/src/core/server/opensearch/client/mocks.ts index 40b731f0f3bf..5cf76ab0ae6d 100644 --- a/src/core/server/opensearch/client/mocks.ts +++ b/src/core/server/opensearch/client/mocks.ts @@ -33,10 +33,12 @@ import { TransportRequestPromise } from '@opensearch-project/opensearch/lib/Tran import { OpenSearchClient } from './types'; import { ICustomClusterClient } from './cluster_client'; -const createInternalClientMock = (): DeeplyMockedKeys => { +const createInternalClientMock = (withLongNumeralsSupport = false): DeeplyMockedKeys => { // we mimic 'reflection' on a concrete instance of the client to generate the mocked functions. const client = new Client({ node: 'http://localhost', + // @ts-expect-error - ToDo: Remove ignoring after https://github.com/opensearch-project/opensearch-js/pull/598 is included in a release + enableLongNumeralSupport: withLongNumeralsSupport, }) as any; const omittedProps = [ @@ -80,7 +82,9 @@ const createInternalClientMock = (): DeeplyMockedKeys => { mockify(client, omittedProps); client.close = jest.fn().mockReturnValue(Promise.resolve()); - client.child = jest.fn().mockImplementation(() => createInternalClientMock()); + client.child = jest + .fn() + .mockImplementation(() => createInternalClientMock(withLongNumeralsSupport)); const mockGetter = (obj: Record, propertyName: string) => { Object.defineProperty(obj, propertyName, { @@ -106,8 +110,8 @@ const createInternalClientMock = (): DeeplyMockedKeys => { export type OpenSearchClientMock = DeeplyMockedKeys; -const createClientMock = (): OpenSearchClientMock => - (createInternalClientMock() as unknown) as OpenSearchClientMock; +const createClientMock = (withLongNumeralsSupport = false): OpenSearchClientMock => + (createInternalClientMock(withLongNumeralsSupport) as unknown) as OpenSearchClientMock; export interface ScopedClusterClientMock { asInternalUser: OpenSearchClientMock; @@ -120,8 +124,8 @@ const createScopedClusterClientMock = () => { const mock: ScopedClusterClientMock = { asInternalUser: createClientMock(), asCurrentUser: createClientMock(), - asInternalUserWithLongNumeralsSupport: createClientMock(), - asCurrentUserWithLongNumeralsSupport: createClientMock(), + asInternalUserWithLongNumeralsSupport: createClientMock(true), + asCurrentUserWithLongNumeralsSupport: createClientMock(true), }; return mock; @@ -129,17 +133,15 @@ const createScopedClusterClientMock = () => { export interface ClusterClientMock { asInternalUser: OpenSearchClientMock; - asScoped: jest.MockedFunction<() => ScopedClusterClientMock>; asInternalUserWithLongNumeralsSupport: OpenSearchClientMock; - asCurrentUserWithLongNumeralsSupport: jest.MockedFunction<() => ScopedClusterClientMock>; + asScoped: jest.MockedFunction<() => ScopedClusterClientMock>; } const createClusterClientMock = () => { const mock: ClusterClientMock = { asInternalUser: createClientMock(), + asInternalUserWithLongNumeralsSupport: createClientMock(true), asScoped: jest.fn(), - asInternalUserWithLongNumeralsSupport: createClientMock(), - asCurrentUserWithLongNumeralsSupport: jest.fn(), }; mock.asScoped.mockReturnValue(createScopedClusterClientMock()); @@ -152,9 +154,8 @@ export type CustomClusterClientMock = jest.Mocked & Cluste const createCustomClusterClientMock = () => { const mock: CustomClusterClientMock = { asInternalUser: createClientMock(), + asInternalUserWithLongNumeralsSupport: createClientMock(true), asScoped: jest.fn(), - asInternalUserWithLongNumeralsSupport: createClientMock(), - asCurrentUserWithLongNumeralsSupport: jest.fn(), close: jest.fn(), }; diff --git a/src/core/server/opensearch/client/scoped_cluster_client.test.ts b/src/core/server/opensearch/client/scoped_cluster_client.test.ts index 5e3d222c3be2..4d22ca762dc2 100644 --- a/src/core/server/opensearch/client/scoped_cluster_client.test.ts +++ b/src/core/server/opensearch/client/scoped_cluster_client.test.ts @@ -36,27 +36,39 @@ describe('ScopedClusterClient', () => { const internalClient = opensearchClientMock.createOpenSearchClient(); const scopedClient = opensearchClientMock.createOpenSearchClient(); + const internalClientWithLongNumeralsSupport = opensearchClientMock.createOpenSearchClient(true); + const scopedClientWithLongNumeralsSupport = opensearchClientMock.createOpenSearchClient(true); + const scopedClusterClient = new ScopedClusterClient( internalClient, scopedClient, - internalClient, - scopedClient + internalClientWithLongNumeralsSupport, + scopedClientWithLongNumeralsSupport ); expect(scopedClusterClient.asInternalUser).toBe(internalClient); + expect(scopedClusterClient.asInternalUserWithLongNumeralsSupport).toBe( + internalClientWithLongNumeralsSupport + ); }); it('uses the scoped client passed in the constructor', () => { const internalClient = opensearchClientMock.createOpenSearchClient(); const scopedClient = opensearchClientMock.createOpenSearchClient(); + const internalClientWithLongNumeralsSupport = opensearchClientMock.createOpenSearchClient(true); + const scopedClientWithLongNumeralsSupport = opensearchClientMock.createOpenSearchClient(true); + const scopedClusterClient = new ScopedClusterClient( internalClient, scopedClient, - internalClient, - scopedClient + internalClientWithLongNumeralsSupport, + scopedClientWithLongNumeralsSupport ); expect(scopedClusterClient.asCurrentUser).toBe(scopedClient); + expect(scopedClusterClient.asCurrentUserWithLongNumeralsSupport).toBe( + scopedClientWithLongNumeralsSupport + ); }); });