import sinon from 'sinon'; import type { IConnectionFacade } from '../connection-facade.js'; /** * Named sinon stubs for the tooling API sub-object. * * Each stub corresponds to a method on IToolingApi and can be configured * with the full sinon stub API (.resolves, .rejects, .onFirstCall, etc.). */ export type StubTooling = { /** Stub for tooling.query */ queryStub: sinon.SinonStub; /** Stub for tooling.queryMore */ queryMoreStub: sinon.SinonStub; /** Stub for tooling.executeAnonymous */ executeAnonymousStub: sinon.SinonStub; /** Stub for tooling.create */ createStub: sinon.SinonStub; /** Stub for tooling.destroy */ destroyStub: sinon.SinonStub; }; /** * Named sinon stubs for a stub-backed IConnectionFacade. * * Use the individual stubs to configure call behaviour directly with sinon's * `.resolves()`, `.rejects()`, `.onFirstCall()`, etc. — no `as unknown as` * cast is required because the `connection` property satisfies all of * IConnectionFacade. * * @example * ```typescript * const stubConn = createStubConnection(); * stubConn.queryStub.resolves({ done: true, totalSize: 1, records: [{ Id: '001' }] }); * const adapter = new SoqlQueryAdapter(stubConn.connection); * ``` */ export type StubConnection = { /** The fully-typed IConnectionFacade backed by sinon stubs */ connection: IConnectionFacade; /** Stub for connection.query */ queryStub: sinon.SinonStub; /** Stub for connection.queryMore */ queryMoreStub: sinon.SinonStub; /** Stub for connection.request */ requestStub: sinon.SinonStub; /** Stub for connection.identity */ identityStub: sinon.SinonStub; /** * Stub for connection.sobject. * * By default this stub returns an object whose `describe` and `find` * properties are themselves sinon stubs. Access the inner stubs via * `stubConn.sobjectDescribeStub` and `stubConn.sobjectFindStub`. */ sobjectStub: sinon.SinonStub; /** Stub for the describe method returned by sobject() */ sobjectDescribeStub: sinon.SinonStub; /** Stub for the find method returned by sobject() */ sobjectFindStub: sinon.SinonStub; /** Named stubs for the tooling API sub-object */ tooling: StubTooling; }; /** * Creates a fully-typed IConnectionFacade backed by sinon stubs. * * All properties required by IConnectionFacade are provided, so TypeScript * accepts the return value as a valid IConnectionFacade without any type cast. * Each method is a sinon stub that can be configured with the full sinon API. * * Prefer this factory over hand-rolling partial objects with * `as unknown as IConnectionFacade` in adapter unit tests. * * @returns StubConnection containing the connection and all underlying stubs * * @example * ```typescript * import { createStubConnection } from '../../../src/adapters/testing/index.js'; * * let stubConn: StubConnection; * * beforeEach(() => { * stubConn = createStubConnection(); * adapter = new SoqlQueryAdapter(stubConn.connection); * }); * * it('returns records on success', async () => { * stubConn.queryStub.resolves({ done: true, totalSize: 1, records: [{ Id: '001' }] }); * const result = await adapter.query('SELECT Id FROM Account'); * expect(result.success).to.equal(true); * expect(result.data.records).to.have.lengthOf(1); * }); * ``` */ export declare function createStubConnection(): StubConnection;