Skip to content

Commit 71990ff

Browse files
committed
test: cols.ts
1 parent 5646a92 commit 71990ff

File tree

2 files changed

+215
-40
lines changed

2 files changed

+215
-40
lines changed

tests/cols.ts

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
import { expect } from 'chai'
2+
3+
import { buildAQL } from '../src/index'
4+
5+
describe('multiple collections', () => {
6+
it(`should return an aql object
7+
when multiple collections are passed TOKEN`, () => {
8+
let query = {
9+
view: 'view',
10+
collections: [
11+
{ name: 'coll1', analyzer: 'analyzer1' },
12+
{ name: 'coll2', analyzer: 'analyzer2' },
13+
],
14+
terms: 'hope',
15+
}
16+
const builtAQL = buildAQL(query)
17+
18+
expect(builtAQL).to.be.an('object')
19+
expect(builtAQL.query).to.equal(`
20+
FOR doc IN view
21+
22+
SEARCH
23+
24+
MIN_MATCH(
25+
ANALYZER(
26+
TOKENS(@value0, @value1)
27+
ANY IN doc.@value2, @value1),
28+
ANALYZER(
29+
TOKENS(@value0, @value3)
30+
ANY IN doc.@value2, @value3),
31+
@value4)
32+
33+
34+
OPTIONS @value5
35+
SORT TFIDF(doc) DESC
36+
37+
LIMIT @value6, @value7
38+
RETURN doc`)
39+
})
40+
41+
it(`should return an aql object
42+
when a PHRASE is passed`, () => {
43+
let query = {
44+
view: 'view',
45+
collections: [
46+
{ name: 'coll1', analyzer: 'analyzer1' },
47+
{ name: 'coll2', analyzer: 'analyzer2' },
48+
],
49+
terms: '-"springs eternal"',
50+
}
51+
const builtAQL = buildAQL(query)
52+
expect(builtAQL).to.be.an('object')
53+
54+
expect(builtAQL.query).to.equal(`
55+
FOR doc IN view
56+
57+
SEARCH
58+
59+
60+
61+
NOT (PHRASE(doc.@value0, @value1, @value2) OR PHRASE(doc.@value0, @value1, @value3))
62+
63+
64+
OPTIONS @value4
65+
SORT TFIDF(doc) DESC
66+
67+
LIMIT @value5, @value6
68+
RETURN doc`)
69+
})
70+
71+
it(`should return an aql object
72+
when TOKENs are passed to multiple collections`, () => {
73+
let query = {
74+
view: 'view',
75+
collections: [
76+
{ name: 'coll1', analyzer: 'analyzer1' },
77+
{ name: 'coll2', analyzer: 'analyzer2' },
78+
],
79+
terms: 'hope',
80+
}
81+
const builtAQL = buildAQL(query)
82+
83+
expect(builtAQL).to.be.an('object')
84+
expect(builtAQL.query).to.equal(`
85+
FOR doc IN view
86+
87+
SEARCH
88+
89+
MIN_MATCH(
90+
ANALYZER(
91+
TOKENS(@value0, @value3)
92+
ANY IN doc.@value2, @value3),
93+
ANALYZER(
94+
TOKENS(@value0, @value3)
95+
ANY IN doc.@value2, @value3),
96+
@value4)
97+
98+
99+
OPTIONS @value5
100+
SORT TFIDF(doc) DESC
101+
102+
LIMIT @value6, @value7
103+
RETURN doc`)
104+
})
105+
106+
it.skip(`should return an aql object
107+
when a phrase string is passed for query terms`, () => {
108+
let query = {
109+
view: 'view',
110+
collections: [ { name: 'coll', analyzer: 'analyzer' } ],
111+
terms: '"phrase search"',
112+
}
113+
const builtAQL = buildAQL(query)
114+
expect(builtAQL).to.be.an('object')
115+
116+
expect(builtAQL.query).to.equal(`\n FOR doc IN view\n \n SEARCH \n \n MIN_MATCH(\n ANALYZER(\n TOKENS(@value0, @value1)\n ANY IN doc.@value2, @value1), \n ANALYZER(\n TOKENS(@value0, @value3)\n ANY IN doc.@value2, @value3), \n @value4)\n \n \n OPTIONS @value5\n SORT TFIDF(doc) DESC\n \n LIMIT @value6, @value7\n RETURN doc`
117+
)
118+
})
119+
120+
it.skip(`should handle basic boolean cases`, () => {
121+
let query = {
122+
view: 'view',
123+
collections: [ { name: 'coll', analyzer: 'analyzer' } ],
124+
terms: '-"hope"',
125+
}
126+
127+
const builtAQL = buildAQL(query)
128+
expect(builtAQL).to.be.an('object')
129+
expect(builtAQL.query).to.equal(`
130+
FOR doc IN view
131+
132+
SEARCH
133+
134+
135+
136+
NOT (PHRASE(doc.@value0, @value1, @value2))
137+
138+
139+
OPTIONS @value3
140+
SORT TFIDF(doc) DESC
141+
142+
LIMIT @value4, @value5
143+
RETURN doc`)
144+
})
145+
146+
it.skip(`should handle basic boolean cases`, () => {
147+
let query = {
148+
view: 'view',
149+
collections: [ { name: 'coll', analyzer: 'analyzer' } ],
150+
terms: '-hope',
151+
}
152+
153+
const builtAQL = buildAQL(query)
154+
expect(builtAQL).to.be.an('object')
155+
expect(builtAQL.query).to.equal(`
156+
FOR doc IN view
157+
158+
SEARCH
159+
160+
161+
162+
163+
MIN_MATCH(
164+
ANALYZER(
165+
TOKENS(@value0, @value1)
166+
NONE IN doc.@value2, @value1),
167+
@value3)
168+
169+
OPTIONS @value4
170+
SORT TFIDF(doc) DESC
171+
172+
LIMIT @value5, @value6
173+
RETURN doc`)
174+
})
175+
})

