UNPKG

1.73 kBJavaScriptView Raw
1import CONFIGURATION_1 from './data/configuration_1.json';
2
3import craftai, { errors } from '../src';
4
5describe('client.getAgent(<agentId>)', function() {
6 let client;
7 let agent;
8 const agentId = `get_agent_${RUN_ID}`;
9
10 before(function() {
11 client = craftai(CRAFT_CFG);
12 expect(client).to.be.ok;
13 });
14
15 beforeEach(function() {
16 return client.deleteAgent(agentId) // Delete any preexisting agent with this id.
17 .then(() => client.createAgent(CONFIGURATION_1, agentId))
18 .then((createdAgent) => {
19 expect(createdAgent).to.be.ok;
20 agent = createdAgent;
21 });
22 });
23
24 afterEach(function() {
25 return client.deleteAgent(agentId);
26 });
27
28 it('should return no first/last timestamps on "empty" agents', function() {
29 return client.getAgent(agent.id)
30 .then((retrievedAgent) => {
31 expect(retrievedAgent.firstTimestamp).to.be.undefined;
32 expect(retrievedAgent.lastTimestamp).to.be.undefined;
33 });
34 });
35
36 it('should fail on non-existing agent', function() {
37 return client.deleteAgent(agentId)
38 .then(() => client.getAgent(agent.id))
39 .then(
40 () => Promise.reject(new Error('Should not be reached')),
41 (err) => {
42 expect(err).to.be.an.instanceof(errors.CraftAiError);
43 expect(err).to.be.an.instanceof(errors.CraftAiBadRequestError);
44 }
45 );
46 });
47
48 it('should fail on bad agent id', function() {
49 return client.getAgent('foo@bar/toto')
50 .then(
51 () => Promise.reject(new Error('Should not be reached')),
52 (err) => {
53 expect(err).to.be.an.instanceof(errors.CraftAiError);
54 expect(err).to.be.an.instanceof(errors.CraftAiBadRequestError);
55 }
56 );
57 });
58});