Fix handling numeric partition keys (#113)
* Fix pk extraction from documentId in g.V() case * Add unit test, cleanup pk related unit tests
This commit is contained in:
parent
c0ce637eec
commit
cb5fe5316e
|
@ -87,13 +87,26 @@ describe("getPkIdFromDocumentId", () => {
|
||||||
expect(GraphExplorer.getPkIdFromDocumentId(doc, "mypk")).toEqual("['pkvalue', 'id']");
|
expect(GraphExplorer.getPkIdFromDocumentId(doc, "mypk")).toEqual("['pkvalue', 'id']");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should create pkid pair from partitioned graph (pk as number)", () => {
|
||||||
|
const doc = createFakeDoc({ id: "id", mypk: 234 });
|
||||||
|
expect(GraphExplorer.getPkIdFromDocumentId(doc, "mypk")).toEqual("[234, 'id']");
|
||||||
|
});
|
||||||
|
|
||||||
it("should create pkid pair from partitioned graph (pk as valid array value)", () => {
|
it("should create pkid pair from partitioned graph (pk as valid array value)", () => {
|
||||||
const doc = createFakeDoc({ id: "id", mypk: [{ id: "someid", _value: "pkvalue" }] });
|
const doc = createFakeDoc({ id: "id", mypk: [{ id: "someid", _value: "pkvalue" }] });
|
||||||
expect(GraphExplorer.getPkIdFromDocumentId(doc, "mypk")).toEqual("['pkvalue', 'id']");
|
expect(GraphExplorer.getPkIdFromDocumentId(doc, "mypk")).toEqual("['pkvalue', 'id']");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should error if id is not a string", () => {
|
it("should error if id is not a string or number", () => {
|
||||||
const doc = createFakeDoc({ id: { foo: 1 } });
|
let doc = createFakeDoc({ id: { foo: 1 } });
|
||||||
|
try {
|
||||||
|
GraphExplorer.getPkIdFromDocumentId(doc, undefined);
|
||||||
|
expect(true).toBe(false);
|
||||||
|
} catch (e) {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
doc = createFakeDoc({ id: true });
|
||||||
try {
|
try {
|
||||||
GraphExplorer.getPkIdFromDocumentId(doc, undefined);
|
GraphExplorer.getPkIdFromDocumentId(doc, undefined);
|
||||||
expect(true).toBe(false);
|
expect(true).toBe(false);
|
||||||
|
@ -102,16 +115,8 @@ describe("getPkIdFromDocumentId", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should error if pk not string nor non-empty array", () => {
|
it("should error if pk is empty array", () => {
|
||||||
let doc = createFakeDoc({ mypk: { foo: 1 } });
|
let doc = createFakeDoc({ mypk: [] });
|
||||||
|
|
||||||
try {
|
|
||||||
GraphExplorer.getPkIdFromDocumentId(doc, "mypk");
|
|
||||||
} catch (e) {
|
|
||||||
expect(true).toBe(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
doc = createFakeDoc({ mypk: [] });
|
|
||||||
try {
|
try {
|
||||||
GraphExplorer.getPkIdFromDocumentId(doc, "mypk");
|
GraphExplorer.getPkIdFromDocumentId(doc, "mypk");
|
||||||
expect(true).toBe(false);
|
expect(true).toBe(false);
|
||||||
|
|
|
@ -1371,7 +1371,7 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
|
||||||
|
|
||||||
if (collectionPartitionKeyProperty && d.hasOwnProperty(collectionPartitionKeyProperty)) {
|
if (collectionPartitionKeyProperty && d.hasOwnProperty(collectionPartitionKeyProperty)) {
|
||||||
let pk = (d as any)[collectionPartitionKeyProperty];
|
let pk = (d as any)[collectionPartitionKeyProperty];
|
||||||
if (typeof pk !== "string") {
|
if (typeof pk !== "string" && typeof pk !== "number") {
|
||||||
if (Array.isArray(pk) && pk.length > 0) {
|
if (Array.isArray(pk) && pk.length > 0) {
|
||||||
// pk is [{ id: 'id', _value: 'value' }]
|
// pk is [{ id: 'id', _value: 'value' }]
|
||||||
pk = pk[0]["_value"];
|
pk = pk[0]["_value"];
|
||||||
|
|
Loading…
Reference in New Issue