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

Commit

Permalink
This commit should have the source changes discussed in the last commit
Browse files Browse the repository at this point in the history
stupid not staging...

issue #5
  • Loading branch information
tritium21 committed Sep 2, 2016
1 parent 31a3a80 commit fe4aaf3
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ bin/
obj/
docs/_build/
coverage/
typings/
typings/
/example
10 changes: 5 additions & 5 deletions lib/dcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ DCC.prototype.sendFile = function (to, filename, length, callback) {
}
}
var server = net.createServer();
server.on("connection", (con) => {
server.close();
callback(null, con, start);
self.client.removeListener("dcc-resume", resumeCallback);
});
server.listen(details.port, self.localAddress, null, () => {
var address = server.address();
var data = {
Expand All @@ -101,6 +96,11 @@ DCC.prototype.sendFile = function (to, filename, length, callback) {
self.client.ctcp(to, "privmsg", format(send_template, data));
self.client.once("dcc-resume", resumeCallback);
});
server.on("connection", (con) => {
server.close();
callback(null, con, start);
self.client.removeListener("dcc-resume", resumeCallback);
});
});
};
DCC.prototype.acceptSend = function (from, host, port, filename, length, position, callback) {
Expand Down
119 changes: 119 additions & 0 deletions test/dcc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,30 @@ describe("DCC", () => {
done();
});
});
it("should remove listener", (done) => {
DCC.prototype.getPortIP.callbackWith({
host: "192.168.1.100",
long: 3232235876,
port: 2000
});
net.createServer.returnWith(fakeServer);
fakeServer.on.callbackWith(fakeCon);
var dcc = new DCC(fakeClient, {});
dcc.sendFile("to", "filename", 0, (err, con, pos) => { done(); });
assert(fakeClient.removeListener.called);
});
it("should close the server", (done) => {
DCC.prototype.getPortIP.callbackWith({
host: "192.168.1.100",
long: 3232235876,
port: 2000
});
net.createServer.returnWith(fakeServer);
fakeServer.on.callbackWith(fakeCon);
var dcc = new DCC(fakeClient, {});
dcc.sendFile("to", "filename", 0, (err, con, pos) => { done(); });
assert(fakeServer.close.called);
});
it("should send a DCC SEND message", (done) => {
DCC.prototype.getPortIP.callbackWith({
host: "192.168.1.100",
Expand All @@ -336,5 +360,100 @@ describe("DCC", () => {
["to", "privmsg", "DCC SEND filename 3232235876 2000 0"]
);
});
it("should callback with pos == 0", (done) => {
DCC.prototype.getPortIP.callbackWith({
host: "192.168.1.100",
long: 3232235876,
port: 2000
});
net.createServer.returnWith(fakeServer);
fakeServer.on.callbackWith(fakeCon);
fakeServer.address.returnWith({ port: 2000 });
fakeServer.listen.callbackWith();
var dcc = new DCC(fakeClient, {});
dcc.sendFile("to", "filename", 0, (err, con, pos) => {
assert.equal(pos, 0);
done();
});
});
it("should not resume", (done) => {
DCC.prototype.getPortIP.callbackWith({
host: "192.168.1.100",
long: 3232235876,
port: 2000
});
net.createServer.returnWith(fakeServer);
fakeServer.address.returnWith({ port: 2000 });
fakeServer.listen.callbackWith();
fakeClient.once.callbackWith(
"to",
{
filename: "filename2",
port: 2000,
position: 50
}
);
fakeServer.on.callbackWith(fakeCon);
var dcc = new DCC(fakeClient, {});
dcc.sendFile("to", "filename", 0, (err, con, pos) => {
done();
});
assert.deepEqual(
fakeClient.ctcp.lastCall.args,
["to", "privmsg", "DCC SEND filename 3232235876 2000 0"]
);
});
it("should resume", (done) => {
DCC.prototype.getPortIP.callbackWith({
host: "192.168.1.100",
long: 3232235876,
port: 2000
});
net.createServer.returnWith(fakeServer);
fakeServer.address.returnWith({ port: 2000 });
fakeServer.listen.callbackWith();
fakeClient.once.callbackWith(
"to",
{
filename: "filename",
port: 2000,
position: 50
}
);
fakeServer.on.callbackWith(fakeCon);
var dcc = new DCC(fakeClient, {});
dcc.sendFile("to", "filename", 0, (err, con, pos) => {
done();
});
assert.deepEqual(
fakeClient.ctcp.lastCall.args,
["to", "privmsg", "DCC ACCEPT filename 2000 50"]
);
});
it("should callback with pos == 50", (done) => {
DCC.prototype.getPortIP.callbackWith({
host: "192.168.1.100",
long: 3232235876,
port: 2000
});
net.createServer.returnWith(fakeServer);
fakeServer.address.returnWith({ port: 2000 });
fakeServer.listen.callbackWith();
fakeClient.once.callbackWith(
"to",
{
filename: "filename",
port: 2000,
position: 50
}
);
fakeServer.on.callbackWith(fakeCon);
var dcc = new DCC(fakeClient, {});
dcc.sendFile("to", "filename", 0, (err, con, pos) => {
assert.equal(pos, 50);
done();
});
});

});
});

0 comments on commit fe4aaf3

Please sign in to comment.