tests/index.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ import { expect } from 'chai'
33
import { buildAQL } from '../src/index'
44

55
describe('index.ts', () => {
6-
it('should export a function named buildAQL', () => {
7-
expect(buildAQL).to.exist
8-
expect(buildAQL).to.be.a('function')
9-
})
6+
it('should export a function named buildAQL', () => {
7+
expect(buildAQL).to.exist
8+
expect(buildAQL).to.be.a('function')
9+
})
1010

11-
it('should validate the query', () => {
12-
expect(() => buildAQL({ view: '', collections: [], terms: [] })).to.throw(/query.view must be a valid ArangoSearch View name/)
11+
it('should validate the query', () => {
12+
expect(() => buildAQL({ view: '', collections: [], terms: [] })).to.throw(/query.view must be a valid ArangoSearch View name/)
1313

14-
expect(() => buildAQL({ view: 'view', collections: [], terms: [] })).to.throw(/query.collections must have at least one name/)
15-
})
14+
expect(() => buildAQL({ view: 'view', collections: [], terms: [] })).to.throw(/query.collections must have at least one name/)
15+
})
1616
})
1717

1818
describe('buildAQL', () => {
19-
it(`should return an aql object
19+
it(`should return an aql object
2020
when an empty string is passed for query terms`, () => {
21-
let query = { view: 'view', collections: [{ name: 'coll', analyzer: 'analyzer' }], terms: '' }
22-
const builtAQL = buildAQL(query)
23-
expect(builtAQL).to.be.an('object')
21+
let query = { view: 'view', collections: [ { name: 'coll', analyzer: 'analyzer' } ], terms: '' }
22+
const builtAQL = buildAQL(query)
23+
expect(builtAQL).to.be.an('object')
2424

25-
expect(builtAQL.query).to.equal(`
25+
expect(builtAQL.query).to.equal(`
2626
FOR doc IN view
2727
2828
SEARCH
@@ -35,16 +35,16 @@ describe('buildAQL', () => {
3535
3636
LIMIT @value2, @value3
3737
RETURN doc`
38-
)
39-
})
38+
)
39+
})
4040

