Removing check for value when populating partition key values (#1928)

* Removing check for value when populating partition key values

* Removed invalid test case

* Added unit test for empty partition key value
This commit is contained in:
vchske 2024-08-13 10:00:34 -07:00 committed by GitHub
parent 62c76cc264
commit 7f55de7aa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 12 deletions

View File

@ -108,6 +108,7 @@ describe("Query Utils", () => {
}, },
Elevation: 3742, Elevation: 3742,
Type: "Stratovolcano", Type: "Stratovolcano",
Category: "",
Status: "Tephrochronology", Status: "Tephrochronology",
"Last Known Eruption": "Last known eruption from A.D. 1-1499, inclusive", "Last Known Eruption": "Last known eruption from A.D. 1-1499, inclusive",
id: "9e3c494e-8367-3f50-1f56-8c6fcb961363", id: "9e3c494e-8367-3f50-1f56-8c6fcb961363",
@ -147,18 +148,20 @@ describe("Query Utils", () => {
expect(expectedPartitionKeyValues).toContain(documentContent["Status"]); expect(expectedPartitionKeyValues).toContain(documentContent["Status"]);
}); });
it("should extract no partition key values", () => { it("should extract three partition key values", () => {
const singlePartitionKeyDefinition: PartitionKeyDefinition = { const multiPartitionKeyDefinition: PartitionKeyDefinition = {
kind: PartitionKeyKind.Hash, kind: PartitionKeyKind.MultiHash,
paths: ["/InvalidPartitionKeyPath"], paths: ["/Country", "/Region", "/Category"],
}; };
const expectedPartitionKeyValues: string[] = ["United States", "US-Washington", ""];
const partitionKeyValues: PartitionKey[] = extractPartitionKeyValues( const partitioinKeyValues: PartitionKey[] = extractPartitionKeyValues(
documentContent, documentContent,
singlePartitionKeyDefinition, multiPartitionKeyDefinition,
); );
expect(partitioinKeyValues.length).toBe(3);
expect(partitionKeyValues.length).toBe(0); expect(expectedPartitionKeyValues).toContain(documentContent["Country"]);
expect(expectedPartitionKeyValues).toContain(documentContent["Region"]);
expect(expectedPartitionKeyValues).toContain(documentContent["Category"]);
}); });
}); });
}); });

View File

@ -96,9 +96,7 @@ 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);
if (documentContent[partitionKeyPathWithoutSlash]) {
partitionKeyValues.push(documentContent[partitionKeyPathWithoutSlash]); partitionKeyValues.push(documentContent[partitionKeyPathWithoutSlash]);
}
}); });
return partitionKeyValues; return partitionKeyValues;
}; };