|
1 | | -import type { Mocked } from "vitest"; |
| 1 | +import type { Mocked, MockedFunction } from "vitest"; |
2 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 3 | import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver"; |
4 | 4 | import { Session } from "../../../src/common/session.js"; |
@@ -119,4 +119,30 @@ describe("Session", () => { |
119 | 119 | expect(connectionString).toContain("--test-device-id--unknown"); |
120 | 120 | }); |
121 | 121 | }); |
| 122 | + |
| 123 | + describe("isSearchIndexSupported", () => { |
| 124 | + let getSearchIndexesMock: MockedFunction<() => unknown>; |
| 125 | + beforeEach(() => { |
| 126 | + getSearchIndexesMock = vi.fn(); |
| 127 | + MockNodeDriverServiceProvider.connect = vi.fn().mockResolvedValue({ |
| 128 | + getSearchIndexes: getSearchIndexesMock, |
| 129 | + } as unknown as NodeDriverServiceProvider); |
| 130 | + }); |
| 131 | + |
| 132 | + it("should return true if listing search indexes succeed", async () => { |
| 133 | + getSearchIndexesMock.mockResolvedValue([]); |
| 134 | + await session.connectToMongoDB({ |
| 135 | + connectionString: "mongodb://localhost:27017", |
| 136 | + }); |
| 137 | + expect(await session.isSearchIndexSupported()).toEqual(true); |
| 138 | + }); |
| 139 | + |
| 140 | + it("should return false if listing search indexes fail with search error", async () => { |
| 141 | + getSearchIndexesMock.mockRejectedValue(new Error("SearchNotEnabled")); |
| 142 | + await session.connectToMongoDB({ |
| 143 | + connectionString: "mongodb://localhost:27017", |
| 144 | + }); |
| 145 | + expect(await session.isSearchIndexSupported()).toEqual(false); |
| 146 | + }); |
| 147 | + }); |
122 | 148 | }); |
0 commit comments