Skip to content

Commit

Permalink
[Search] Refactor test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dgetu committed May 8, 2024
1 parent 2ebcac9 commit e4cb613
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 292 deletions.
2 changes: 1 addition & 1 deletion sdk/search/search-documents/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "js",
"TagPrefix": "js/search/search-documents",
"Tag": "js/search/search-documents_436aab18ea"
"Tag": "js/search/search-documents_a090bb38a6"
}
2 changes: 0 additions & 2 deletions sdk/search/search-documents/src/serviceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,6 @@ export function delay(timeInMs: number): Promise<void> {
return new Promise((resolve) => setTimeout(() => resolve(), timeInMs));
}

export const serviceVersions = ["2023-11-01", "2024-03-01-Preview"];

export const defaultServiceVersion = "2024-03-01-Preview";

function convertKnowledgeStoreToPublic(
Expand Down
59 changes: 31 additions & 28 deletions sdk/search/search-documents/test/public/node/searchClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@ import {
KnownQueryLanguage,
KnownSpeller,
SearchClient,
SearchIndex,
SearchIndexClient,
SelectFields,
} from "../../../src";
import { SearchFieldArray, SelectArray } from "../../../src/indexModels";
import { delay, serviceVersions } from "../../../src/serviceUtils";
import { defaultServiceVersion, delay } from "../../../src/serviceUtils";
import { COMPRESSION_DISABLED } from "../../compressionDisabled";
import { Hotel } from "../utils/interfaces";
import { createClients } from "../utils/recordedClient";
import { createIndex, createRandomIndexName, populateIndex, WAIT_TIME } from "../utils/setup";

const [stableServiceVersion, previewServiceVersion] = [
serviceVersions.find((v) => !v.toLowerCase().includes("preview"))!,
serviceVersions.find((v) => v.toLowerCase().includes("preview"))!,
];

describe("SearchClient", function (this: Suite) {
this.timeout(99999);

Expand All @@ -37,24 +33,24 @@ describe("SearchClient", function (this: Suite) {
describe("Passing serviceVersion", () => {
it("supports passing serviceVersion", () => {
const client = new SearchClient<Hotel>("", "", credential, {
serviceVersion: stableServiceVersion,
serviceVersion: defaultServiceVersion,
});
assert.equal(stableServiceVersion, client.serviceVersion);
assert.equal(stableServiceVersion, client.apiVersion);
assert.equal(defaultServiceVersion, client.serviceVersion);
assert.equal(defaultServiceVersion, client.apiVersion);
});

it("supports passing the deprecated apiVersion", () => {
const client = new SearchClient<Hotel>("", "", credential, {
apiVersion: stableServiceVersion,
apiVersion: defaultServiceVersion,
});
assert.equal(stableServiceVersion, client.serviceVersion);
assert.equal(stableServiceVersion, client.apiVersion);
assert.equal(defaultServiceVersion, client.serviceVersion);
assert.equal(defaultServiceVersion, client.apiVersion);
});

it("defaults to the current apiVersion", () => {
const client = new SearchClient<Hotel>("", "", credential);
assert.equal(previewServiceVersion, client.serviceVersion);
assert.equal(previewServiceVersion, client.apiVersion);
assert.equal(defaultServiceVersion, client.serviceVersion);
assert.equal(defaultServiceVersion, client.apiVersion);
});
});
});
Expand All @@ -74,18 +70,16 @@ describe("SearchClient", function (this: Suite) {
indexClient,
indexName: TEST_INDEX_NAME,
openAIClient,
} = await createClients<Hotel>(stableServiceVersion, recorder, TEST_INDEX_NAME));
await createIndex(indexClient, TEST_INDEX_NAME, stableServiceVersion);
} = await createClients<Hotel>(defaultServiceVersion, recorder, TEST_INDEX_NAME));
await createIndex(indexClient, TEST_INDEX_NAME, defaultServiceVersion);
await delay(WAIT_TIME);
await populateIndex(searchClient, openAIClient);
});

afterEach(async function () {
await indexClient.deleteIndex(TEST_INDEX_NAME);
await delay(WAIT_TIME);
if (recorder) {
await recorder.stop();
}
await recorder?.stop();
});

