Skip to content

Commit

Permalink
Merge pull request #11 from gcandal/gc/fix-finds
Browse files Browse the repository at this point in the history
Fix Model#findS
  • Loading branch information
joamag committed Sep 9, 2020
2 parents 3db5d00 + 5288710 commit 9c924f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions js/data/model.js
Expand Up @@ -430,10 +430,10 @@ export class ModelStore extends Model {
}

static get default() {
return (
(Object.entries(this.schema).findOne(([name, definition]) => definition.default) || {})
.name || null
const defaultEntry = Object.entries(this.schema).find(
([name, definition]) => definition.default
);
return defaultEntry ? defaultEntry[0] : null;
}

static definitionN(name) {
Expand Down
29 changes: 29 additions & 0 deletions test/util/model.js
Expand Up @@ -27,6 +27,10 @@ class MockModel extends yonius.ModelStore {
type: String,
unique: true,
required: true
},
name: {
type: String,
default: true
}
};
}
Expand Down Expand Up @@ -74,6 +78,31 @@ describe("#find()", function() {
});
});

it("should allow find_s", () => {
MockModel.find({
find_s: "swear"
});
assert.deepStrictEqual(MockModel.lastCall.params, {
name: {
$options: "",
$regex: "swear"
}
});
});

it("should allow case-insentitive find_s", () => {
MockModel.find({
find_s: "swear",
find_i: 1
});
assert.deepStrictEqual(MockModel.lastCall.params, {
name: {
$options: "-i",
$regex: "swear"
}
});
});

it("should allow pages and sorting", () => {
MockModel.find({
find_d: "brand:likei:swear",
Expand Down

0 comments on commit 9c924f5

Please sign in to comment.