1 | 'use strict';
|
2 |
|
3 | module.exports = function (dbType, context) {
|
4 |
|
5 | describe(dbType + ': pick fields', function () {
|
6 |
|
7 | it('should pick shallow fields', function () {
|
8 | var db = context.db;
|
9 | return db.bulkDocs([
|
10 | { name: 'Mario', _id: 'mario', series: 'Mario', debut: {year: 1981, month: 'May'} },
|
11 | { name: 'Jigglypuff', _id: 'puff', series: 'Pokemon', debut: {year: 1996, month: 'June'} },
|
12 | { name: 'Link', _id: 'link', series: 'Zelda', debut: {year: 1986, month: 'July'} },
|
13 | { name: 'Donkey Kong', _id: 'dk', series: 'Mario', debut: {year: 1981, month: 'April'} },
|
14 | { name: 'Pikachu', series: 'Pokemon', _id: 'pikachu',
|
15 | debut: {year: 1996, month: 'September'} },
|
16 | { name: 'Captain Falcon', _id: 'falcon', series: 'F-Zero',
|
17 | debut: {year: 1990, month: 'December'} }
|
18 | ]).then(function () {
|
19 | return db.find({
|
20 | selector: {_id: {$gt: null}},
|
21 | sort: ['_id'],
|
22 | fields: ['name']
|
23 | });
|
24 | }).then(function (res) {
|
25 | res.docs.should.deep.equal([
|
26 | { name: 'Donkey Kong' },
|
27 | { name: 'Captain Falcon' },
|
28 | { name: 'Link' },
|
29 | { name: 'Mario' },
|
30 | { name: 'Pikachu' },
|
31 | { name: 'Jigglypuff' } ]);
|
32 | });
|
33 | });
|
34 |
|
35 | it('should pick deep fields', function () {
|
36 | var db = context.db;
|
37 | return db.bulkDocs([
|
38 | {_id: 'a', foo: {bar: 'yo'}, bar: {baz: 'hey'}},
|
39 | {_id: 'b', foo: {bar: 'sup'}, bar: {baz: 'dawg'}},
|
40 | {_id: 'c', foo: true, bar: "yo"},
|
41 | {_id: 'd', foo: null, bar: []}
|
42 | ]).then(function () {
|
43 | return db.find({
|
44 | selector: {_id: {$gt: null}},
|
45 | sort: ['_id'],
|
46 | fields: ['_id', 'bar.baz']
|
47 | });
|
48 | }).then(function (res) {
|
49 | res.docs.should.deep.equal([
|
50 | { _id: 'a', bar: { baz: 'hey' } },
|
51 | { _id: 'b', bar: { baz: 'dawg' } },
|
52 | { _id: 'c' },
|
53 | { _id: 'd' } ]);
|
54 | });
|
55 | });
|
56 |
|
57 | it('should pick really deep fields with escape', function () {
|
58 | var db = context.db;
|
59 | return db.bulkDocs([
|
60 | {_id: 'a', really: {deeply: {nested: {'escaped.field': 'You found me!'}}}}
|
61 | ]).then(function () {
|
62 | return db.find({
|
63 | selector: {_id: {$gt: null}},
|
64 | fields: ['really.deeply.nested.escaped\\.field']
|
65 | });
|
66 | }).then(function (res) {
|
67 | res.docs.should.deep.equal([
|
68 | { really: { deeply: { nested: { 'escaped.field': 'You found me!' } } } }
|
69 | ]);
|
70 | });
|
71 | });
|
72 |
|
73 | });
|
74 |
|
75 | }; |
\ | No newline at end of file |