Commit 20412a16 by James Cropcho Committed by GitHub

Merge pull request #124 from todvora/master

NumberLong data type recognition
parents 955fc90e 5ee817fc
......@@ -36,6 +36,7 @@ module.exports = {
"collection": false,
"DBQuery": false,
"BinData": false,
"NumberLong": false,
"tojson": false
},
......
import { Binary } from 'mongodb';
import { Long } from 'mongodb';
import Tester from './utils/Tester.js';
const test = new Tester('test', 'users');
......@@ -10,7 +11,8 @@ const crazyObject = {
'key_binData-generic': new Binary('1234'), // TODO: how to create other bin-data types?
key_array: [],
key_object: {},
key_null: null
key_null: null,
key_long: Long.fromString('4611686018427387904')
};
describe('Data type recognition', () => {
......@@ -20,13 +22,16 @@ describe('Data type recognition', () => {
it('should recognize all supported data types', async () => {
const results = await test.runJsonAnalysis({collection:'users'}, true);
results.validateResultsCount(10);
results.validate('_id', 1, 100.0, {ObjectId: 1});
results.validate('key_string', 1, 100.0, {String: 1});
results.validate('key_boolean', 1, 100.0, {Boolean: 1});
results.validate('key_number', 1, 100.0, {Number: 1});
results.validate('key_date', 1, 100.0, {Date: 1});
results.validate('key_binData-generic', 1, 100.0, {'BinData-generic': 1});
results.validate('key_array', 1, 100.0, {Array: 1});
results.validate('key_object', 1, 100.0, {Object: 1});
results.validate('key_null', 1, 100.0, {null: 1}); // TODO: why has 'null' first letter lowercase, unlike all other types?
results.validate('key_long', 1, 100.0, {NumberLong: 1});
});
});
......@@ -18,6 +18,6 @@ export default class JsonValidator {
}
validateResultsCount(count) {
equal(this.results.length, count, 'Total count of results does not match expected count.');
equal(this.results.length, count, `Total count of results does not match expected count. Known keys are: [${this.results.map(item => item._id.key).join(',')}].`);
}
}
......@@ -154,6 +154,8 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */
return 'null';
} else if (thing instanceof Date) {
return 'Date';
} else if(thing instanceof NumberLong) {
return 'NumberLong';
} else if (thing instanceof ObjectId) {
return 'ObjectId';
} else if (thing instanceof BinData) {
......@@ -183,7 +185,8 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */
var isObject = typeof v === 'object';
var specialObject = v instanceof Date ||
v instanceof ObjectId ||
v instanceof BinData;
v instanceof BinData ||
v instanceof NumberLong;
return !specialObject && (isArray || isObject);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment