UNPKG

3.15 kBJavaScriptView Raw
1import CONFIGURATION_1 from './data/configuration_1.json';
2
3import craftai from '../src';
4
5describe('client.sharedAgentInspectorUrl(<agentId>, <timestamp>)', function() {
6 let client;
7 const agentId = `get_public_url_${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 });
15
16 after(function() {
17 client.deleteAgent(agentId);
18 });
19
20 it('should return a shared inspector url', function() {
21 const timestamp = 1234567890987;
22 return client.getSharedAgentInspectorUrl(agentId, timestamp)
23 .then((publicInspectorUrl) => {
24 expect(publicInspectorUrl).to.not.be.equal('');
25 const splittedPublicInspectorUrl = publicInspectorUrl.split('?');
26 expect(splittedPublicInspectorUrl.length).to.be.equal(2);
27 expect(splittedPublicInspectorUrl[1]).to.be.equal(`t=${timestamp}`);
28 return client.getAgentInspectorUrl(agentId, timestamp)
29 .then((publicInspectorUrlDeprecated) => {
30 expect(publicInspectorUrlDeprecated, publicInspectorUrl);
31 });
32 });
33 });
34
35 it('should return a new shared inspector url, after the deletion of the previous one', function() {
36 return client.getSharedAgentInspectorUrl(agentId)
37 .then((publicInspectorUrl) => {
38 expect(publicInspectorUrl).to.not.be.equal('');
39 const splittedPublicInspectorUrl = publicInspectorUrl.split('?');
40 expect(splittedPublicInspectorUrl.length).to.be.equal(1);
41 return client.deleteSharedAgentInspectorUrl(agentId)
42 .then(() => client.getSharedAgentInspectorUrl(agentId))
43 .then((publicInspectorUrl2) => {
44 expect(publicInspectorUrl2).to.not.be.equal(publicInspectorUrl);
45 });
46 });
47 });
48
49 it('should return a shared inspector url, when a timestamp is specified', function() {
50 const timestamp = 1234567890987;
51 return client.getSharedAgentInspectorUrl(agentId)
52 .then((publicInspectorUrl) => {
53 expect(publicInspectorUrl).to.not.be.equal('');
54 const splittedPublicInspectorUrl = publicInspectorUrl.split('?');
55 expect(splittedPublicInspectorUrl.length).to.be.equal(1);
56 return client.getAgentInspectorUrl(agentId)
57 .then((publicInspectorUrlDeprecated) => {
58 expect(publicInspectorUrlDeprecated, publicInspectorUrl);
59 return client.getSharedAgentInspectorUrl(agentId, timestamp);
60 })
61 .then((publicInspectorUrl2) => {
62 expect(publicInspectorUrl).to.not.be.equal(publicInspectorUrl2);
63 expect(publicInspectorUrl, publicInspectorUrl2.split('?')[0]);
64 });
65 });
66 });
67
68 it('should raise an error when timestamp is invalid', function() {
69 return client.getSharedAgentInspectorUrl(agentId, 'toto')
70 .then(
71 () => Promise.reject(new Error('Should not be reached')),
72 (err) => {
73 expect(err.name).to.be.equal('CraftAiTimeError');
74 expect(err.message).to.be.equal('Time error, given "toto" is invalid.');
75 }
76 );
77 });
78});