Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
acceptAndConnectFile
Browse files Browse the repository at this point in the history
issue #5
  • Loading branch information
tritium21 committed Sep 4, 2016
1 parent 50381b6 commit 8d16716
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions test/dcc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,55 @@ describe("DCC.parseDCC()", function () {
});

describe("DCC", () => {
describe(".acceptAndConnectFile", () => {
var fakeCon;
before(() => {
simple.mock(net, "connect");
fakeCon = {
on: simple.stub(),
write: simple.stub()
};
net.connect.loop = false;
fakeCon.on.loop = false;
fakeCon.write.loop = false;
});
afterEach(() => {
net.connect.reset();
fakeCon.on.reset();
fakeCon.write.reset();
});
after(() => {
simple.restore();
});
it("should callback with filename and connection", (done) => {
var expected = [null, "filename", fakeCon];
net.connect.returnWith(fakeCon);
fakeCon.on.callbackWith()
var opt = {
host: "192.168.1.100",
port: 2000,
localAddress: "0.0.0.0"
};
DCC.acceptAndConnectFile(opt, "filename", (err, filename, connection) => {
assert.deepEqual([err, filename, connection], expected);
done();
});
});
it("should send data length", (done) => {
var buf = new Buffer(4);
buf.writeUInt32BE(4, 0);
var expected = [buf];
net.connect.returnWith(fakeCon);
fakeCon.on.callbackWith().callbackWith("data");
var opt = {
host: "192.168.1.100",
port: 2000,
localAddress: "0.0.0.0"
};
DCC.acceptAndConnectFile(opt, "filename", done);
assert.deepEqual(fakeCon.write.lastCall.args, expected);
});
});
describe("(constructor)", () => {
var fakeClient;
before(() => {
Expand Down Expand Up @@ -337,7 +386,6 @@ describe("DCC", () => {
};
fakeCon = {
addListener: simple.stub(),
setTimeout: simple.stub(),
};
net.createServer.loop = false;
DCC.prototype.getPortIP.loop = false;
Expand All @@ -351,7 +399,6 @@ describe("DCC", () => {
fakeServer.address.loop = false;
fakeServer.on.loop = false;
fakeCon.addListener.loop = false;
fakeCon.setTimeout.loop = false;
});
afterEach(() => {
net.createServer.reset();
Expand All @@ -366,7 +413,6 @@ describe("DCC", () => {
fakeServer.address.reset();
fakeServer.on.reset();
fakeCon.addListener.reset();
fakeCon.setTimeout.reset();
});
after(() => {
simple.restore();
Expand Down

0 comments on commit 8d16716

Please sign in to comment.