2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-09-30 22:39:57 +00:00
|
|
|
var EventEmitter = require("events").EventEmitter;
|
|
|
|
var util = require("util");
|
|
|
|
var _ = require("lodash");
|
|
|
|
var express = require("express");
|
2016-03-20 14:39:59 +00:00
|
|
|
var Network = require("../src/models/network");
|
2016-04-19 10:24:57 +00:00
|
|
|
var Chan = require("../src/models/chan");
|
2014-11-17 20:14:28 +00:00
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
function MockClient() {
|
2016-03-08 16:01:56 +00:00
|
|
|
this.user = {nick: "test-user"};
|
2014-11-17 20:14:28 +00:00
|
|
|
}
|
|
|
|
util.inherits(MockClient, EventEmitter);
|
|
|
|
|
|
|
|
MockClient.prototype.createMessage = function(opts) {
|
2015-09-30 22:39:57 +00:00
|
|
|
var message = _.extend({
|
2016-12-09 20:46:53 +00:00
|
|
|
text: "dummy message",
|
2016-03-08 16:01:56 +00:00
|
|
|
nick: "test-user",
|
2017-07-06 06:16:01 +00:00
|
|
|
target: "#test-channel",
|
|
|
|
previews: [],
|
2015-09-30 22:39:57 +00:00
|
|
|
}, opts);
|
2014-11-17 20:14:28 +00:00
|
|
|
|
2016-12-09 20:46:53 +00:00
|
|
|
return message;
|
2015-09-30 22:39:57 +00:00
|
|
|
};
|
2014-11-17 20:14:28 +00:00
|
|
|
|
2017-12-09 07:11:05 +00:00
|
|
|
function mockLogger(callback) {
|
2017-11-22 06:39:32 +00:00
|
|
|
return function(...args) {
|
|
|
|
// Concats and removes ANSI colors. See https://stackoverflow.com/a/29497680
|
|
|
|
const stdout = args.join(" ").replace(
|
|
|
|
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
|
|
|
|
""
|
|
|
|
);
|
2017-12-09 07:11:05 +00:00
|
|
|
|
|
|
|
callback(stdout + "\n");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-11-17 20:14:28 +00:00
|
|
|
module.exports = {
|
2015-09-30 22:39:57 +00:00
|
|
|
createClient: function() {
|
|
|
|
return new MockClient();
|
|
|
|
},
|
|
|
|
createNetwork: function() {
|
2016-03-20 14:39:59 +00:00
|
|
|
return new Network({
|
|
|
|
host: "example.com",
|
2016-04-19 10:24:57 +00:00
|
|
|
channels: [new Chan({
|
2017-11-15 06:35:15 +00:00
|
|
|
name: "#test-channel",
|
|
|
|
})],
|
2016-03-20 14:39:59 +00:00
|
|
|
});
|
2015-09-30 22:39:57 +00:00
|
|
|
},
|
|
|
|
createWebserver: function() {
|
|
|
|
return express();
|
2017-11-15 06:35:15 +00:00
|
|
|
},
|
2017-12-09 07:11:05 +00:00
|
|
|
mockLogger,
|
2015-09-30 22:39:57 +00:00
|
|
|
};
|