1 | 'use strict';
|
2 |
|
3 | const util = require('util');
|
4 | const PubSub = require('../');
|
5 |
|
6 | exports.createMockClient = function (config, sendCallback) {
|
7 | config = config || {};
|
8 | let client = new PubSub(config);
|
9 | client._send = function () {
|
10 | sendCallback && sendCallback.apply(null, arguments);
|
11 | };
|
12 | return client;
|
13 | };
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function MockConfigClient() {
|
20 | return PubSub.apply(this, arguments);
|
21 | }
|
22 | util.inherits(MockConfigClient, PubSub);
|
23 | MockConfigClient.prototype.fetchConfig = () => null;
|
24 | MockConfigClient.prototype.updateConfig = function (config) {
|
25 | this._parseConfig(Object.assign(this.config || {}, config));
|
26 | };
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | exports.createMockConfigClient = function (config) {
|
34 | return new MockConfigClient(config);
|
35 | };
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | function Request(body, headers) {
|
43 | this.headers = headers || {};
|
44 | this.body = body || {};
|
45 | }
|
46 | exports.Request = Request;
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | function Response() {
|
52 | }
|
53 | exports.Response = Response;
|
54 |
|
55 | Response.prototype.writeHead = function (code, headers) {
|
56 | this.code = code;
|
57 | this.headers = headers;
|
58 | };
|
59 | Response.prototype.write = function (str) {
|
60 | this.body = str;
|
61 | };
|
62 | Response.prototype.end = function () {
|
63 | this.ended = true;
|
64 | };
|
65 | Response.prototype.wasUnauthorized = function () {
|
66 | return this.code === 401 && this.ended;
|
67 | };
|