-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
const searchEndpoint = process.env["AI_SEARCH_SERVICE_ENDPOINT"] ?? ""; | ||
const indexName = process.env["AI_SEARCH_INDEX_NAME"]; | ||
const apiKey = process.env["AI_SEARCH_API_KEY"] ?? ""; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Quality Gate passedIssues Measures |
Description
Jira ticket: DHSCFT-50
Changes
Validation