Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHSCFT-50: Unit testing AI search #33

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

adawari-thomas-bjss
Copy link
Collaborator

@adawari-thomas-bjss adawari-thomas-bjss commented Dec 20, 2024

Description

Jira ticket: DHSCFT-50

Changes

  • Added unit tests to test for the successful creation and population of an index within existing AI search instance.

Validation

image

search-setup/package.json Outdated Show resolved Hide resolved
Comment on lines 6 to 8
const searchEndpoint = process.env["AI_SEARCH_SERVICE_ENDPOINT"] ?? "";
const indexName = process.env["AI_SEARCH_INDEX_NAME"];
const apiKey = process.env["AI_SEARCH_API_KEY"] ?? "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have defaults for the search endpoint or API key? I'm not sure we would expect this to work if they're not provided.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler complains when the API key passed as a header could possibly be undefined. This way the test still fails when an api key is not provided

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you throw an error if any of these values are undefined Typescript should be clever enough to know they'll never be undefined when you use them later. I think that makes more sense than continuing with the tests if we're missing critical information.

search-setup/__tests__/search.test.ts Outdated Show resolved Hide resolved
search-setup/__tests__/search.test.ts Outdated Show resolved Hide resolved
Comment on lines 25 to 48
expect(index.name).toBe(indexName);
expect(index.fields.length).toBe(2);
expect(index.fields.at(0)?.name).toBe("IID");
expect(index.fields.at(0)?.type).toBe("Edm.String");
expect(index.fields.at(0)?.key).toBe(true);
expect(index.fields.at(0)?.retrievable).toBe(true);
expect(index.fields.at(0)?.searchable).toBe(true);
expect(index.fields.at(0)?.sortable).toBe(true);
expect(index.fields.at(0)?.filterable).toBe(true);
expect(index.fields.at(1)?.name).toBe("Descriptive");
expect(index.fields.at(1)?.type).toBe("Edm.ComplexType");
expect(index.fields.at(1)?.fields?.length).toBe(2);
expect(index.fields.at(1)?.fields?.at(0)?.name).toBe("Name");
expect(index.fields.at(1)?.fields?.at(0)?.type).toBe("Edm.String");
expect(index.fields.at(1)?.fields?.at(0)?.retrievable).toBe(true);
expect(index.fields.at(1)?.fields?.at(0)?.searchable).toBe(true);
expect(index.fields.at(1)?.fields?.at(0)?.sortable).toBe(true);
expect(index.fields.at(1)?.fields?.at(0)?.filterable).toBe(true);
expect(index.fields.at(1)?.fields?.at(1)?.name).toBe("Definition");
expect(index.fields.at(1)?.fields?.at(1)?.type).toBe("Edm.String");
expect(index.fields.at(1)?.fields?.at(1)?.retrievable).toBe(true);
expect(index.fields.at(1)?.fields?.at(1)?.searchable).toBe(true);
expect(index.fields.at(1)?.fields?.at(1)?.sortable).toBe(true);
expect(index.fields.at(1)?.fields?.at(1)?.filterable).toBe(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list of assertions is already long, and our index only has three fields. I think we need to look at whether we can compare this against an object, or if that doesn't work at least having a function to check each field is as expected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using helper methods to fix this as the object returned by the fetch call contains plenty fields that are not being used. This way, only the necessary fields are being tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants