1 | import craftai, { errors } from '../src';
|
2 |
|
3 | describe('craftai(<token_or_cfg>)', function() {
|
4 | it('should create a valid client given a valid configuration', function() {
|
5 | const client = craftai(CRAFT_CFG);
|
6 | expect(client.cfg.url).to.be.ok;
|
7 | expect(client.cfg.owner).to.be.ok;
|
8 | expect(client.cfg.project).to.be.ok;
|
9 | expect(client.cfg.token).to.be.equal(CRAFT_CFG.token);
|
10 | });
|
11 |
|
12 | it('should create a valid client given a valid token', function() {
|
13 | const client = craftai(CRAFT_CFG.token);
|
14 | expect(client.cfg.url).to.be.ok;
|
15 | expect(client.cfg.owner).to.be.ok;
|
16 | expect(client.cfg.project).to.be.ok;
|
17 | expect(client.cfg.token).to.be.equal(CRAFT_CFG.token);
|
18 | });
|
19 |
|
20 | it('should fail properly given an invalid token', function() {
|
21 | expect(() => craftai('this is an invalid token')).to.throw(errors.CraftAiCredentialsError);
|
22 | });
|
23 |
|
24 | it('should fail properly given an invalid proxy', function() {
|
25 | expect(
|
26 | () => craftai(Object.assign({}, CRAFT_CFG, {
|
27 | proxy: 7
|
28 | }))
|
29 | ).to.throw(errors.CraftAiBadRequestError);
|
30 |
|
31 | expect(
|
32 | () => craftai(Object.assign({}, CRAFT_CFG, {
|
33 | proxy: 'tutututu'
|
34 | }))
|
35 | ).to.throw(errors.CraftAiBadRequestError);
|
36 | });
|
37 |
|
38 | it('should create a valid client given a valid proxy configuration', function() {
|
39 | const proxy = 'http://10.180.0.146:3128/';
|
40 |
|
41 | const client = craftai(Object.assign({}, CRAFT_CFG, { proxy }));
|
42 |
|
43 | expect(client.cfg.url).to.be.ok;
|
44 | expect(client.cfg.owner).to.be.ok;
|
45 | expect(client.cfg.project).to.be.ok;
|
46 | expect(client.cfg.proxy).to.be.equal(proxy);
|
47 | });
|
48 |
|
49 | it('should create a valid client given an undefined proxy configuration', function() {
|
50 | const proxy = undefined;
|
51 |
|
52 | const client = craftai(Object.assign({}, CRAFT_CFG, { proxy }));
|
53 |
|
54 | expect(client.cfg.url).to.be.ok;
|
55 | expect(client.cfg.owner).to.be.ok;
|
56 | expect(client.cfg.project).to.be.ok;
|
57 | expect(client.cfg.proxy).to.be.equal(proxy);
|
58 | });
|
59 | });
|