mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
fix(style): more switch..case
This commit is contained in:
30
loader.js
30
loader.js
@@ -87,22 +87,22 @@ Loader.addWorkerEvents = function (worker) {
|
|||||||
worker.on('message', function (message) {
|
worker.on('message', function (message) {
|
||||||
if (message && typeof message === 'object' && message.action) {
|
if (message && typeof message === 'object' && message.action) {
|
||||||
switch (message.action) {
|
switch (message.action) {
|
||||||
case 'restart':
|
case 'restart':
|
||||||
console.log('[cluster] Restarting...');
|
console.log('[cluster] Restarting...');
|
||||||
Loader.restart();
|
Loader.restart();
|
||||||
break;
|
break;
|
||||||
case 'pubsub':
|
case 'pubsub':
|
||||||
workers.forEach(function (w) {
|
workers.forEach(function (w) {
|
||||||
w.send(message);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case 'socket.io':
|
|
||||||
workers.forEach(function (w) {
|
|
||||||
if (w !== worker) {
|
|
||||||
w.send(message);
|
w.send(message);
|
||||||
}
|
});
|
||||||
});
|
break;
|
||||||
break;
|
case 'socket.io':
|
||||||
|
workers.forEach(function (w) {
|
||||||
|
if (w !== worker) {
|
||||||
|
w.send(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
68
test/api.js
68
test/api.js
@@ -120,35 +120,35 @@ describe('Read API', async () => {
|
|||||||
assert(response[prop] !== null, '"' + prop + '" was null, but schema does not specify it to be a nullable property (path: ' + path + ', context: ' + context + ')');
|
assert(response[prop] !== null, '"' + prop + '" was null, but schema does not specify it to be a nullable property (path: ' + path + ', context: ' + context + ')');
|
||||||
|
|
||||||
switch (schema[prop].type) {
|
switch (schema[prop].type) {
|
||||||
case 'string':
|
case 'string':
|
||||||
assert.strictEqual(typeof response[prop], 'string', '"' + prop + '" was expected to be a string, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
|
assert.strictEqual(typeof response[prop], 'string', '"' + prop + '" was expected to be a string, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
|
||||||
break;
|
break;
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
assert.strictEqual(typeof response[prop], 'boolean', '"' + prop + '" was expected to be a boolean, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
|
assert.strictEqual(typeof response[prop], 'boolean', '"' + prop + '" was expected to be a boolean, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
|
||||||
break;
|
break;
|
||||||
case 'object':
|
case 'object':
|
||||||
assert.strictEqual(typeof response[prop], 'object', '"' + prop + '" was expected to be an object, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
|
assert.strictEqual(typeof response[prop], 'object', '"' + prop + '" was expected to be an object, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
|
||||||
compare(schema[prop], response[prop], context ? [context, prop].join('.') : prop);
|
compare(schema[prop], response[prop], context ? [context, prop].join('.') : prop);
|
||||||
break;
|
break;
|
||||||
case 'array':
|
case 'array':
|
||||||
assert.strictEqual(Array.isArray(response[prop]), true, '"' + prop + '" was expected to be an array, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
|
assert.strictEqual(Array.isArray(response[prop]), true, '"' + prop + '" was expected to be an array, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
|
||||||
|
|
||||||
if (schema[prop].items) {
|
if (schema[prop].items) {
|
||||||
// Ensure the array items have a schema defined
|
// Ensure the array items have a schema defined
|
||||||
assert(schema[prop].items.type || schema[prop].items.allOf, '"' + prop + '" is defined to be an array, but its items have no schema defined (path: ' + path + ', context: ' + context + ')');
|
assert(schema[prop].items.type || schema[prop].items.allOf, '"' + prop + '" is defined to be an array, but its items have no schema defined (path: ' + path + ', context: ' + context + ')');
|
||||||
|
|
||||||
// Compare types
|
// Compare types
|
||||||
if (schema[prop].items.type === 'object' || Array.isArray(schema[prop].items.allOf)) {
|
if (schema[prop].items.type === 'object' || Array.isArray(schema[prop].items.allOf)) {
|
||||||
response[prop].forEach((res) => {
|
response[prop].forEach((res) => {
|
||||||
compare(schema[prop].items, res, context ? [context, prop].join('.') : prop);
|
compare(schema[prop].items, res, context ? [context, prop].join('.') : prop);
|
||||||
});
|
});
|
||||||
} else if (response[prop].length) { // for now
|
} else if (response[prop].length) { // for now
|
||||||
response[prop].forEach((item) => {
|
response[prop].forEach((item) => {
|
||||||
assert.strictEqual(typeof item, schema[prop].items.type, '"' + prop + '" should have ' + schema[prop].items.type + ' items, but found ' + typeof items + ' instead (path: ' + path + ', context: ' + context + ')');
|
assert.strictEqual(typeof item, schema[prop].items.type, '"' + prop + '" should have ' + schema[prop].items.type + ' items, but found ' + typeof items + ' instead (path: ' + path + ', context: ' + context + ')');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -176,15 +176,15 @@ describe('Read API', async () => {
|
|||||||
assert(param.example !== null && param.example !== undefined, path + ' has parameters without examples');
|
assert(param.example !== null && param.example !== undefined, path + ' has parameters without examples');
|
||||||
|
|
||||||
switch (param.in) {
|
switch (param.in) {
|
||||||
case 'path':
|
case 'path':
|
||||||
testPath = testPath.replace('{' + param.name + '}', param.example);
|
testPath = testPath.replace('{' + param.name + '}', param.example);
|
||||||
break;
|
break;
|
||||||
case 'header':
|
case 'header':
|
||||||
headers[param.name] = param.example;
|
headers[param.name] = param.example;
|
||||||
break;
|
break;
|
||||||
case 'query':
|
case 'query':
|
||||||
qs[param.name] = param.example;
|
qs[param.name] = param.example;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,13 +293,13 @@ describe('Flags', function () {
|
|||||||
|
|
||||||
history.forEach(function (change) {
|
history.forEach(function (change) {
|
||||||
switch (change.attribute) {
|
switch (change.attribute) {
|
||||||
case 'state':
|
case 'state':
|
||||||
assert.strictEqual('[[flags:state-wip]]', change.value);
|
assert.strictEqual('[[flags:state-wip]]', change.value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'assignee':
|
case 'assignee':
|
||||||
assert.strictEqual(1, change.value);
|
assert.strictEqual(1, change.value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user