-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
87 lines (72 loc) · 2.42 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const { expect } = require('chai');
const g = require('.');
describe('Gumgum', () => {
it('Must work', () => {
const nin = g.must({ hello: 'world' });
expect(nin.compile()).to.deep.equal({ must: { hello: 'world' } });
});
it('must handle results of other gumgum functions', () => {
const nin = g.must(g.should({ hello: 'world' }));
expect(nin.compile()).to.deep.equal({ must: { should: { hello: 'world' } } });
});
it('Multiple params', () => {
const nin = g.must(
g.should({ hello: 'world' }),
g.mustNot({ say: 'hello' })
);
expect(nin.compile()).to.deep.equal({
must: {
should: { hello: 'world' },
must_not: { say: 'hello' },
}
});
});
it('argument of type array', () => {
const obj = [{ hello: 'world' }];
const nin = g.should(obj);
expect(nin.compile()).to.deep.equal({ should: obj });
});
it('argument of type array with a length > 1', () => {
const obj = [{ hello: 'world' }, { salut: 'bonjour' }]
const nin = g.should(obj);
expect(nin.compile()).to.deep.equal({ should: obj });
});
it('chains', () => {
const obj = { hello: 'world' };
const nin = g().should.bool.must(obj);
expect(nin.compile()).to.deep.equal({
should: { bool: { must: obj } }
});
});
it('Work with complex query', () => {
const res = ['123', '234']
.map(type => g().query.bool(
g().must.match({ type }),
g.mustNot([
g.match({ status: 'created' }),
g.match({ status: 'terminated' })
])
).compile());
expect(res).to.deep.equal([{
query: {
bool: {
must: { match: { type: '123' } },
must_not: [
{ match: { status: 'created' } },
{ match: { status: 'terminated' } }
]
}
}
}, {
query: {
bool: {
must: { match: { type: '234' } },
must_not: [
{ match: { status: 'created' } },
{ match: { status: 'terminated' } }
]
}
}
}]);
});
});