Skip to content
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

Adds withCount query constraint #868

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions integration/test/ParseQueryTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Parse Query', () => {
.then(() => { done() }, () => { done() });
});


it('can do basic queries', (done) => {
const baz = new TestObject({ foo: 'baz' });
const qux = new TestObject({ foo: 'qux' });
Expand Down Expand Up @@ -51,6 +52,119 @@ describe('Parse Query', () => {
}).catch(done.fail);
});

it('can do query with count', async () => {
const items = [];
for (let i = 0; i < 4; i++) {
items.push(new TestObject({ countMe: true }));
}
await Parse.Object.saveAll(items);

const query = new Parse.Query(TestObject);
query.withCount(true);
const {results,count} = await query.find();

assert(typeof count === 'number');
assert.equal(results.length, 4);
assert.equal(count, 4);
for (let i = 0; i < 4; i++) {
assert.equal(results[i].className,'TestObject');
}
});

it('can do query withCount set to false', async () => {
const items = [];
for (let i = 0; i < 4; i++) {
items.push(new TestObject({ countMe: true }));
}
await Parse.Object.saveAll(items);

const query = new Parse.Query(TestObject);
query.withCount(false);
const results = await query.find();

assert.equal(results.length, 4);
for (let i = 0; i < 4; i++) {
assert.equal(results[i].className,'TestObject');
}
});

it('can do query with count on empty collection', async () => {
const query = new Parse.Query(TestObject);
query.withCount(true);
const {results,count} = await query.find();

assert(typeof count == 'number');
assert.equal(results.length, 0);
assert.equal(count, 0);
});

it('can do query with count and limit', async () => {
const items = [];
for (let i = 0; i < 4; i++) {
items.push(new TestObject({ countMe: 2}));
}
await Parse.Object.saveAll(items);
const query = new Parse.Query(TestObject);
query.withCount(true);
query.limit(2);

const {results,count} = await query.find();

assert(typeof count == 'number');
assert.equal(results.length, 2);
assert.equal(count, 4);
});

it('can do query withCount and skip', async () => {
const items = [];
for (let i = 0; i < 4; i++) {
items.push(new TestObject({ countMe: 2}));
}
await Parse.Object.saveAll(items);
const query = new Parse.Query(TestObject);
query.withCount(true);
query.skip(3);

const {results,count} = await query.find();

assert(typeof count == 'number');
assert.equal(results.length, 1);
assert.equal(count, 4);
});

it('can do query when withCount set without arguments', async () => {
const items = [];
for (let i = 0; i < 4; i++) {
items.push(new TestObject({ countMe: 2}));
}
await Parse.Object.saveAll(items);
const query = new Parse.Query(TestObject);
query.withCount();

const {results,count} = await query.find();

assert(typeof count == 'number');
assert.equal(results.length, 4);
assert.equal(count, 4);
});

it('can do query when withCount undefined', async () => {
const items = [];
for (let i = 0; i < 4; i++) {
items.push(new TestObject({ countMe: 2}));
}
await Parse.Object.saveAll(items);
const query = new Parse.Query(TestObject);
let foo;
query.withCount(foo);

const {results,count} = await query.find();

assert(typeof count == 'number');
assert.equal(results.length, 4);
assert.equal(count, 4);
});

it('can do containedIn queries with arrays', (done) => {
const messageList = [];
for (let i = 0; i < 4; i++) {
Expand Down
45 changes: 12 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading