1 | const assert = require('assert');
|
2 | const co = require('../cockrel');
|
3 |
|
4 |
|
5 |
|
6 | describe("Plugin: pick", function() {
|
7 |
|
8 |
|
9 | it("can pick object values correctly", function(done) {
|
10 |
|
11 | let input = {
|
12 | a : {
|
13 | b : 'Pixel'
|
14 | },
|
15 | age : 12
|
16 | }
|
17 |
|
18 | co.pick({
|
19 | species : 'cat',
|
20 | description : 'A cat named {a.b} is {age} years old!',
|
21 | details : { name : '@a.b', age : '@age' } })
|
22 | .do(check)
|
23 | .begin(input);
|
24 |
|
25 |
|
26 | function check(data) {
|
27 | assert.equal(data.species, 'cat');
|
28 | assert.equal(data.details.name, 'Pixel');
|
29 | assert.equal(data.details.age, 12);
|
30 | assert.equal(data.description, 'A cat named Pixel is 12 years old!');
|
31 | done();
|
32 | }
|
33 |
|
34 | });
|
35 |
|
36 | it("can pick all data with @", function(done) {
|
37 |
|
38 | let input = {
|
39 | a : {
|
40 | b : 'Pixel'
|
41 | },
|
42 | age : 12
|
43 | }
|
44 |
|
45 | co.pick({ all : '@'})
|
46 | .do(check)
|
47 | .begin(input);
|
48 |
|
49 |
|
50 | function check(data) {
|
51 | assert.equal(data.all.a.b, 'Pixel');
|
52 | done();
|
53 | }
|
54 |
|
55 | });
|
56 |
|
57 |
|
58 |
|
59 | });
|
60 |
|
61 |
|