UNPKG

11 kBJavaScriptView Raw
1import CONFIGURATION_1 from './data/configuration_1.json';
2import CONFIGURATION_1_OPERATIONS_1 from './data/configuration_1_operations_1.json';
3import craftai from '../src';
4
5describe('client.getAgentStateHistory(<agentId>)', function() {
6 let client;
7 const agentId = `getAgentStateHistory_${RUN_ID}`;
8
9 before(function() {
10 client = craftai(CRAFT_CFG);
11 expect(client).to.be.ok;
12 return client.deleteAgent(agentId) // Delete any preexisting agent with this id.
13 .then(() => client.createAgent(CONFIGURATION_1, agentId))
14 .then((createdAgent) => {
15 expect(createdAgent).to.be.ok;
16 return client.addAgentContextOperations(agentId, CONFIGURATION_1_OPERATIONS_1);
17 });
18 });
19
20 after(function() {
21 return client.deleteAgent(agentId);
22 });
23
24 it('should retrieve all state history', function() {
25 return client.getAgentStateHistory(agentId)
26 .then((stateHistory) => {
27 expect(stateHistory.length).to.be.equal(16);
28 expect(stateHistory).to.be.deep.equal([
29 {
30 sample: {
31 presence: 'robert',
32 lightIntensity: 0.4,
33 lightbulbColor: 'green'
34 },
35 timestamp: 1464600000
36 },
37 {
38 sample: {
39 presence: 'robert',
40 lightIntensity: 0.4,
41 lightbulbColor: 'green'
42 },
43 timestamp: 1464600100 },
44 {
45 sample: {
46 presence: 'robert',
47 lightIntensity: 0.4,
48 lightbulbColor: 'green'
49 },
50 timestamp: 1464600200
51 },
52 {
53 sample: {
54 presence: 'robert',
55 lightIntensity: 0.4,
56 lightbulbColor: 'green'
57 },
58 timestamp: 1464600300
59 },
60 {
61 sample: {
62 presence: 'robert',
63 lightIntensity: 0.4,
64 lightbulbColor: 'green'
65 },
66 timestamp: 1464600400
67 },
68 {
69 sample: {
70 presence: 'none',
71 lightIntensity: 0,
72 lightbulbColor: 'black'
73 },
74 timestamp: 1464600500
75 },
76 {
77 sample: {
78 presence: 'none',
79 lightIntensity: 0,
80 lightbulbColor: 'black'
81 },
82 timestamp: 1464600600
83 },
84 {
85 sample: {
86 presence: 'none',
87 lightIntensity: 0,
88 lightbulbColor: 'black'
89 },
90 timestamp: 1464600700
91 },
92 {
93 sample: {
94 presence: 'none',
95 lightIntensity: 0,
96 lightbulbColor: 'black'
97 },
98 timestamp: 1464600800
99 },
100 {
101 sample: {
102 presence: 'none',
103 lightIntensity: 0,
104 lightbulbColor: 'black'
105 },
106 timestamp: 1464600900
107 },
108 {
109 sample: {
110 presence: 'gisele',
111 lightIntensity: 0.4,
112 lightbulbColor: 'blue'
113 },
114 timestamp: 1464601000
115 },
116 {
117 sample: {
118 presence: 'gisele',
119 lightIntensity: 0.4,
120 lightbulbColor: 'blue'
121 },
122 timestamp: 1464601100
123 },
124 {
125 sample: {
126 presence: 'gisele',
127 lightIntensity: 0.4,
128 lightbulbColor: 'blue'
129 },
130 timestamp: 1464601200
131 },
132 {
133 sample: {
134 presence: 'gisele',
135 lightIntensity: 0.4,
136 lightbulbColor: 'blue'
137 },
138 timestamp: 1464601300
139 },
140 {
141 sample: {
142 presence: 'gisele',
143 lightIntensity: 0.4,
144 lightbulbColor: 'blue'
145 },
146 timestamp: 1464601400
147 },
148 {
149 sample: {
150 presence: 'robert',
151 lightIntensity: 0.6,
152 lightbulbColor: 'green'
153 },
154 timestamp: 1464601500
155 }
156 ]);
157 });
158 });
159
160 it('should only retrieve the state after the given lower bound', function() {
161 const lowerBound = 1464600867;
162 return client.getAgentStateHistory(agentId, lowerBound)
163 .then((stateHistory) => {
164 expect(stateHistory).to.be.deep.equal([
165 {
166 sample: {
167 presence: 'none',
168 lightIntensity: 0,
169 lightbulbColor: 'black'
170 },
171 timestamp: 1464600900
172 },
173 {
174 sample: {
175 presence: 'gisele',
176 lightIntensity: 0.4,
177 lightbulbColor: 'blue'
178 },
179 timestamp: 1464601000
180 },
181 {
182 sample: {
183 presence: 'gisele',
184 lightIntensity: 0.4,
185 lightbulbColor: 'blue'
186 },
187 timestamp: 1464601100
188 },
189 {
190 sample: {
191 presence: 'gisele',
192 lightIntensity: 0.4,
193 lightbulbColor: 'blue'
194 },
195 timestamp: 1464601200
196 },
197 {
198 sample: {
199 presence: 'gisele',
200 lightIntensity: 0.4,
201 lightbulbColor: 'blue'
202 },
203 timestamp: 1464601300
204 },
205 {
206 sample: {
207 presence: 'gisele',
208 lightIntensity: 0.4,
209 lightbulbColor: 'blue'
210 },
211 timestamp: 1464601400
212 },
213 {
214 sample: {
215 presence: 'robert',
216 lightIntensity: 0.6,
217 lightbulbColor: 'green'
218 },
219 timestamp: 1464601500
220 }
221 ]);
222 });
223 });
224
225 it('should only retrieve the state before the given upper bound', function() {
226 const upperBound = 1464601439;
227 return client.getAgentStateHistory(agentId, undefined, upperBound)
228 .then((stateHistory) => {
229 expect(stateHistory).to.be.deep.equal([
230 {
231 sample: {
232 presence: 'robert',
233 lightIntensity: 0.4,
234 lightbulbColor: 'green'
235 },
236 timestamp: 1464600000
237 },
238 {
239 sample: {
240 presence: 'robert',
241 lightIntensity: 0.4,
242 lightbulbColor: 'green'
243 },
244 timestamp: 1464600100 },
245 {
246 sample: {
247 presence: 'robert',
248 lightIntensity: 0.4,
249 lightbulbColor: 'green'
250 },
251 timestamp: 1464600200
252 },
253 {
254 sample: {
255 presence: 'robert',
256 lightIntensity: 0.4,
257 lightbulbColor: 'green'
258 },
259 timestamp: 1464600300
260 },
261 {
262 sample: {
263 presence: 'robert',
264 lightIntensity: 0.4,
265 lightbulbColor: 'green'
266 },
267 timestamp: 1464600400
268 },
269 {
270 sample: {
271 presence: 'none',
272 lightIntensity: 0,
273 lightbulbColor: 'black'
274 },
275 timestamp: 1464600500
276 },
277 {
278 sample: {
279 presence: 'none',
280 lightIntensity: 0,
281 lightbulbColor: 'black'
282 },
283 timestamp: 1464600600
284 },
285 {
286 sample: {
287 presence: 'none',
288 lightIntensity: 0,
289 lightbulbColor: 'black'
290 },
291 timestamp: 1464600700
292 },
293 {
294 sample: {
295 presence: 'none',
296 lightIntensity: 0,
297 lightbulbColor: 'black'
298 },
299 timestamp: 1464600800
300 },
301 {
302 sample: {
303 presence: 'none',
304 lightIntensity: 0,
305 lightbulbColor: 'black'
306 },
307 timestamp: 1464600900
308 },
309 {
310 sample: {
311 presence: 'gisele',
312 lightIntensity: 0.4,
313 lightbulbColor: 'blue'
314 },
315 timestamp: 1464601000
316 },
317 {
318 sample: {
319 presence: 'gisele',
320 lightIntensity: 0.4,
321 lightbulbColor: 'blue'
322 },
323 timestamp: 1464601100
324 },
325 {
326 sample: {
327 presence: 'gisele',
328 lightIntensity: 0.4,
329 lightbulbColor: 'blue'
330 },
331 timestamp: 1464601200
332 },
333 {
334 sample: {
335 presence: 'gisele',
336 lightIntensity: 0.4,
337 lightbulbColor: 'blue'
338 },
339 timestamp: 1464601300
340 },
341 {
342 sample: {
343 presence: 'gisele',
344 lightIntensity: 0.4,
345 lightbulbColor: 'blue'
346 },
347 timestamp: 1464601400
348 }
349 ]);
350 });
351 });
352
353 it('should only retrieve the state between the desired bounds', function() {
354 const lowerBound = 1464600449;
355 const upperBound = 1464601124;
356 return client.getAgentStateHistory(agentId, lowerBound, upperBound)
357 .then((stateHistory) => {
358 expect(stateHistory).to.be.deep.equal([
359 {
360 sample: {
361 presence: 'none',
362 lightIntensity: 0,
363 lightbulbColor: 'black'
364 },
365 timestamp: 1464600500
366 },
367 {
368 sample: {
369 presence: 'none',
370 lightIntensity: 0,
371 lightbulbColor: 'black'
372 },
373 timestamp: 1464600600
374 },
375 {
376 sample: {
377 presence: 'none',
378 lightIntensity: 0,
379 lightbulbColor: 'black'
380 },
381 timestamp: 1464600700
382 },
383 {
384 sample: {
385 presence: 'none',
386 lightIntensity: 0,
387 lightbulbColor: 'black'
388 },
389 timestamp: 1464600800
390 },
391 {
392 sample: {
393 presence: 'none',
394 lightIntensity: 0,
395 lightbulbColor: 'black'
396 },
397 timestamp: 1464600900
398 },
399 {
400 sample: {
401 presence: 'gisele',
402 lightIntensity: 0.4,
403 lightbulbColor: 'blue'
404 },
405 timestamp: 1464601000
406 },
407 {
408 sample: {
409 presence: 'gisele',
410 lightIntensity: 0.4,
411 lightbulbColor: 'blue'
412 },
413 timestamp: 1464601100
414 }
415 ]);
416 });
417 });
418});