it_only_db('mongo')('should error on invalid relative time', function (done) { const obj1 = new Parse.Object('MyCustomObject', { name: 'obj1', ttl: new Date(Date.now() + 2 * 24 * 60 * 60 * 1000), // 2 days from now }); const q = new Parse.Query('MyCustomObject'); q.greaterThan('ttl', { $relativeTime: '-12 bananas ago' }); obj1 .save({ useMasterKey: true }) .then(() => q.find({ useMasterKey: true })) .then(done.fail, () => done()); });
it("GET " + apiPrefix + "customers should PASS", function(done) { //testcase //http get an url agent .get(apiPrefix + "customers") // api url .expect(200) // 2xx for success and 4xx for failure .end(function(err, res) { // Handle /api/customers error if (err) { return done(err); } res.body.should.be.instanceOf(Array); res.body.length.should.be.greaterThan(0); //validate response return done(); }); });
it('count', function (done) { const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) ).then(function () { const query = new Parse.Query(BoxedNumber); query.greaterThan('number', 1); query.count().then(function (count) { equal(count, 8); done(); }); }); });
describe('#grabElementBoundingRect', () => { it('should get the element bounding rectangle', async () => { await I.amOnPage('https://www.google.com'); const size = await I.grabElementBoundingRect('#hplogo'); expect(size.x).is.greaterThan(0); expect(size.y).is.greaterThan(0); expect(size.width).is.greaterThan(0); expect(size.height).is.greaterThan(0); }); it('should get the element width', async () => { await I.amOnPage('https://www.google.com'); const width = await I.grabElementBoundingRect('#hplogo', 'width'); expect(width).is.greaterThan(0); }); it('should get the element height', async () => { await I.amOnPage('https://www.google.com'); const height = await I.grabElementBoundingRect('#hplogo', 'height'); expect(height).is.greaterThan(0); }); });
it('or queries', function (done) { const objects = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function (x) { const object = new Parse.Object('BoxedNumber'); object.set('x', x); return object; }); Parse.Object.saveAll(objects).then(function () { const query1 = new Parse.Query('BoxedNumber'); query1.lessThan('x', 2); const query2 = new Parse.Query('BoxedNumber'); query2.greaterThan('x', 5); const orQuery = Parse.Query.or(query1, query2); orQuery.find().then(function (results) { equal(results.length, 6); for (const number of results) { ok(number.get('x') < 2 || number.get('x') > 5); } done(); }); }); });
it('dontSelect query', function (done) { const RestaurantObject = Parse.Object.extend('Restaurant'); const PersonObject = Parse.Object.extend('Person'); const objects = [ new RestaurantObject({ ratings: 5, location: 'Djibouti' }), new RestaurantObject({ ratings: 3, location: 'Ouagadougou' }), new PersonObject({ name: 'Bob', hometown: 'Djibouti' }), new PersonObject({ name: 'Tom', hometown: 'Ouagadougou' }), new PersonObject({ name: 'Billy', hometown: 'Djibouti' }), ]; Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(RestaurantObject); query.greaterThan('ratings', 4); const mainQuery = new Parse.Query(PersonObject); mainQuery.doesNotMatchKeyInQuery('hometown', 'location', query); mainQuery.find().then(function (results) { equal(results.length, 1); equal(results[0].get('name'), 'Tom'); done(); }); }); });
query.greaterThan('some', 10); query.include('otherKey'); query.include('otherValue');
it('greaterThan zero queries', (done) => { const makeBoxedNumber = (i) => { return new BoxedNumber({ number: i }); }; const numbers = [-3, -2, -1, 0, 1]; const boxedNumbers = numbers.map(makeBoxedNumber); Parse.Object.saveAll(boxedNumbers) .then(() => { const query = new Parse.Query(BoxedNumber); query.greaterThan('number', 0); return query.find(); }) .then((results) => { equal(results.length, 1); done(); }); });
it("GET " + apiPrefix + "payments/103___JM555205 should PASS", function( done ) { //http get an url agent .get(apiPrefix + "payments/103___JM555205") // api url .expect(200) // 2xx for success and 4xx for failure .end(function(err, res) { // Handle /api/tables error if (err) { return done(err); } //validate response - max value here is 14571.44 res.body.length.should.be.equal(1); res.body[0]["amount"].should.be.greaterThan(14570); return done(); }); });
it('lessThan greaterThan queries', function (done) { const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) ).then(function () { const query = new Parse.Query(BoxedNumber); query.lessThan('number', 9); query.greaterThan('number', 3); query.find().then(function (results) { equal(results.length, 5); done(); }); }); });
it('greaterThan queries', function (done) { const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) ).then(function () { const query = new Parse.Query(BoxedNumber); query.greaterThan('number', 7); query.find().then(function (results) { equal(results.length, 2); done(); }); }); });
it('select query', function (done) { const RestaurantObject = Parse.Object.extend('Restaurant'); const PersonObject = Parse.Object.extend('Person'); const objects = [ new RestaurantObject({ ratings: 5, location: 'Djibouti' }), new RestaurantObject({ ratings: 3, location: 'Ouagadougou' }), new PersonObject({ name: 'Bob', hometown: 'Djibouti' }), new PersonObject({ name: 'Tom', hometown: 'Ouagadougou' }), new PersonObject({ name: 'Billy', hometown: 'Detroit' }), ]; Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(RestaurantObject); query.greaterThan('ratings', 4); const mainQuery = new Parse.Query(PersonObject); mainQuery.matchesKeyInQuery('hometown', 'location', query); mainQuery.find().then(function (results) { equal(results.length, 1); equal(results[0].get('name'), 'Bob'); done(); }); }); });
it_only_db('mongo')( 'should error when using $relativeTime on non-Date field', function (done) { const obj1 = new Parse.Object('MyCustomObject', { name: 'obj1', nonDateField: 'abcd', ttl: new Date(Date.now() + 2 * 24 * 60 * 60 * 1000), // 2 days from now }); const q = new Parse.Query('MyCustomObject'); q.greaterThan('nonDateField', { $relativeTime: '1 day ago' }); obj1 .save({ useMasterKey: true }) .then(() => q.find({ useMasterKey: true })) .then(done.fail, () => done()); } );
describe('#grabElementBoundingRect', () => { it('should get the element bounding rectangle', async () => { await I.amOnPage('https://www.google.com'); const size = await I.grabElementBoundingRect('#hplogo'); expect(size.x).is.greaterThan(0); expect(size.y).is.greaterThan(0); expect(size.width).is.greaterThan(0); expect(size.height).is.greaterThan(0); }); it('should get the element width', async () => { await I.amOnPage('https://www.google.com'); const width = await I.grabElementBoundingRect('#hplogo', 'width'); expect(width).is.greaterThan(0); }); it('should get the element height', async () => { await I.amOnPage('https://www.google.com'); const height = await I.grabElementBoundingRect('#hplogo', 'height'); expect(height).is.greaterThan(0); }); });
describe('#grabElementBoundingRect', () => { it('should get the element size', async () => { await wd.amOnPage('https://www.google.com'); const size = await wd.grabElementBoundingRect('#hplogo'); expect(size.x).is.greaterThan(0); expect(size.y).is.greaterThan(0); expect(size.width).is.greaterThan(0); expect(size.height).is.greaterThan(0); }); it('should get the element width', async () => { await wd.amOnPage('https://www.google.com'); const width = await wd.grabElementBoundingRect('#hplogo', 'width'); expect(width).is.greaterThan(0); }); it('should get the element height', async () => { await wd.amOnPage('https://www.google.com'); const height = await wd.grabElementBoundingRect('#hplogo', 'height'); expect(height).is.greaterThan(0); }); });