added explicit any test

This commit is contained in:
Asier Isayas 2023-10-17 12:53:52 -04:00
parent 282004b09b
commit 6e267b2bba
3 changed files with 11 additions and 7 deletions

View File

@ -39,6 +39,7 @@ module.exports = {
"@typescript-eslint/switch-exhaustiveness-check": "error", "@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/no-unused-vars": "error", "@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-extraneous-class": "error", "@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-explicit-any": "error",
"prefer-arrow/prefer-arrow-functions": ["error", { allowStandaloneDeclarations: true }], "prefer-arrow/prefer-arrow-functions": ["error", { allowStandaloneDeclarations: true }],
eqeqeq: "error", eqeqeq: "error",
"react/display-name": "off", "react/display-name": "off",

View File

@ -117,6 +117,7 @@ describe("Query Utils", () => {
_attachments: "attachments/", _attachments: "attachments/",
_ts: 1697136708, _ts: 1697136708,
}; };
it("should extract single partition key value", () => { it("should extract single partition key value", () => {
const singlePartitionKeyDefinition: PartitionKeyDefinition = { const singlePartitionKeyDefinition: PartitionKeyDefinition = {
kind: PartitionKeyKind.Hash, kind: PartitionKeyKind.Hash,
@ -132,19 +133,18 @@ describe("Query Utils", () => {
}); });
it("should extract two partition key values", () => { it("should extract two partition key values", () => {
const singlePartitionKeyDefinition: PartitionKeyDefinition = { const multiPartitionKeyDefinition: PartitionKeyDefinition = {
kind: PartitionKeyKind.MultiHash, kind: PartitionKeyKind.MultiHash,
paths: ["/Type", "/Status"], paths: ["/Type", "/Status"],
}; };
// const validPartitionKeyValues: Set<string> = new Set(["Stratovolcano", "Tephrochronology"]); const expectedPartitionKeyValues: string[] = ["Stratovolcano", "Tephrochronology"];
const validPartitionKeyValues: string[] = ["Stratovolcano", "Tephrochronology"];
const partitionKeyValues: PartitionKey[] = extractPartitionKeyValues( const partitionKeyValues: PartitionKey[] = extractPartitionKeyValues(
documentContent, documentContent,
singlePartitionKeyDefinition, multiPartitionKeyDefinition,
); );
expect(partitionKeyValues.length).toBe(2); expect(partitionKeyValues.length).toBe(2);
expect(validPartitionKeyValues).toContain(documentContent["Type"]); expect(expectedPartitionKeyValues).toContain(documentContent["Type"]);
expect(validPartitionKeyValues).toContain(documentContent["Status"]); expect(expectedPartitionKeyValues).toContain(documentContent["Status"]);
}); });
it("should extract no partition key values", () => { it("should extract no partition key values", () => {

View File

@ -84,6 +84,7 @@ export const queryPagesUntilContentPresent = async (
return await doRequest(firstItemIndex); return await doRequest(firstItemIndex);
}; };
/* eslint-disable @typescript-eslint/no-explicit-any */
export const extractPartitionKeyValues = ( export const extractPartitionKeyValues = (
documentContent: any, documentContent: any,
partitionKeyDefinition: PartitionKeyDefinition, partitionKeyDefinition: PartitionKeyDefinition,
@ -95,7 +96,9 @@ export const extractPartitionKeyValues = (
const partitionKeyValues: PartitionKey[] = []; const partitionKeyValues: PartitionKey[] = [];
partitionKeyDefinition.paths.forEach((partitionKeyPath: string) => { partitionKeyDefinition.paths.forEach((partitionKeyPath: string) => {
const partitionKeyPathWithoutSlash: string = partitionKeyPath.substring(1); const partitionKeyPathWithoutSlash: string = partitionKeyPath.substring(1);
partitionKeyValues.push(documentContent[partitionKeyPathWithoutSlash]); if (documentContent[partitionKeyPathWithoutSlash]) {
partitionKeyValues.push(documentContent[partitionKeyPathWithoutSlash]);
}
}); });
return partitionKeyValues; return partitionKeyValues;
}; };