Skip to content

Commit

Permalink
Merge d38ea4b into 94edfb3
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Sep 1, 2020
2 parents 94edfb3 + d38ea4b commit ffbad74
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 143 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"debounce": "^1.1.0",
"debug": "^4.0.0",
"json-stringify-safe": "^5.0.1",
"noflo": "^1.0.0",
"noflo": "^1.2.0",
"temp": "^0.9.0"
},
"nyc": {
Expand Down
59 changes: 41 additions & 18 deletions spec/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ describe('Graph protocol', () => {
permissions: {
foo: ['protocol:graph'],
},
baseDir,
});
runtime.graph.on('updated', (msg) => runtimeEvents.push(msg));
client = new direct.Client(runtime);
client.connect();
client2 = new direct.Client(runtime);
return client2.connect();
client2.connect();
});
afterEach(() => {
client.disconnect();
client = null;
client2.disconnect();
client2 = null;
return runtime = null;
runtime = null;
});

describe('sending graph:clear', () => {
Expand All @@ -33,9 +34,9 @@ describe('Graph protocol', () => {
client.once('message', (msg) => {
chai.expect(msg.protocol).to.equal('graph');
chai.expect(msg.command).to.equal('error');
return done();
done();
});
return client.send('graph', 'clear', payload);
client.send('graph', 'clear', payload);
});
it('should respond with graph:clear', (done) => {
const payload = {
Expand All @@ -48,11 +49,11 @@ describe('Graph protocol', () => {
chai.expect(msg.command).to.equal('clear');
chai.expect(msg.payload).to.include.keys('id');
chai.expect(msg.payload.id).to.equal(payload.id);
return done();
done();
});
return client.send('graph', 'clear', payload);
client.send('graph', 'clear', payload);
});
return it('should send to all clients', (done) => {
it('should send to all clients', (done) => {
const payload = {
id: 'mygraph',
main: true,
Expand All @@ -63,44 +64,66 @@ describe('Graph protocol', () => {
chai.expect(msg.command).to.equal('clear');
chai.expect(msg.payload).to.include.keys('id');
chai.expect(msg.payload.id).to.equal(payload.id);
return done();
done();
});
return client.send('graph', 'clear', payload);
client.send('graph', 'clear', payload);
});
});

return describe('sending graph:addnode', () => {
describe('sending graph:addnode', () => {
const graph = 'graphwithnodes';
const payload = {
id: 'node1',
component: 'Component1',
component: 'core/Repeat',
graph,
metadata: {},
};
const authenticatedPayload = JSON.parse(JSON.stringify(payload));
authenticatedPayload.secret = 'foo';
const checkAddNode = function (msg, done) {
if (msg.command !== 'addnode') { return; }
if (msg.command === 'error') {
done(msg.payload);
return;
}
if (msg.command !== 'addnode') {
return;
}
chai.expect(msg.protocol).to.equal('graph');
chai.expect(msg.command).to.equal('addnode');
chai.expect(msg.payload).to.deep.equal(payload);
return done();
done();
};
after(() => runtimeEvents = []);
it('should respond with graph:addnode', (done) => {
client.on('message', (msg) => checkAddNode(msg, done));
client.send('graph', 'clear', { id: graph, main: true, secret: 'foo' });
return client.send('graph', 'addnode', authenticatedPayload);
client.send('graph', 'addnode', authenticatedPayload);
});
it('should have emitted an updated event', () => {
chai.expect(runtimeEvents.length).to.equal(1);
const event = runtimeEvents.shift();
return chai.expect(event.name).to.equal(graph);
chai.expect(event.name).to.equal(graph);
});
return it('should send to all clients', (done) => {
it('should send to all clients', (done) => {
client2.on('message', (msg) => checkAddNode(msg, done));
client.send('graph', 'clear', { id: graph, main: true, secret: 'foo' });
return client.send('graph', 'addnode', authenticatedPayload);
client.send('graph', 'addnode', authenticatedPayload);
});
});

describe('sending graph:addnode without an existing graph', () => {
it('should respond with an error', (done) => {
client.once('message', (msg) => {
chai.expect(msg.protocol).to.equal('graph');
chai.expect(msg.command).to.equal('error');
done();
});
client.send('graph', 'addnode', {
id: 'foo',
component: 'Bar',
graph: 'not-found',
metadata: {},
secret: 'foo',
});
});
});
});
72 changes: 54 additions & 18 deletions spec/Network.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
describe('Network protocol', () => {
let runtime = null;
let client = null;
before(() => runtime = new direct.Runtime({
permissions: {
foo: ['protocol:graph', 'protocol:network'],
},
baseDir,
}));
before(() => {
runtime = new direct.Runtime({
permissions: {
foo: ['protocol:graph', 'protocol:network'],
},
baseDir,
});
});
beforeEach(() => {
client = new direct.Client(runtime);
return client.connect();
client.connect();
});
afterEach(() => {
if (!client) { return; }
client.removeAllListeners('message');
client.disconnect();
return client = null;
client = null;
});

describe('defining a graph', () => it('should succeed', (done) => {
client.on('error', (err) => done(err));
client.on('message', (msg) => {
if (msg.command === 'error') {
return done(msg.payload);
done(msg.payload);
return;
}
if (msg.command !== 'addinitial') { return; }
chai.expect(msg.payload.src.data).to.equal('Hello, world!');
return done();
done();
});
client.send('graph', 'clear', {
id: 'bar',
Expand Down Expand Up @@ -57,7 +60,7 @@ describe('Network protocol', () => {
graph: 'bar',
secret: 'foo',
});
return client.send('graph', 'addinitial', {
client.send('graph', 'addinitial', {
src: {
data: 'Hello, world!',
},
Expand All @@ -69,7 +72,7 @@ describe('Network protocol', () => {
secret: 'foo',
});
}));
return describe('starting the network', () => {
describe('starting the network', () => {
it('should process the nodes and stop when it completes', (done) => {
const expects = [
'started',
Expand All @@ -80,32 +83,65 @@ describe('Network protocol', () => {
client.on('error', (err) => done(err));
client.on('message', (msg) => {
if (msg.command === 'error') {
return done(msg.payload);
done(msg.payload);
return;
}
if (msg.protocol !== 'network') { return; }
chai.expect(msg.protocol).to.equal('network');
chai.expect(msg.command).to.equal(expects.shift());
if (!expects.length) { return done(); }
if (!expects.length) {
done();
}
});
return client.send('network', 'start', {
client.send('network', 'start', {
graph: 'bar',
secret: 'foo',
});
});
return it('should provide a "finished" status', (done) => {
it('should provide a "finished" status', (done) => {
client.on('error', (err) => done(err));
client.on('message', (msg) => {
chai.expect(msg.protocol).to.equal('network');
chai.expect(msg.command).to.equal('status');
chai.expect(msg.payload.graph).to.equal('bar');
chai.expect(msg.payload.running).to.equal(false);
chai.expect(msg.payload.started).to.equal(false);
return done();
done();
});
return client.send('network', 'getstatus', {
client.send('network', 'getstatus', {
graph: 'bar',
secret: 'foo',
});
});
it('should be able to rename a name', (done) => {
client.on('error', (err) => done(err));
client.send('graph', 'renamenode', {
from: 'World',
to: 'NoFlo',
graph: 'bar',
secret: 'foo',
});
client.on('message', (msg) => {
chai.expect(msg.protocol).to.equal('graph');
chai.expect(msg.command).to.equal('renamenode');
done();
});
});
it('should not be able to add a node with a non-existing component', (done) => {
client.on('error', (err) => done(err));
client.send('graph', 'addnode', {
id: 'Nonworking',
component: '404NotFound',
graph: 'bar',
secret: 'foo',
});
client.on('message', (msg) => {
chai.expect(msg.protocol).to.equal('graph');
chai.expect(msg.command).to.equal('error');
chai.expect(msg.payload).to.be.an('error');
chai.expect(msg.payload.message).to.include('Component 404NotFound not available');
done();
});
});
});
});
Loading

0 comments on commit ffbad74

Please sign in to comment.