Skip to content

Commit 89651dd

Browse files
committed
Converted fakeIpcProvider to 2 spaces
1 parent 9b41fa8 commit 89651dd

File tree

1 file changed

+91
-91
lines changed

1 file changed

+91
-91
lines changed

test/helpers/fakeIpcProvider.js

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,136 +2,136 @@ const assert = require('assert');
22
const _ = require('lodash');
33

44
const FakeIpcProvider = function IpcProvider() {
5-
var _this = this;
6-
this.countId = 1;
7-
this.notificationCount = 1;
8-
this.getResponseStub = function () {
9-
return {
10-
jsonrpc: '2.0',
11-
id: _this.countId,
12-
result: null
13-
};
5+
var _this = this;
6+
this.countId = 1;
7+
this.notificationCount = 1;
8+
this.getResponseStub = function () {
9+
return {
10+
jsonrpc: '2.0',
11+
id: _this.countId,
12+
result: null
1413
};
15-
this.getErrorStub = function () {
16-
return {
17-
jsonrpc: '2.0',
18-
id: _this.countId,
19-
error: {
20-
code: 1234,
21-
message: 'Stub error'
22-
}
23-
};
14+
};
15+
this.getErrorStub = function () {
16+
return {
17+
jsonrpc: '2.0',
18+
id: _this.countId,
19+
error: {
20+
code: 1234,
21+
message: 'Stub error'
22+
}
2423
};
24+
};
2525

26-
this.response = [];
27-
this.error = [];
28-
this.validation = [];
29-
this.notificationCallbacks = [];
26+
this.response = [];
27+
this.error = [];
28+
this.validation = [];
29+
this.notificationCallbacks = [];
3030
};
3131

3232
FakeIpcProvider.prototype.send = function (payload, callback) {
33-
var _this = this;
33+
var _this = this;
3434

35-
// set id
36-
if(payload.id)
37-
this.countId = payload.id;
38-
// else
39-
// this.countId++;
35+
// set id
36+
if (payload.id)
37+
this.countId = payload.id;
38+
// else
39+
// this.countId++;
4040

41-
assert.equal(_.isArray(payload) || _.isObject(payload), true);
42-
assert.equal(_.isFunction(callback), true);
41+
assert.equal(_.isArray(payload) || _.isObject(payload), true);
42+
assert.equal(_.isFunction(callback), true);
4343

44-
var validation = this.validation.shift();
44+
var validation = this.validation.shift();
4545

46-
if (validation) {
47-
// imitate plain json object
48-
validation(JSON.parse(JSON.stringify(payload)), callback);
49-
}
46+
if (validation) {
47+
// imitate plain json object
48+
validation(JSON.parse(JSON.stringify(payload)), callback);
49+
}
5050

51-
var response = this.getResponseOrError('response', payload);
52-
var error = this.getResponseOrError('error', payload);
51+
var response = this.getResponseOrError('response', payload);
52+
var error = this.getResponseOrError('error', payload);
5353

54-
setTimeout(function(){
55-
callback(error, response);
56-
}, 1);
54+
setTimeout(function () {
55+
callback(error, response);
56+
}, 1);
5757
};
5858

5959
FakeIpcProvider.prototype.on = function (type, callback) {
60-
if(type === 'data') {
61-
this.notificationCallbacks.push(callback);
62-
}
60+
if (type === 'data') {
61+
this.notificationCallbacks.push(callback);
62+
}
6363
};
6464

6565
FakeIpcProvider.prototype.getResponseOrError = function (type, payload) {
66-
var _this = this;
67-
var response;
68-
69-
if(type === 'error') {
70-
response = this.error.shift();
71-
} else {
72-
response = this.response.shift() || this.getResponseStub();
73-
}
74-
75-
76-
if(response) {
77-
if(_.isArray(response)) {
78-
response = response.map(function(resp, index) {
79-
resp.id = payload[index] ? payload[index].id : _this.countId++;
80-
return resp;
81-
});
82-
} else
83-
response.id = payload.id;
84-
}
85-
86-
return response;
66+
var _this = this;
67+
var response;
68+
69+
if (type === 'error') {
70+
response = this.error.shift();
71+
} else {
72+
response = this.response.shift() || this.getResponseStub();
73+
}
74+
75+
76+
if (response) {
77+
if (_.isArray(response)) {
78+
response = response.map(function (resp, index) {
79+
resp.id = payload[index] ? payload[index].id : _this.countId++;
80+
return resp;
81+
});
82+
} else
83+
response.id = payload.id;
84+
}
85+
86+
return response;
8787
};
8888

8989
FakeIpcProvider.prototype.injectNotification = function (notification) {
90-
var _this = this;
91-
setTimeout(function(){
92-
_this.notificationCallbacks.forEach(function(cb){
93-
if(notification && cb)
94-
cb(null, notification);
95-
});
96-
}, 100 + this.notificationCount);
97-
98-
this.notificationCount += 10;
90+
var _this = this;
91+
setTimeout(function () {
92+
_this.notificationCallbacks.forEach(function (cb) {
93+
if (notification && cb)
94+
cb(null, notification);
95+
});
96+
}, 100 + this.notificationCount);
97+
98+
this.notificationCount += 10;
9999
};
100100

101101
// FakeHttpProvider.prototype.injectResponse = function (response) {
102102
// this.response = response;
103103
// };
104104

105105
FakeIpcProvider.prototype.injectBatchResults = function (results, error) {
106-
var _this = this;
107-
this.response.push(results.map(function (r) {
108-
if(error) {
109-
var response = _this.getErrorStub();
110-
response.error.message = r;
111-
} else {
112-
var response = _this.getResponseStub();
113-
response.result = r;
114-
}
115-
return response;
116-
}));
106+
var _this = this;
107+
this.response.push(results.map(function (r) {
108+
if (error) {
109+
var response = _this.getErrorStub();
110+
response.error.message = r;
111+
} else {
112+
var response = _this.getResponseStub();
113+
response.result = r;
114+
}
115+
return response;
116+
}));
117117
};
118118

119119
FakeIpcProvider.prototype.injectResult = function (result) {
120-
var response = this.getResponseStub();
121-
response.result = result;
120+
var response = this.getResponseStub();
121+
response.result = result;
122122

123-
this.response.push(response);
123+
this.response.push(response);
124124
};
125125

126126
FakeIpcProvider.prototype.injectError = function (error) {
127-
var errorStub = this.getErrorStub();
128-
errorStub.error = error; // message, code
127+
var errorStub = this.getErrorStub();
128+
errorStub.error = error; // message, code
129129

130-
this.error.push(errorStub);
130+
this.error.push(errorStub);
131131
};
132132

133133
FakeIpcProvider.prototype.injectValidation = function (callback) {
134-
this.validation.push(callback);
134+
this.validation.push(callback);
135135
};
136136

137137
module.exports = FakeIpcProvider;

0 commit comments

Comments
 (0)