@@ -8,7 +8,6 @@ const matchesQuery = QueryTools.matchesQuery;
|
||||
const Item = Parse.Object.extend('Item');
|
||||
|
||||
describe('queryHash', function() {
|
||||
|
||||
it('should always hash a query to the same string', function() {
|
||||
const q = new Parse.Query(Item);
|
||||
q.equalTo('field', 'value');
|
||||
@@ -91,7 +90,7 @@ describe('matchesQuery', function() {
|
||||
it('matches blanket queries', function() {
|
||||
const obj = {
|
||||
id: new Id('Klass', 'O1'),
|
||||
value: 12
|
||||
value: 12,
|
||||
};
|
||||
const q = new Parse.Query('Klass');
|
||||
expect(matchesQuery(obj, q)).toBe(true);
|
||||
@@ -103,7 +102,7 @@ describe('matchesQuery', function() {
|
||||
it('matches existence queries', function() {
|
||||
const obj = {
|
||||
id: new Id('Item', 'O1'),
|
||||
count: 15
|
||||
count: 15,
|
||||
};
|
||||
const q = new Parse.Query('Item');
|
||||
q.exists('count');
|
||||
@@ -115,7 +114,7 @@ describe('matchesQuery', function() {
|
||||
it('matches queries with doesNotExist constraint', function() {
|
||||
const obj = {
|
||||
id: new Id('Item', 'O1'),
|
||||
count: 15
|
||||
count: 15,
|
||||
};
|
||||
let q = new Parse.Query('Item');
|
||||
q.doesNotExist('name');
|
||||
@@ -130,14 +129,14 @@ describe('matchesQuery', function() {
|
||||
const day = new Date();
|
||||
const location = new Parse.GeoPoint({
|
||||
latitude: 37.484815,
|
||||
longitude: -122.148377
|
||||
longitude: -122.148377,
|
||||
});
|
||||
const obj = {
|
||||
id: new Id('Person', 'O1'),
|
||||
score: 12,
|
||||
name: 'Bill',
|
||||
birthday: day,
|
||||
lastLocation: location
|
||||
lastLocation: location,
|
||||
};
|
||||
|
||||
let q = new Parse.Query('Person');
|
||||
@@ -169,21 +168,30 @@ describe('matchesQuery', function() {
|
||||
expect(matchesQuery(obj, q)).toBe(false);
|
||||
|
||||
q = new Parse.Query('Person');
|
||||
q.equalTo('lastLocation', new Parse.GeoPoint({
|
||||
latitude: 37.484815,
|
||||
longitude: -122.148377
|
||||
}));
|
||||
q.equalTo(
|
||||
'lastLocation',
|
||||
new Parse.GeoPoint({
|
||||
latitude: 37.484815,
|
||||
longitude: -122.148377,
|
||||
})
|
||||
);
|
||||
expect(matchesQuery(obj, q)).toBe(true);
|
||||
q.equalTo('lastLocation', new Parse.GeoPoint({
|
||||
latitude: 37.4848,
|
||||
longitude: -122.1483
|
||||
}));
|
||||
q.equalTo(
|
||||
'lastLocation',
|
||||
new Parse.GeoPoint({
|
||||
latitude: 37.4848,
|
||||
longitude: -122.1483,
|
||||
})
|
||||
);
|
||||
expect(matchesQuery(obj, q)).toBe(false);
|
||||
|
||||
q.equalTo('lastLocation', new Parse.GeoPoint({
|
||||
latitude: 37.484815,
|
||||
longitude: -122.148377
|
||||
}));
|
||||
q.equalTo(
|
||||
'lastLocation',
|
||||
new Parse.GeoPoint({
|
||||
latitude: 37.484815,
|
||||
longitude: -122.148377,
|
||||
})
|
||||
);
|
||||
q.equalTo('score', 12);
|
||||
q.equalTo('name', 'Bill');
|
||||
q.equalTo('birthday', day);
|
||||
@@ -194,7 +202,7 @@ describe('matchesQuery', function() {
|
||||
|
||||
let img = {
|
||||
id: new Id('Image', 'I1'),
|
||||
tags: ['nofilter', 'latergram', 'tbt']
|
||||
tags: ['nofilter', 'latergram', 'tbt'],
|
||||
};
|
||||
|
||||
q = new Parse.Query('Image');
|
||||
@@ -219,8 +227,8 @@ describe('matchesQuery', function() {
|
||||
objectId: 'I1',
|
||||
owner: {
|
||||
className: '_User',
|
||||
objectId: 'U2'
|
||||
}
|
||||
objectId: 'U2',
|
||||
},
|
||||
};
|
||||
expect(matchesQuery(img, q)).toBe(true);
|
||||
|
||||
@@ -234,10 +242,12 @@ describe('matchesQuery', function() {
|
||||
img = {
|
||||
className: 'Image',
|
||||
objectId: 'I1',
|
||||
owners: [{
|
||||
className: '_User',
|
||||
objectId: 'U2'
|
||||
}]
|
||||
owners: [
|
||||
{
|
||||
className: '_User',
|
||||
objectId: 'U2',
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(matchesQuery(img, q)).toBe(true);
|
||||
|
||||
@@ -291,7 +301,7 @@ describe('matchesQuery', function() {
|
||||
const player = {
|
||||
id: new Id('Player', 'P1'),
|
||||
name: 'Player 1',
|
||||
score: 12
|
||||
score: 12,
|
||||
};
|
||||
const q = new Parse.Query('Player');
|
||||
q.equalTo('name', 'Player 1');
|
||||
@@ -307,7 +317,7 @@ describe('matchesQuery', function() {
|
||||
const player = {
|
||||
id: new Id('Player', 'P1'),
|
||||
name: 'Player 1',
|
||||
score: 12
|
||||
score: 12,
|
||||
};
|
||||
|
||||
let q = new Parse.Query('Player');
|
||||
@@ -358,14 +368,14 @@ describe('matchesQuery', function() {
|
||||
// With no max distance, any GeoPoint is 'near'
|
||||
const pt = {
|
||||
id: new Id('Checkin', 'C1'),
|
||||
location: new Parse.GeoPoint(40, 40)
|
||||
location: new Parse.GeoPoint(40, 40),
|
||||
};
|
||||
const ptUndefined = {
|
||||
id: new Id('Checkin', 'C1')
|
||||
id: new Id('Checkin', 'C1'),
|
||||
};
|
||||
const ptNull = {
|
||||
id: new Id('Checkin', 'C1'),
|
||||
location: null
|
||||
location: null,
|
||||
};
|
||||
expect(matchesQuery(pt, q)).toBe(true);
|
||||
expect(matchesQuery(ptUndefined, q)).toBe(false);
|
||||
@@ -384,24 +394,24 @@ describe('matchesQuery', function() {
|
||||
const caltrainStation = {
|
||||
id: new Id('Checkin', 'C1'),
|
||||
location: new Parse.GeoPoint(37.776346, -122.394218),
|
||||
name: 'Caltrain'
|
||||
name: 'Caltrain',
|
||||
};
|
||||
|
||||
const santaClara = {
|
||||
id: new Id('Checkin', 'C2'),
|
||||
location: new Parse.GeoPoint(37.325635, -121.945753),
|
||||
name: 'Santa Clara'
|
||||
name: 'Santa Clara',
|
||||
};
|
||||
|
||||
const noLocation = {
|
||||
id: new Id('Checkin', 'C2'),
|
||||
name: 'Santa Clara'
|
||||
name: 'Santa Clara',
|
||||
};
|
||||
|
||||
const nullLocation = {
|
||||
id: new Id('Checkin', 'C2'),
|
||||
location: null,
|
||||
name: 'Santa Clara'
|
||||
name: 'Santa Clara',
|
||||
};
|
||||
|
||||
let q = new Parse.Query('Checkin').withinGeoBox(
|
||||
@@ -437,63 +447,62 @@ describe('matchesQuery', function() {
|
||||
it('matches on subobjects with dot notation', function() {
|
||||
const message = {
|
||||
id: new Id('Message', 'O1'),
|
||||
text: "content",
|
||||
status: {x: "read", y: "delivered"}
|
||||
text: 'content',
|
||||
status: { x: 'read', y: 'delivered' },
|
||||
};
|
||||
|
||||
let q = new Parse.Query('Message');
|
||||
q.equalTo("status.x", "read");
|
||||
q.equalTo('status.x', 'read');
|
||||
expect(matchesQuery(message, q)).toBe(true);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.equalTo("status.z", "read");
|
||||
q.equalTo('status.z', 'read');
|
||||
expect(matchesQuery(message, q)).toBe(false);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.equalTo("status.x", "delivered");
|
||||
q.equalTo('status.x', 'delivered');
|
||||
expect(matchesQuery(message, q)).toBe(false);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.notEqualTo("status.x", "read");
|
||||
q.notEqualTo('status.x', 'read');
|
||||
expect(matchesQuery(message, q)).toBe(false);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.notEqualTo("status.z", "read");
|
||||
q.notEqualTo('status.z', 'read');
|
||||
expect(matchesQuery(message, q)).toBe(true);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.notEqualTo("status.x", "delivered");
|
||||
q.notEqualTo('status.x', 'delivered');
|
||||
expect(matchesQuery(message, q)).toBe(true);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.exists("status.x");
|
||||
q.exists('status.x');
|
||||
expect(matchesQuery(message, q)).toBe(true);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.exists("status.z");
|
||||
q.exists('status.z');
|
||||
expect(matchesQuery(message, q)).toBe(false);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.exists("nonexistent.x");
|
||||
q.exists('nonexistent.x');
|
||||
expect(matchesQuery(message, q)).toBe(false);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.doesNotExist("status.x");
|
||||
q.doesNotExist('status.x');
|
||||
expect(matchesQuery(message, q)).toBe(false);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.doesNotExist("status.z");
|
||||
q.doesNotExist('status.z');
|
||||
expect(matchesQuery(message, q)).toBe(true);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.doesNotExist("nonexistent.z");
|
||||
q.doesNotExist('nonexistent.z');
|
||||
expect(matchesQuery(message, q)).toBe(true);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.equalTo("status.x", "read");
|
||||
q.doesNotExist("status.y");
|
||||
q.equalTo('status.x', 'read');
|
||||
q.doesNotExist('status.y');
|
||||
expect(matchesQuery(message, q)).toBe(false);
|
||||
|
||||
});
|
||||
|
||||
function pointer(className, objectId) {
|
||||
@@ -503,43 +512,51 @@ describe('matchesQuery', function() {
|
||||
it('should support containedIn with pointers', () => {
|
||||
const message = {
|
||||
id: new Id('Message', 'O1'),
|
||||
profile: pointer('Profile', 'abc')
|
||||
profile: pointer('Profile', 'abc'),
|
||||
};
|
||||
let q = new Parse.Query('Message');
|
||||
q.containedIn('profile', [Parse.Object.fromJSON({ className: 'Profile', objectId: 'abc' }),
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'def' })]);
|
||||
q.containedIn('profile', [
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'abc' }),
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'def' }),
|
||||
]);
|
||||
expect(matchesQuery(message, q)).toBe(true);
|
||||
|
||||
q = new Parse.Query('Message');
|
||||
q.containedIn('profile', [Parse.Object.fromJSON({ className: 'Profile', objectId: 'ghi' }),
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'def' })]);
|
||||
q.containedIn('profile', [
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'ghi' }),
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'def' }),
|
||||
]);
|
||||
expect(matchesQuery(message, q)).toBe(false);
|
||||
});
|
||||
|
||||
it('should support notContainedIn with pointers', () => {
|
||||
let message = {
|
||||
id: new Id('Message', 'O1'),
|
||||
profile: pointer('Profile', 'abc')
|
||||
profile: pointer('Profile', 'abc'),
|
||||
};
|
||||
let q = new Parse.Query('Message');
|
||||
q.notContainedIn('profile', [Parse.Object.fromJSON({ className: 'Profile', objectId: 'def' }),
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'ghi' })]);
|
||||
q.notContainedIn('profile', [
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'def' }),
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'ghi' }),
|
||||
]);
|
||||
expect(matchesQuery(message, q)).toBe(true);
|
||||
|
||||
message = {
|
||||
id: new Id('Message', 'O1'),
|
||||
profile: pointer('Profile', 'def')
|
||||
profile: pointer('Profile', 'def'),
|
||||
};
|
||||
q = new Parse.Query('Message');
|
||||
q.notContainedIn('profile', [Parse.Object.fromJSON({ className: 'Profile', objectId: 'ghi' }),
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'def' })]);
|
||||
q.notContainedIn('profile', [
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'ghi' }),
|
||||
Parse.Object.fromJSON({ className: 'Profile', objectId: 'def' }),
|
||||
]);
|
||||
expect(matchesQuery(message, q)).toBe(false);
|
||||
});
|
||||
|
||||
it('should support containedIn queries with [objectId]', () => {
|
||||
let message = {
|
||||
id: new Id('Message', 'O1'),
|
||||
profile: pointer('Profile', 'abc')
|
||||
profile: pointer('Profile', 'abc'),
|
||||
};
|
||||
let q = new Parse.Query('Message');
|
||||
q.containedIn('profile', ['abc', 'def']);
|
||||
@@ -547,7 +564,7 @@ describe('matchesQuery', function() {
|
||||
|
||||
message = {
|
||||
id: new Id('Message', 'O1'),
|
||||
profile: pointer('Profile', 'ghi')
|
||||
profile: pointer('Profile', 'ghi'),
|
||||
};
|
||||
q = new Parse.Query('Message');
|
||||
q.containedIn('profile', ['abc', 'def']);
|
||||
@@ -557,14 +574,14 @@ describe('matchesQuery', function() {
|
||||
it('should support notContainedIn queries with [objectId]', () => {
|
||||
let message = {
|
||||
id: new Id('Message', 'O1'),
|
||||
profile: pointer('Profile', 'ghi')
|
||||
profile: pointer('Profile', 'ghi'),
|
||||
};
|
||||
let q = new Parse.Query('Message');
|
||||
q.notContainedIn('profile', ['abc', 'def']);
|
||||
expect(matchesQuery(message, q)).toBe(true);
|
||||
message = {
|
||||
id: new Id('Message', 'O1'),
|
||||
profile: pointer('Profile', 'ghi')
|
||||
profile: pointer('Profile', 'ghi'),
|
||||
};
|
||||
q = new Parse.Query('Message');
|
||||
q.notContainedIn('profile', ['abc', 'def', 'ghi']);
|
||||
|
||||
Reference in New Issue
Block a user