From 52526cb7ac304137a9c44b4496f222992113cf40 Mon Sep 17 00:00:00 2001 From: OKNoah Date: Fri, 1 Sep 2017 15:51:17 -0700 Subject: [PATCH] Attemps to fix array bug --- fields/field-types.js | 4 ++-- index.test.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/fields/field-types.js b/fields/field-types.js index 56bba41..94d5db2 100644 --- a/fields/field-types.js +++ b/fields/field-types.js @@ -25,7 +25,7 @@ export default class FieldTypes extends FieldType { } convertToModelValue (array) { - if (!array && this.options.optional) { + if (!array) { return } @@ -35,7 +35,7 @@ export default class FieldTypes extends FieldType { } convertToDocumentValue (array) { - if (!array && this.options.optional) { + if (!array) { return } diff --git a/index.test.js b/index.test.js index 7c87549..855dbb8 100644 --- a/index.test.js +++ b/index.test.js @@ -17,6 +17,7 @@ const db = ormjs.connect({ class User extends db.Model { static schema = { name: String, + interests: { $type: [String], optional: true }, profile: { vegan: { $type: Boolean, optional: true } } @@ -119,6 +120,42 @@ test('check list is sorted', async () => { expect(isEqual(posts, sorted)).toBe(true) }) +test('Update with arangojs', async () => { + const { _collection } = await User + + const user = await User.findOne({ + where: { name: username } + }) + + await _collection.update(user, { + interests: ['fun', 'games'] + }) + + const updatedUser = await User.findOne({ + where: { name: username } + }) + + expect(updatedUser).toHaveProperty('interests') +}) + +test('Remove last arangojs update', async () => { + const { _collection } = await User + + const user = await User.findOne({ + where: { name: username } + }) + + await _collection.update(user, { + interests: null + }) + + const updatedUser = await User.findOne({ + where: { name: username } + }) + + expect(updatedUser).toHaveProperty('interests') +}) + test('remove item', async () => { const userToRemove = await User.findOne({ where: { name: username }