Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Commit

Permalink
Add unit tests to test array inclusion and exclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
SirbyAlive committed Apr 26, 2016
1 parent e6f05e7 commit 7842da0
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions test/queries.js
Expand Up @@ -397,10 +397,11 @@ test('populate the response', async t => {
});
});

test('find documents and include only selected fields', async t => {
test('find documents and include only one selected field', async t => {
let post = new Post({
title: 'San Francisco',
featured: true
featured: true,
published: false
});

await post.save();
Expand All @@ -411,17 +412,48 @@ test('find documents and include only selected fields', async t => {
t.same(keys, ['_id', 'title']);
});

test('find documents and exclude selected fields', async t => {
test('find documents and include only two selected fields', async t => {
let post = new Post({
title: 'San Francisco',
featured: true
featured: true,
published: false
});

await post.save();

let posts = await Post.include(['title', 'featured']).find();
let attrs = posts[0].toJSON();
let keys = Object.keys(attrs);
t.same(keys, ['_id', 'title', 'featured']);
});

test('find documents and exclude one selected field', async t => {
let post = new Post({
title: 'San Francisco',
featured: true,
published: false
});

await post.save();

let posts = await Post.exclude('title').find();
let attrs = posts[0].toJSON();
let keys = Object.keys(attrs);
t.same(keys, ['_id', 'featured', 'published', 'created_at', 'updated_at']);
});

test('find documents and exclude two selected fields', async t => {
let post = new Post({
title: 'San Francisco',
featured: true,
published: false
});

await post.save();

let posts = await Post.exclude(['title', 'published']).find();
let attrs = posts[0].toJSON();
let keys = Object.keys(attrs);
t.same(keys, ['_id', 'featured', 'created_at', 'updated_at']);
});

Expand Down

0 comments on commit 7842da0

Please sign in to comment.