test: add test for undefined fields in getObjectsFields

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 75f7972b88
commit 92de49be00

@ -120,7 +120,7 @@ module.exports = function (module) {
cache.set(key, cachedData[key]);
});
if (!fields.length) {
if (!Array.isArray(fields) || !fields.length) {
return keys.map(key => (cachedData[key] ? { ...cachedData[key] } : null));
}
return keys.map((key) => {

@ -142,7 +142,9 @@ SELECT h."data"->>$2::TEXT f
if (!key) {
return null;
}
if (!Array.isArray(fields) || !fields.length) {
return await module.getObject(key);
}
const res = await module.pool.query({
name: 'getObjectFields',
text: `
@ -174,7 +176,8 @@ SELECT (SELECT jsonb_object_agg(f, d."value")
if (!Array.isArray(keys) || !keys.length) {
return [];
}
if (!fields.length) {
if (!Array.isArray(fields) || !fields.length) {
return await module.getObjects(keys);
}
const res = await module.pool.query({

@ -324,6 +324,15 @@ describe('Hash methods', () => {
assert.strictEqual(Number(objects[1].age), 3);
assert.strictEqual(!!objects[2], false);
});
it('should return objects if fields is not an array', async () => {
const objects = await db.getObjectsFields(['testObject8', 'testObject9', 'doesnotexist'], undefined);
assert.strictEqual(objects[0].name, 'baris');
assert.strictEqual(Number(objects[0].age), 99);
assert.strictEqual(objects[1].name, 'ginger');
assert.strictEqual(Number(objects[1].age), 3);
assert.strictEqual(!!objects[2], false);
});
});
describe('getObjectKeys()', () => {

Loading…
Cancel
Save