mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +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) {
|
||||
if (message && typeof message === 'object' && message.action) {
|
||||
switch (message.action) {
|
||||
case 'restart':
|
||||
console.log('[cluster] Restarting...');
|
||||
Loader.restart();
|
||||
break;
|
||||
case 'pubsub':
|
||||
workers.forEach(function (w) {
|
||||
w.send(message);
|
||||
});
|
||||
break;
|
||||
case 'socket.io':
|
||||
workers.forEach(function (w) {
|
||||
if (w !== worker) {
|
||||
case 'restart':
|
||||
console.log('[cluster] Restarting...');
|
||||
Loader.restart();
|
||||
break;
|
||||
case 'pubsub':
|
||||
workers.forEach(function (w) {
|
||||
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 + ')');
|
||||
|
||||
switch (schema[prop].type) {
|
||||
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 + ')');
|
||||
break;
|
||||
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 + ')');
|
||||
break;
|
||||
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 + ')');
|
||||
compare(schema[prop], response[prop], context ? [context, prop].join('.') : prop);
|
||||
break;
|
||||
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 + ')');
|
||||
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 + ')');
|
||||
break;
|
||||
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 + ')');
|
||||
break;
|
||||
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 + ')');
|
||||
compare(schema[prop], response[prop], context ? [context, prop].join('.') : prop);
|
||||
break;
|
||||
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 + ')');
|
||||
|
||||
if (schema[prop].items) {
|
||||
if (schema[prop].items) {
|
||||
// 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
|
||||
if (schema[prop].items.type === 'object' || Array.isArray(schema[prop].items.allOf)) {
|
||||
response[prop].forEach((res) => {
|
||||
compare(schema[prop].items, res, context ? [context, prop].join('.') : prop);
|
||||
});
|
||||
} else if (response[prop].length) { // for now
|
||||
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 + ')');
|
||||
});
|
||||
// Compare types
|
||||
if (schema[prop].items.type === 'object' || Array.isArray(schema[prop].items.allOf)) {
|
||||
response[prop].forEach((res) => {
|
||||
compare(schema[prop].items, res, context ? [context, prop].join('.') : prop);
|
||||
});
|
||||
} else if (response[prop].length) { // for now
|
||||
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 + ')');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -176,15 +176,15 @@ describe('Read API', async () => {
|
||||
assert(param.example !== null && param.example !== undefined, path + ' has parameters without examples');
|
||||
|
||||
switch (param.in) {
|
||||
case 'path':
|
||||
testPath = testPath.replace('{' + param.name + '}', param.example);
|
||||
break;
|
||||
case 'header':
|
||||
headers[param.name] = param.example;
|
||||
break;
|
||||
case 'query':
|
||||
qs[param.name] = param.example;
|
||||
break;
|
||||
case 'path':
|
||||
testPath = testPath.replace('{' + param.name + '}', param.example);
|
||||
break;
|
||||
case 'header':
|
||||
headers[param.name] = param.example;
|
||||
break;
|
||||
case 'query':
|
||||
qs[param.name] = param.example;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -293,13 +293,13 @@ describe('Flags', function () {
|
||||
|
||||
history.forEach(function (change) {
|
||||
switch (change.attribute) {
|
||||
case 'state':
|
||||
assert.strictEqual('[[flags:state-wip]]', change.value);
|
||||
break;
|
||||
case 'state':
|
||||
assert.strictEqual('[[flags:state-wip]]', change.value);
|
||||
break;
|
||||
|
||||
case 'assignee':
|
||||
assert.strictEqual(1, change.value);
|
||||
break;
|
||||
case 'assignee':
|
||||
assert.strictEqual(1, change.value);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user