|
1 | | -/*eslint-env jasmine */ |
2 | | - |
| 1 | +/* eslint-env jasmine */ |
3 | 2 | 'use strict'; |
4 | 3 |
|
5 | | -var angular = require('angular'); |
6 | | -var Api = require('./../src/service/Api'); |
7 | | - |
| 4 | +var Api = require('../src/service/Api'); |
8 | 5 | describe('Api', function() { |
9 | | - |
10 | | - beforeEach(function() { |
11 | | - var ngModule = angular.module('mockModule', []); |
| 6 | + var apiKey, |
| 7 | + config, |
| 8 | + sessionId = apiKey = '12345678'; |
12 | 9 |
|
13 | | - require('./../src/streamApiServiceProvider')(ngModule); |
14 | | - }); |
15 | | - |
16 | | - beforeEach(angular.mock.module('mockModule')); |
17 | | - |
18 | | - var streamApiService; |
19 | | - |
20 | 10 | beforeEach(function() { |
21 | | - angular.mock.inject(function(_streamApiService_) { |
22 | | - streamApiService = _streamApiService_; |
23 | | - }); |
24 | | - }); |
25 | | - |
26 | | - it('should return an object of type Api', function() { |
27 | | - var api = streamApiService.getInstance({url:'https://foo'}); |
28 | | - expect(api).toEqual(jasmine.any(Api)); |
29 | | - }); |
30 | | - |
31 | | - it('should throw exception when passed not an object', function() { |
32 | | - expect(function(){streamApiService.getInstance('foo');}) |
33 | | - .toThrow(new Error('Please provide valid configuration object.')); |
34 | | - }); |
35 | | - |
36 | | - it('should throw exception when not passed argument', function() { |
37 | | - expect(function(){streamApiService.getInstance();}) |
38 | | - .toThrow(new Error('Please provide valid configuration object.')); |
39 | | - }); |
40 | | - |
41 | | - it('should throw exception when passed argument hasn\'t url property', function() { |
42 | | - expect(function(){streamApiService.getInstance({nourl: 'foo'});}) |
43 | | - .toThrow(new Error('\'config\' should have \'url\' property of type \'string\'')); |
44 | | - }); |
45 | | - |
46 | | - it('should throw exception when url type is not string', function() { |
47 | | - expect(function(){streamApiService.getInstance({url: 1});}) |
48 | | - .toThrow(new Error('\'config\' should have \'url\' property of type \'string\'')); |
49 | | - }); |
50 | | - |
51 | | - it('should throw exception when passing config.url without valid scheme', function() { |
52 | | - expect(function(){streamApiService.getInstance({url: 'foo'});}) |
53 | | - .toThrow(new Error('You must provide valid scheme with \'url\'')); |
54 | | - }); |
55 | | - |
56 | | - it('should set it\'s config.url correctly when passed correct url and not passed version', function() { |
57 | | - var api = streamApiService.getInstance({url: 'https://foo'}); |
58 | | - expect(api.options.url) |
59 | | - .toBe('https://foo/attask/api-internal'); |
60 | | - }); |
61 | | - |
62 | | - it('should set it\'s config.url when passed valid url and version unsupported', function() { |
63 | | - var api = streamApiService.getInstance({url: 'https://foo', version: 'unsupported'}); |
64 | | - expect(api.options.url) |
65 | | - .toBe('https://foo/attask/api-unsupported'); |
66 | | - }); |
67 | | - |
68 | | - it('should set it\'s config.url when passed valid url and version internal', function() { |
69 | | - var api = streamApiService.getInstance({url: 'https://foo', version: 'internal'}); |
70 | | - expect(api.options.url) |
71 | | - .toBe('https://foo/attask/api-internal'); |
72 | | - }); |
73 | | - |
74 | | - it('should set it\'s config.url when passed valid url and version number', function() { |
75 | | - var api = streamApiService.getInstance({url: 'https://foo', version: '5.0'}); |
76 | | - expect(api.options.url) |
77 | | - .toBe('https://foo/attask/api/v5.0'); |
78 | | - }); |
79 | | - |
80 | | - it('should return the same object on each getInstance regardless of passed config and version', function() { |
81 | | - var api1 = streamApiService.getInstance({url: 'https://foo', version: '5.0'}); |
82 | | - var api2 = streamApiService.getInstance({url: 'https://bar', version: '4.0'}); |
83 | | - expect(api1).toBe(api2); |
84 | | - }); |
85 | | - |
86 | | - it('should return new Api object when requested new', function() { |
87 | | - var api1 = streamApiService.getInstance({url: 'https://foo', version: '5.0'}); |
88 | | - var api2 = streamApiService.getInstance({url: 'https://bar', version: '4.0'}, true); |
89 | | - expect(api1).not.toBe(api2); |
| 11 | + config = { |
| 12 | + host: 'https://foo', |
| 13 | + version: '5.0' |
| 14 | + }; |
90 | 15 | }); |
91 | 16 |
|
92 | 17 | it('should set option headers to sessionId when passed', function() { |
93 | | - var sessionId = '12345678', |
94 | | - api = streamApiService.getInstance({url: 'https://foo', version: '5.0', sessionId: sessionId}); |
95 | | - expect(api.options.headers).not.toBe({sessionID: sessionId}); |
| 18 | + config.sessionId = sessionId; |
| 19 | + var api = new Api(config); |
| 20 | + expect(api.options.headers.sessionID).toBe(sessionId); |
96 | 21 | }); |
97 | 22 |
|
98 | 23 | it('should set option headers to apiKey when passed', function() { |
99 | | - var apiKey = '12345678', |
100 | | - api = streamApiService.getInstance({url: 'https://foo', version: '5.0', apiKey: apiKey}); |
101 | | - expect(api.options.headers).not.toBe({apiKey: apiKey}); |
| 24 | + config.apiKey = apiKey; |
| 25 | + var api = new Api(config); |
| 26 | + expect(api.options.headers.apiKey).toBe(apiKey); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should has Methods property', function() { |
| 30 | + config.apiKey = apiKey; |
| 31 | + var api = new Api(config); |
| 32 | + expect(api.Methods).toBeDefined(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should has Constants property', function() { |
| 36 | + config.apiKey = apiKey; |
| 37 | + var api = new Api(config); |
| 38 | + expect(api.Constants).toBeDefined(); |
102 | 39 | }); |
103 | 40 | }); |
0 commit comments