it("count returns the correct document count", async function () {
Expand Down Expand Up @@ -418,6 +412,7 @@ describe("SearchClient", function (this: Suite) {
let indexClient: SearchIndexClient;
let openAIClient: OpenAIClient;
let TEST_INDEX_NAME: string;
let indexDefinition: SearchIndex;

beforeEach(async function (this: Context) {
recorder = new Recorder(this.currentTest);
Expand All @@ -427,18 +422,16 @@ describe("SearchClient", function (this: Suite) {
indexClient,
indexName: TEST_INDEX_NAME,
openAIClient,
} = await createClients<Hotel>(previewServiceVersion, recorder, TEST_INDEX_NAME));
await createIndex(indexClient, TEST_INDEX_NAME, previewServiceVersion);
} = await createClients<Hotel>(defaultServiceVersion, recorder, TEST_INDEX_NAME));
indexDefinition = await createIndex(indexClient, TEST_INDEX_NAME, defaultServiceVersion);
await delay(WAIT_TIME);
await populateIndex(searchClient, openAIClient);
});

afterEach(async function () {
await indexClient.deleteIndex(TEST_INDEX_NAME);
await delay(WAIT_TIME);
if (recorder) {
await recorder.stop();
}
await recorder?.stop();
});

it("search with speller", async function () {
Expand All @@ -459,7 +452,11 @@ describe("SearchClient", function (this: Suite) {
includeTotalCount: true,
queryLanguage: KnownQueryLanguage.EnUs,
queryType: "semantic",
semanticSearchOptions: { configurationName: "semantic-configuration-name" },
semanticSearchOptions: {
configurationName:
indexDefinition.semanticSearch?.configurations?.[0].name ??
assert.fail("No semantic configuration in index."),
},
});
assert.equal(searchResults.count, 1);
});
Expand All @@ -469,7 +466,9 @@ describe("SearchClient", function (this: Suite) {
queryLanguage: KnownQueryLanguage.EnUs,
queryType: "semantic",
semanticSearchOptions: {
configurationName: "semantic-configuration-name",
configurationName:
indexDefinition.semanticSearch?.configurations?.[0].name ??
assert.fail("No semantic configuration in index."),
errorMode: "fail",
debugMode: "semantic",
},
Expand Down Expand Up @@ -514,7 +513,9 @@ describe("SearchClient", function (this: Suite) {
queryLanguage: KnownQueryLanguage.EnUs,
queryType: "semantic",
semanticSearchOptions: {
configurationName: "semantic-configuration-name",
configurationName:
indexDefinition.semanticSearch?.configurations?.[0].name ??
assert.fail("No semantic configuration in index."),
answers: { answerType: "extractive", count: 3, threshold: 0.7 },
},
top: 3,
Expand All @@ -533,7 +534,9 @@ describe("SearchClient", function (this: Suite) {
queryLanguage: KnownQueryLanguage.EnUs,
queryType: "semantic",
semanticSearchOptions: {
configurationName: "semantic-configuration-name",
configurationName:
indexDefinition.semanticSearch?.configurations?.[0].name ??
assert.fail("No semantic configuration in index."),
errorMode: "partial",
},
select: ["hotelId"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
VectorSearchAlgorithmConfiguration,
VectorSearchProfile,
} from "../../../src";
import { delay, serviceVersions } from "../../../src/serviceUtils";
import { defaultServiceVersion, delay } from "../../../src/serviceUtils";
import { Hotel } from "../utils/interfaces";
import { createClients } from "../utils/recordedClient";
import {
Expand All @@ -23,11 +23,6 @@ import {
WAIT_TIME,
} from "../utils/setup";

const [stableServiceVersion, previewServiceVersion] = [
serviceVersions.find((v) => !v.toLowerCase().includes("preview"))!,
serviceVersions.find((v) => v.toLowerCase().includes("preview"))!,
];

describe("SearchIndexClient", function (this: Suite) {
this.timeout(99999);

Expand All @@ -40,7 +35,7 @@ describe("SearchIndexClient", function (this: Suite) {
recorder = new Recorder(this.currentTest);
TEST_INDEX_NAME = createRandomIndexName();
({ indexClient, indexName: TEST_INDEX_NAME } = await createClients<Hotel>(
stableServiceVersion,
defaultServiceVersion,
recorder,
TEST_INDEX_NAME,
));
Expand All @@ -54,9 +49,7 @@ describe("SearchIndexClient", function (this: Suite) {
await indexClient.deleteIndex(TEST_INDEX_NAME);
await delay(WAIT_TIME);
await deleteSynonymMaps(indexClient);
if (recorder) {
await recorder.stop();
}
await recorder?.stop();
});

describe("#synonymmaps", function () {
Expand Down Expand Up @@ -245,7 +238,7 @@ describe("SearchIndexClient", function (this: Suite) {
recorder = new Recorder(this.currentTest);
TEST_INDEX_NAME = createRandomIndexName();
({ indexClient, indexName: TEST_INDEX_NAME } = await createClients<Hotel>(
previewServiceVersion,
defaultServiceVersion,
recorder,
TEST_INDEX_NAME,
));
Expand All @@ -259,9 +252,7 @@ describe("SearchIndexClient", function (this: Suite) {
await indexClient.deleteIndex(TEST_INDEX_NAME);
await delay(WAIT_TIME);
await deleteSynonymMaps(indexClient);
if (recorder) {
await recorder.stop();
}
await recorder?.stop();
});

it("creates the index object vector fields", async function () {
Expand Down
Loading

0 comments on commit e4cb613

Please sign in to comment.