-
Notifications
You must be signed in to change notification settings - Fork 23
/
search.http.spec.ts
114 lines (101 loc) · 3.37 KB
/
search.http.spec.ts
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*!
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
import { HttpVerb } from '../../../src/client/constants/http-verb';
import { SearchHandle } from '../../../src/client/handles/search';
import { SearchThingsResponse } from '../../../src/model/response';
import { DefaultSearchOptions } from '../../../src/options/request.options';
import { HttpHelper as H } from './http.helper';
describe('Http Search Handle', () => {
const baseRequest = 'search/things';
const handle: SearchHandle = H.thingsClient.getSearchHandle();
const errorHandle: SearchHandle = H.errorThingsClient.getSearchHandle();
const searchOptions = DefaultSearchOptions.getInstance()
.withLimit(0, 25)
.withFilter(
'and(like(definition,"*test*"),and(or(ilike(/attributes/test,"*test*"),eq(/definition,"test"))))'
)
.withFields("thingId", "definition", "attributes", "features");
const expectedPayload =
"option=limit(0%2C25)&filter=and(like(definition%2C%22*test*%22)%2Cand(or(ilike(%2Fattributes%2Ftest%2C%22*test*%22)%2Ceq(%2Fdefinition%2C%22test%22))))&fields=thingId%2Cdefinition%2Cattributes%2Cfeatures";
it('gets the Thing by post with search options', () => {
const response = new SearchThingsResponse([H.thing], -1);
return H.test({
toTest: () => handle.postSearch(searchOptions),
testBody: response.toObject(),
expected: response,
payload:expectedPayload,
request: baseRequest,
method: HttpVerb.POST,
status: 200,
});
});
it("gets the Thing by post", () => {
const response = new SearchThingsResponse([H.thing], -1);
return H.test({
toTest: () => handle.postSearch(),
testBody: response.toObject(),
expected: response,
request: baseRequest,
method: HttpVerb.POST,
status: 200,
});
});
it("gets the Thing", () => {
const response = new SearchThingsResponse([H.thing], -1);
return H.test({
toTest: () => handle.search(),
testBody: response.toObject(),
expected: response,
request: baseRequest,
method: HttpVerb.GET,
status: 200
});
});
it('counts Things', () => {
return H.test({
toTest: () => handle.count(),
testBody: 4,
expected: 4,
request: `${baseRequest}/count`,
method: HttpVerb.GET,
status: 200
});
});
it("counts Things by post with search options", () => {
return H.test({
toTest: () => handle.postCount(searchOptions),
testBody: 4,
expected: 4,
request: `${baseRequest}/count`,
method: HttpVerb.POST,
payload: expectedPayload,
status: 200,
});
});
it("counts Things by post", () => {
return H.test({
toTest: () => handle.postCount(),
testBody: 4,
expected: 4,
request: `${baseRequest}/count`,
method: HttpVerb.POST,
status: 200,
});
});
it('returns a search error message', () => {
return H.testError(() => errorHandle.search());
});
it('returns a count error message', () => {
return H.testError(() => errorHandle.count());
});
});