Skip to content

Commit

Permalink
FIX: Issues with the fill() operation
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Jul 23, 2020
1 parent 6b2e8a8 commit dc72182
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions js/data/model.js
Expand Up @@ -40,8 +40,8 @@ export class Model {
*/
static async fill(model = {}, safe = false) {
for (const [name, field] of Object.entries(this.schema)) {
if (model.name !== undefined) continue;
if (["_id"].includes(model.name)) continue;
if (model[name] !== undefined) continue;
if (["_id"].includes(model[name])) continue;
const _private = field.private === undefined ? false : field.private;
const increment = field.increment === undefined ? false : field.increment;
if (_private && safe) continue;
Expand Down
6 changes: 6 additions & 0 deletions test/data/mock.js
Expand Up @@ -17,6 +17,12 @@ class Person extends yonius.ModelStore {
},
name: {
initial: "dummy"
},
age: {
type: Number
},
info: {
type: Object
}
};
}
Expand Down
6 changes: 5 additions & 1 deletion test/data/model.js
Expand Up @@ -7,7 +7,11 @@ describe("Model", function() {
describe("#fill()", function() {
it("should be able to run simple fill operations", () => {
const person = new mock.Person();
console.info(person);
assert.deepStrictEqual(person.identifier, undefined);
assert.deepStrictEqual(person.identifierSafe, undefined);
assert.deepStrictEqual(person.name, "dummy");
assert.deepStrictEqual(person.age, null);
assert.deepStrictEqual(person.info, null);
});
});
});
Expand Down

0 comments on commit dc72182

Please sign in to comment.