-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add InPredicate and tests #192
Draft
AntonIV8
wants to merge
1
commit into
develop
Choose a base branch
from
feature-161-InPredicate
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# Change Log | ||
|
||
## [Unreleased] | ||
### Added | ||
- The `InPredicate`. | ||
|
||
## [2.6.0-beta.0] - 2020-10-06 | ||
### Added | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import Ember from 'ember'; | ||
import FilterOperator from './filter-operator'; | ||
import Condition from './condition'; | ||
import moment from 'moment'; | ||
|
@@ -681,6 +682,53 @@ export class FalsePredicate extends BasePredicate { | |
} | ||
} | ||
|
||
/** | ||
* The class of in predicate. | ||
* | ||
* @namespace Query | ||
* @class InPredicate | ||
* @extends BasePredicate | ||
* @constructor | ||
*/ | ||
export class InPredicate extends BasePredicate { | ||
constructor(attributePath, valueArray) { | ||
super(); | ||
|
||
if (!attributePath) { | ||
throw new Error('Attribute path is required for inPredicate constructor.'); | ||
} | ||
|
||
if (!Ember.isArray(valueArray) && valueArray.length === 0) { | ||
throw new Error('Array of compared values is required for inPredicate constructor.'); | ||
} | ||
|
||
this._attributePath = attributePath; | ||
this._valueArray = valueArray; | ||
} | ||
|
||
/** | ||
* The path to the attribute for predicate. | ||
* | ||
* @property attributePath | ||
* @type {String} | ||
* @public | ||
*/ | ||
get attributePath() { | ||
return this._attributePath; | ||
} | ||
|
||
/** | ||
* Array of values, that check of attribute exist. | ||
* | ||
* @property valueArray | ||
* @type {Array} | ||
* @public | ||
*/ | ||
get valueArray() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Может |
||
return this._valueArray; | ||
} | ||
} | ||
|
||
/** | ||
* Combines specified predicates using `and` logic condition. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Ember from 'ember'; | ||
import QueryBuilder from 'ember-flexberry-data/query/builder'; | ||
import { InPredicate } from 'ember-flexberry-data/query/predicate'; | ||
|
||
export default function readingComplexPredicates(store, assert) { | ||
assert.expect(3); | ||
let done = assert.async(); | ||
|
||
Ember.run(() => { | ||
initTestData(store) | ||
|
||
.then(() => { | ||
let filterArrayValues = ['Vasya', 'SpiderMan', 'Batman']; | ||
let ip = new InPredicate('name', filterArrayValues); | ||
|
||
let builder = new QueryBuilder(store, 'ember-flexberry-dummy-application-user').where(ip); | ||
return store.query('ember-flexberry-dummy-application-user', builder.build()) | ||
.then((data) => { | ||
assert.equal(data.get('length'), 1, `Predicate "in" | Length`); | ||
assert.ok(data.any(item => item.get('name') === 'Vasya'), `Predicate "in" | Data`); | ||
}); | ||
}) | ||
|
||
.then(() => { | ||
let filterArrayValues = ['CaptainAmerica', 'SpiderMan', 'Batman']; | ||
let ip = new InPredicate('name', filterArrayValues); | ||
|
||
let builder = new QueryBuilder(store, 'ember-flexberry-dummy-application-user').where(ip); | ||
return store.query('ember-flexberry-dummy-application-user', builder.build()) | ||
.then((data) => { | ||
assert.equal(data.get('length'), 0, `Predicate "out" | Length`); | ||
}); | ||
}) | ||
.catch((e) => { | ||
console.log(e, e.message); | ||
throw e; | ||
}) | ||
.finally(done); | ||
}); | ||
} | ||
|
||
function initTestData(store) { | ||
return Ember.RSVP.Promise.all([ | ||
store.createRecord('ember-flexberry-dummy-application-user', { | ||
name: 'Vasya', | ||
eMail: '[email protected]', | ||
karma: 4 | ||
}).save(), | ||
|
||
store.createRecord('ember-flexberry-dummy-application-user', { | ||
name: 'Oleg', | ||
eMail: '[email protected]', | ||
karma: 5 | ||
}).save(), | ||
|
||
store.createRecord('ember-flexberry-dummy-application-user', { | ||
name: 'Oleg', | ||
eMail: '[email protected]', | ||
karma: 7 | ||
}).save(), | ||
|
||
store.createRecord('ember-flexberry-dummy-application-user', { | ||
name: 'Andrey', | ||
eMail: '[email protected]', | ||
karma: 6 | ||
}).save() | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import executeTest from './execute-odata-test'; | ||
import readingInPredicates from '../base/base-reading-in-predicates-test'; | ||
|
||
executeTest('reading | predicates | in predicates', (store, assert) => { | ||
readingInPredicates(store, assert); | ||
}); |
6 changes: 6 additions & 0 deletions
6
tests/unit/CRUD/offline/offline-reading-in-predicates-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import executeTest from './execute-offline-test'; | ||
import readingInPredicates from '../base/base-reading-in-predicates-test'; | ||
|
||
executeTest('reading | predicates | in predicates', (store, assert) => { | ||
readingInPredicates(store, assert); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { module, test } from 'qunit'; | ||
|
||
import { InPredicate } from 'ember-flexberry-data/query/predicate'; | ||
|
||
module('query'); | ||
|
||
test('predicate | in | constructor', function (assert) { | ||
assert.throws(() => new InPredicate(), Error); | ||
assert.throws(() => new InPredicate(''), Error); | ||
assert.throws(() => new InPredicate(null), Error); | ||
assert.throws(() => new InPredicate(null, ''), Error); | ||
assert.throws(() => new InPredicate('', null), Error); | ||
assert.throws(() => new InPredicate('', ''), Error); | ||
assert.throws(() => new InPredicate('', 2), Error); | ||
|
||
let p = new InPredicate('City', ['Perm', 'Moscow', 'Paris']); | ||
|
||
assert.ok(p); | ||
assert.equal(p.attributePath, 'City'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.