hardlounge/test/util.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

"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");
function MockClient() {
2016-03-08 16:01:56 +00:00
this.user = {nick: "test-user"};
}
util.inherits(MockClient, EventEmitter);
MockClient.prototype.createMessage = function(opts) {
2015-09-30 22:39:57 +00:00
var message = _.extend({
text: "dummy message",
2016-03-08 16:01:56 +00:00
nick: "test-user",
target: "#test-channel",
previews: [],
2015-09-30 22:39:57 +00:00
}, opts);
return message;
2015-09-30 22:39:57 +00:00
};
function mockLogger(callback) {
return function() {
// TODO: Use ...args with The Lounge v3: add `...args` as function argument
// and replaced the next line with `args.join(", ")`
const stdout = Array.prototype.slice.call(arguments).join(" ")
.replace( // Removes ANSI colors. See https://stackoverflow.com/a/29497680
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
""
);
callback(stdout + "\n");
};
}
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({
name: "#test-channel",
})],
2016-03-20 14:39:59 +00:00
});
2015-09-30 22:39:57 +00:00
},
createWebserver: function() {
return express();
},
mockLogger,
2015-09-30 22:39:57 +00:00
};