Skip to content

Commit bca1690

Browse files
hanged streamApi factory method logic.
1 parent 6463de8 commit bca1690

22 files changed

Lines changed: 258 additions & 156 deletions

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"coveralls": "^2.11.9",
3535
"cross-env": "^1.0.8",
3636
"eslint": "^2.10.2",
37+
"eslint-loader": "^1.3.0",
3738
"istanbul-instrumenter-loader": "^0.2.0",
3839
"jasmine": "^2.4.1",
3940
"karma": "^0.13.22",

‎spec/Api.spec.js‎

Lines changed: 27 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,40 @@
1-
/*eslint-env jasmine */
2-
1+
/* eslint-env jasmine */
32
'use strict';
43

5-
var angular = require('angular');
6-
var Api = require('./../src/service/Api');
7-
4+
var Api = require('../src/service/Api');
85
describe('Api', function() {
9-
10-
beforeEach(function() {
11-
var ngModule = angular.module('mockModule', []);
6+
var apiKey,
7+
config,
8+
sessionId = apiKey = '12345678';
129

13-
require('./../src/streamApiServiceProvider')(ngModule);
14-
});
15-
16-
beforeEach(angular.mock.module('mockModule'));
17-
18-
var streamApiService;
19-
2010
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+
};
9015
});
9116

9217
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);
9621
});
9722

9823
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();
10239
});
10340
});

‎spec/copy.spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('copy', function() {
2121

2222
var streamApi;
2323
beforeEach(function() {
24-
streamApi = streamApiService.getInstance({url: 'https://foo'});
24+
streamApi = streamApiService.getInstance({host: 'https://foo'});
2525
});
2626

2727
it('should throw an error when objCode is not provided', function() {

‎spec/count.spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('count', function() {
2121

2222
var streamApi;
2323
beforeEach(function() {
24-
streamApi = streamApiService.getInstance({url: 'https://foo'});
24+
streamApi = streamApiService.getInstance({host: 'https://foo'});
2525
});
2626

2727
it('should throw an exception when objCode doesn\'t orvided', function() {

‎spec/create.spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('create', function() {
2121

2222
var streamApi;
2323
beforeEach(function() {
24-
streamApi = streamApiService.getInstance({url: 'https://foo'});
24+
streamApi = streamApiService.getInstance({host: 'https://foo'});
2525
});
2626
it('should throw an error when objCode is not provided', function() {
2727
expect(function() {

‎spec/edit.spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('edit', function() {
2121

2222
var streamApi;
2323
beforeEach(function() {
24-
streamApi = streamApiService.getInstance({url: 'https://foo'});
24+
streamApi = streamApiService.getInstance({host: 'https://foo'});
2525
});
2626

2727
it('should make call to correct url', function() {

‎spec/execute.spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('execute', function() {
2121

2222
var streamApi;
2323
beforeEach(function() {
24-
streamApi = streamApiService.getInstance({url: 'https://foo'});
24+
streamApi = streamApiService.getInstance({host: 'https://foo'});
2525
});
2626

2727
it('should make call to correct url when passed ID', function() {

‎spec/get.spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('get', function() {
2121

2222
var streamApi;
2323
beforeEach(function() {
24-
streamApi = streamApiService.getInstance({url: 'https://foo'});
24+
streamApi = streamApiService.getInstance({host: 'https://foo'});
2525
});
2626

2727
it('should make call by correct url with array of object IDs', function() {

‎spec/getApiKey.spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('getApiKey', function() {
2121

2222
var streamApi;
2323
beforeEach(function() {
24-
streamApi = streamApiService.getInstance({url: 'https://foo'});
24+
streamApi = streamApiService.getInstance({host: 'https://foo'});
2525
});
2626

2727
it('should set correct apiKey in config headers on successful login', function(done) {

‎spec/login.spec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('login', function() {
2121

2222
var streamApi;
2323
beforeEach(function() {
24-
streamApi = streamApiService.getInstance({url: 'https://foo'});
24+
streamApi = streamApiService.getInstance({host: 'https://foo'});
2525
});
2626

2727
it('should make call to correct url', function() {

0 commit comments

Comments
 (0)