| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /**
- * @node utils-test
- * @name Utils Test
- * @description Test node for smartbotic.utils API
- * @category development
- * @version 1.0.0
- * @trigger false
- */
- const configSchema = {};
- const inputSchema = {};
- const outputSchema = {};
- async function execute(config, input, context) {
- const results = {};
- // Test uuid()
- results.uuid = smartbotic.utils.uuid();
- smartbotic.log.info("Generated UUID: " + results.uuid);
- // Test interpolate()
- const template = "Hello {{name}}, your order #{{order.id}} for {{order.items.0}} is ready!";
- const data = {
- name: "John",
- order: {
- id: 12345,
- items: ["Widget", "Gadget"]
- }
- };
- results.interpolated = smartbotic.utils.interpolate(template, data);
- smartbotic.log.info("Interpolated: " + results.interpolated);
- // Test deepClone()
- const original = { a: 1, b: { c: 2 } };
- const cloned = smartbotic.utils.deepClone(original);
- cloned.b.c = 999; // Modify clone
- results.deepClone = {
- original: original,
- cloned: cloned,
- independentCheck: original.b.c === 2 // Should be true if deep cloned properly
- };
- smartbotic.log.info("Deep clone check: original.b.c = " + original.b.c + ", cloned.b.c = " + cloned.b.c);
- // Test isEmpty()
- results.isEmpty = {
- emptyString: smartbotic.utils.isEmpty(""),
- nonEmptyString: smartbotic.utils.isEmpty("hello"),
- emptyArray: smartbotic.utils.isEmpty([]),
- nonEmptyArray: smartbotic.utils.isEmpty([1, 2]),
- emptyObject: smartbotic.utils.isEmpty({}),
- nonEmptyObject: smartbotic.utils.isEmpty({ a: 1 }),
- nullValue: smartbotic.utils.isEmpty(null),
- undefinedValue: smartbotic.utils.isEmpty(undefined)
- };
- smartbotic.log.info("isEmpty tests: " + JSON.stringify(results.isEmpty));
- // Test pick()
- const obj = { a: 1, b: 2, c: 3, d: 4 };
- results.pick = smartbotic.utils.pick(obj, ["a", "c"]);
- smartbotic.log.info("pick result: " + JSON.stringify(results.pick));
- // Test omit()
- results.omit = smartbotic.utils.omit(obj, ["b", "d"]);
- smartbotic.log.info("omit result: " + JSON.stringify(results.omit));
- return results;
- }
- module.exports = { configSchema, inputSchema, outputSchema, execute };
|