Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should call sizeCypher and save return value to data set value', async () => {
const node = testUtils.makeNode([label1]);
testUtils.mockFullRunSubscribe({
[initial_cypher]: {
default: [testUtils.makeRecord([node])]
},
[sizeCypher]: {
[node.identity.toInt()]: [testUtils.makeRecord([Neo4j.int(1)])]
}
});
neovis.render();
await testUtils.neovisRenderDonePromise(neovis);
expect(Neo4jMock.mockSessionRun).toHaveBeenCalledTimes(1 + 1); // once for initial cypher and once for the sizeCypher
expect(neovis._data.nodes.get(1)).toHaveProperty('value', 1);
});
});
const captionKey = labelConfig && labelConfig['caption'];
const sizeKey = labelConfig && labelConfig['size'];
const sizeCypher = labelConfig && labelConfig['sizeCypher'];
const communityKey = labelConfig && labelConfig['community'];
node.id = neo4jNode.identity.toInt();
// node size
if (sizeCypher) {
// use a cypher statement to determine the size of the node
// the cypher statement will be passed a parameter {id} with the value
// of the internal node id
let session = this._driver.session();
const result = await session.run(sizeCypher, {id: Neo4j.int(node.id)});
for (let record of result.records) {
record.forEach((v) => {
if (typeof v === 'number') {
node.value = v;
} else if (Neo4j.isInt(v)) {
node.value = v.toNumber();
}
});
}
} else if (typeof sizeKey === 'number') {
node.value = sizeKey;
} else {
let sizeProp = neo4jNode.properties[sizeKey];
if (sizeProp && typeof sizeProp === 'number') {
// property value is a number, OK to use
export function makeRelationship(type, startNode, endNode, properties = {}) {
return new Neo4j.types.Relationship(Neo4j.int(counter++), startNode.identity, endNode.identity, type, properties);
}
export function makeNode(labels, properties = {}) {
return new Neo4j.types.Node(Neo4j.int(counter++), labels, properties);
}
return new types[className](
applyGraphTypes(item.hour),
applyGraphTypes(item.minute),
applyGraphTypes(item.second),
applyGraphTypes(item.nanosecond)
)
case 'Time':
return new types[className](
applyGraphTypes(item.hour),
applyGraphTypes(item.minute),
applyGraphTypes(item.second),
applyGraphTypes(item.nanosecond),
applyGraphTypes(item.timeZoneOffsetSeconds)
)
case 'Integer':
return neo4j.int(tmpItem)
default:
return item
}
} else if (typeof rawItem === 'object') {
let typedObject = {}
Object.keys(rawItem).forEach(key => {
typedObject[key] = applyGraphTypes(rawItem[key], types)
})
typedObject = unEscapeReservedProps(typedObject, reservedTypePropertyName)
return typedObject
} else {
return rawItem
}
}
(serialized, [key, value]) => {
if (Number.isInteger(value)) value = neo4j.int(value);
serialized[key] = value;
return serialized;
},
{}
Object.keys(neo4jTypeParam).forEach(paramFieldName => {
const fieldAst = neo4jTypeFields.find(
field => field.name.value === paramFieldName
);
const unwrappedFieldType = unwrapNamedType({ type: fieldAst.type });
const fieldTypeName = unwrappedFieldType.name;
if (
fieldTypeName === GraphQLInt.name &&
Number.isInteger(neo4jTypeParam[paramFieldName])
) {
const serialized = neo4j.int(neo4jTypeParam[paramFieldName]);
let param = params[paramName];
if (paramIndex >= 0) {
if (paramKey) param = params[paramKey][paramName][paramIndex];
else param = param[paramIndex];
} else if (paramKey) param = params[paramKey][paramName];
param[paramFieldName] = serialized;
}
});
return params;