{ "name": "verify-database-change", "settings": { "storagePermissions": { "collections": { "watch_cursors": "read-write", "dbchange_test": "read-write" } } }, "nodes": [ {"id": "n1", "name": "Trigger", "type": "click-trigger", "position": {"x": 0, "y": 0}, "config": {}}, {"id": "setup", "name": "Setup", "type": "code", "position": {"x": 0, "y": 100}, "config": {"code": "smartbotic.storage.delete('watch_cursors', context.workflowId + ':first');\nsmartbotic.storage.delete('watch_cursors', context.workflowId + ':second');\nsmartbotic.storage.delete('dbchange_test', 'before-1');\nsmartbotic.storage.delete('dbchange_test', 'after-1');\nsmartbotic.storage.insert('dbchange_test', { name: 'before', at: Date.now() }, 'before-1');\nconst beforeDoc = smartbotic.storage.get('dbchange_test', 'before-1');\nconst raw = Number(beforeDoc.document._updated_at);\nconst stamp = raw > 1e15 ? Math.floor(raw / 1000000) : raw;\nsmartbotic.storage.insert('watch_cursors', { since: stamp, updatedAt: Date.now(), collection: 'dbchange_test' }, context.workflowId + ':second');\nreturn { ready: true };"}}, {"id": "first", "name": "First Run", "type": "database-change", "position": {"x": 0, "y": 200}, "config": {"collection": "dbchange_test", "emitOnFirstRun": false}}, {"id": "add", "name": "Insert One", "type": "code", "position": {"x": 0, "y": 300}, "config": {"code": "smartbotic.utils.sleep(1100);\nsmartbotic.storage.insert('dbchange_test', { name: 'after', at: Date.now() }, 'after-1');\nreturn { inserted: 'after-1' };"}}, {"id": "second", "name": "Second Run", "type": "database-change", "position": {"x": 0, "y": 400}, "config": {"collection": "dbchange_test", "emitOnFirstRun": false}}, {"id": "cleanup", "name": "Cleanup", "type": "code", "position": {"x": 0, "y": 500}, "config": {"code": "smartbotic.storage.delete('dbchange_test', 'before-1');\nsmartbotic.storage.delete('dbchange_test', 'after-1');\nreturn { cleaned: true };"}} ], "connections": [ {"sourceNodeId": "n1", "sourceOutput": "main", "targetNodeId": "setup", "targetInput": "data"}, {"sourceNodeId": "setup", "sourceOutput": "main", "targetNodeId": "first", "targetInput": "data"}, {"sourceNodeId": "first", "sourceOutput": "main", "targetNodeId": "add", "targetInput": "data"}, {"sourceNodeId": "add", "sourceOutput": "main", "targetNodeId": "second", "targetInput": "data"}, {"sourceNodeId": "second", "sourceOutput": "main", "targetNodeId": "cleanup", "targetInput": "data"} ], "expect": { "first": {"status": "completed", "output": {"count": 0, "isFirstRun": true}}, "second": {"status": "completed", "output": {"count": 1, "isFirstRun": false, "documents": [{"name": "after"}]}} } }