mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-03-12 03:05:28 +00:00
Compare commits
3 Commits
master
...
users/aisa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3f7e280ca | ||
|
|
924f03df74 | ||
|
|
aeb3537a68 |
@@ -350,6 +350,25 @@ describe("Query Utils", () => {
|
||||
expect(partitionKeyValues.length).toBe(2);
|
||||
expect(partitionKeyValues).toEqual(["Japan", "hello"]);
|
||||
});
|
||||
|
||||
it("should extract partition key value when path has surrounding whitespace", () => {
|
||||
const doc = {
|
||||
id: "test-id",
|
||||
Country: "United States",
|
||||
Location: {
|
||||
type: "Point",
|
||||
},
|
||||
};
|
||||
|
||||
const partitionKeyDefinition: PartitionKeyDefinition = {
|
||||
kind: PartitionKeyKind.MultiHash,
|
||||
paths: ["/ Country ", "/ Location / type "],
|
||||
};
|
||||
|
||||
const partitionKeyValues: PartitionKey[] = extractPartitionKeyValues(doc, partitionKeyDefinition);
|
||||
expect(partitionKeyValues.length).toBe(2);
|
||||
expect(partitionKeyValues).toEqual(["United States", "Point"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("stripDoubleQuotesFromSegment", () => {
|
||||
|
||||
@@ -157,7 +157,11 @@ export const extractPartitionKeyValues = (
|
||||
const partitionKeyValues: PartitionKey[] = [];
|
||||
|
||||
partitionKeyDefinition.paths.forEach((partitionKeyPath: string) => {
|
||||
const pathSegments: string[] = partitionKeyPath.substring(1).split("/").map(stripDoubleQuotesFromSegment);
|
||||
const pathSegments: string[] = partitionKeyPath
|
||||
.substring(1)
|
||||
.split("/")
|
||||
.map(stripDoubleQuotesFromSegment)
|
||||
.map((s) => s.trim());
|
||||
const value = getValueForPath(documentContent, pathSegments);
|
||||
|
||||
if (value !== undefined) {
|
||||
|
||||
@@ -272,4 +272,27 @@ export const documentTestCases: DocumentTestCase[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Single Partition Key With Whitespace",
|
||||
databaseId: "e2etests-sql-readonly",
|
||||
containerId: "whitespacePartitionKey",
|
||||
documents: [
|
||||
{
|
||||
documentId: "whitespacePartitionKey",
|
||||
partitionKeys: [{ key: "/ partitionKey ", value: "whitespaceValue" }],
|
||||
},
|
||||
{
|
||||
documentId: "whitespacePartitionKey_empty_string",
|
||||
partitionKeys: [{ key: "/ partitionKey ", value: "" }],
|
||||
},
|
||||
{
|
||||
documentId: "whitespacePartitionKey_null",
|
||||
partitionKeys: [{ key: "/ partitionKey ", value: null }],
|
||||
},
|
||||
{
|
||||
documentId: "whitespacePartitionKey_missing",
|
||||
partitionKeys: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user