41-
it(`should return an aql object
41+
it(`should return an aql object
4242
when an empty array is passed for query terms`, () => {
43-
let query = { view: 'view', collections: [{ name: 'coll', analyzer: 'analyzer' }], terms: [] }
44-
const builtAQL = buildAQL(query)
45-
expect(builtAQL).to.be.an('object')
43+
let query = { view: 'view', collections: [ { name: 'coll', analyzer: 'analyzer' } ], terms: [] }
44+
const builtAQL = buildAQL(query)
45+
expect(builtAQL).to.be.an('object')
4646

47-
expect(builtAQL.query).to.equal(`
47+
expect(builtAQL.query).to.equal(`
4848
FOR doc IN view
4949
5050
SEARCH
@@ -57,16 +57,16 @@ describe('buildAQL', () => {
5757
5858
LIMIT @value2, @value3
5959
RETURN doc`
60-
)
61-
})
60+
)
61+
})
6262

63-
it(`should return an aql object
63+
it(`should return an aql object
6464
when a phrase string is passed for query terms`, () => {
65-
let query = { view: 'view', collections: [{ name: 'coll', analyzer: 'analyzer' }], terms: '"phrase search"' }
66-
const builtAQL = buildAQL(query)
67-
expect(builtAQL).to.be.an('object')
65+
let query = { view: 'view', collections: [ { name: 'coll', analyzer: 'analyzer' } ], terms: '"phrase search"' }
66+
const builtAQL = buildAQL(query)
67+
expect(builtAQL).to.be.an('object')
6868

69-
expect(builtAQL.query).to.equal(`
69+
expect(builtAQL.query).to.equal(`
7070
FOR doc IN view
7171
7272
SEARCH
@@ -79,14 +79,14 @@ describe('buildAQL', () => {
7979
8080
LIMIT @value4, @value5
8181
RETURN doc`)
82-
})
82+
})
8383

84-
it(`should handle basic boolean cases`, () => {
85-
let query = { view: 'view', collections: [{ name: 'coll', analyzer: 'analyzer' }], terms: '-"hope"' }
84+
it(`should handle basic boolean cases`, () => {
85+
let query = { view: 'view', collections: [ { name: 'coll', analyzer: 'analyzer' } ], terms: '-"hope"' }
8686

87-
const builtAQL = buildAQL(query)
88-
expect(builtAQL).to.be.an('object')
89-
expect(builtAQL.query).to.equal(`
87+
const builtAQL = buildAQL(query)
88+
expect(builtAQL).to.be.an('object')
89+
expect(builtAQL.query).to.equal(`
9090
FOR doc IN view
9191
9292
SEARCH
@@ -101,14 +101,14 @@ describe('buildAQL', () => {
101101
102102
LIMIT @value4, @value5
103103
RETURN doc`)
104-
})
104+
})
105105

106-
it(`should handle basic boolean cases`, () => {
107-
let query = { view: 'view', collections: [{ name: 'coll', analyzer: 'analyzer' }], terms: '-hope' }
106+
it(`should handle basic boolean cases`, () => {
107+
let query = { view: 'view', collections: [ { name: 'coll', analyzer: 'analyzer' } ], terms: '-hope' }
108108

109-
const builtAQL = buildAQL(query)
110-
expect(builtAQL).to.be.an('object')
111-
expect(builtAQL.query).to.equal(`
109+
const builtAQL = buildAQL(query)
110+
expect(builtAQL).to.be.an('object')
111+
expect(builtAQL.query).to.equal(`
112112
FOR doc IN view
113113
114114
SEARCH
@@ -127,5 +127,5 @@ describe('buildAQL', () => {
127127
128128
LIMIT @value5, @value6
129129
RETURN doc`)
130-
})
130+
})
131131
})

0 commit comments

Comments
 (0)