1 | import CONFIGURATION_1 from './data/configuration_1.json';
|
2 | import CONFIGURATION_1_OPERATIONS_2 from './data/configuration_1_operations_2.json';
|
3 | import craftai from '../src';
|
4 |
|
5 | describe('client.getAgentContextOperations(<agentId>)', function() {
|
6 | let client;
|
7 | const agentId = `getAgentContextOps_${RUN_ID}`;
|
8 |
|
9 | before(function() {
|
10 | client = craftai(CRAFT_CFG);
|
11 | expect(client).to.be.ok;
|
12 | return client.deleteAgent(agentId)
|
13 | .then(() => client.createAgent(CONFIGURATION_1, agentId))
|
14 | .then((createdAgent) => {
|
15 | expect(createdAgent).to.be.ok;
|
16 | return client.addAgentContextOperations(agentId, CONFIGURATION_1_OPERATIONS_2);
|
17 | });
|
18 | });
|
19 |
|
20 | after(function() {
|
21 | return client.deleteAgent(agentId);
|
22 | });
|
23 |
|
24 | it('should retrieve all context operations', function() {
|
25 | return client.getAgentContextOperations(agentId)
|
26 | .then((operations) => {
|
27 | expect(_.first(operations)).to.be.deep.equal(_.first(CONFIGURATION_1_OPERATIONS_2));
|
28 | expect(_.last(operations)).to.be.deep.equal(_.last(CONFIGURATION_1_OPERATIONS_2));
|
29 | expect(operations).to.be.deep.equal(CONFIGURATION_1_OPERATIONS_2);
|
30 | });
|
31 | });
|
32 | it('should only retrieve the operations after the given lower bound', function() {
|
33 | const lowerBound = 1464356844;
|
34 | return client.getAgentContextOperations(agentId, lowerBound)
|
35 | .then((operations) => {
|
36 | const expectedOperations = _.filter(CONFIGURATION_1_OPERATIONS_2, ({ timestamp }) => timestamp >= lowerBound);
|
37 | expect(operations).to.be.deep.equal(expectedOperations);
|
38 | });
|
39 | });
|
40 |
|
41 | it('should only retrieve the operations before the given upper bound', function() {
|
42 | const upperBound = 1462824549;
|
43 | return client.getAgentContextOperations(agentId, undefined, upperBound)
|
44 | .then((operations) => {
|
45 | const expectedOperations = _.filter(CONFIGURATION_1_OPERATIONS_2, ({ timestamp }) => timestamp <= upperBound);
|
46 | expect(operations).to.be.deep.equal(expectedOperations);
|
47 | });
|
48 | });
|
49 |
|
50 | it('should retrieve no operations between the desired bounds', function() {
|
51 | const lowerBound = 1464356844;
|
52 | const upperBound = 1462824549;
|
53 | return client.getAgentContextOperations(agentId, lowerBound, upperBound)
|
54 | .then((operations) => {
|
55 | const expectedOperations = _.filter(CONFIGURATION_1_OPERATIONS_2, ({ timestamp }) => timestamp >= lowerBound && timestamp <= upperBound);
|
56 | expect(operations).to.be.deep.equal(expectedOperations);
|
57 | });
|
58 | });
|
59 |
|
60 | it('should only retrieve the operations between the desired bounds', function() {
|
61 | const lowerBound = 1462824549;
|
62 | const upperBound = 1464356844;
|
63 | return client.getAgentContextOperations(agentId, lowerBound, upperBound)
|
64 | .then((operations) => {
|
65 | const expectedOperations = _.filter(CONFIGURATION_1_OPERATIONS_2, ({ timestamp }) => timestamp >= lowerBound && timestamp <= upperBound);
|
66 | expect(operations).to.be.deep.equal(expectedOperations);
|
67 | });
|
68 | });
|
69 | });
|