buildbot-data
Advanced tools
Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "buildbot-data", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"homepage": "https://github.com/tothandras/buildbot-data", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -92,3 +92,3 @@ (function() { | ||
BaseInstance.prototype.update = function(o) { | ||
return angular.extend(this, o); | ||
return angular.merge(this, o); | ||
}; | ||
@@ -485,2 +485,3 @@ | ||
var Data, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
slice = [].slice; | ||
@@ -501,21 +502,7 @@ | ||
function DataService() { | ||
this.socketCloseListener = bind(this.socketCloseListener, this); | ||
this.unsubscribeListener = bind(this.unsubscribeListener, this); | ||
self = this; | ||
socketService.eventStream.onUnsubscribe = this.unsubscribeListener; | ||
this.listeners = {}; | ||
socketService.socket.onclose = (function(_this) { | ||
return function() { | ||
var listenerIds, path, ref, results; | ||
ref = _this.listeners; | ||
results = []; | ||
for (path in ref) { | ||
listenerIds = ref[path]; | ||
if (listenerIds.length > 0) { | ||
results.push(_this.startConsuming(path)); | ||
} else { | ||
results.push(void 0); | ||
} | ||
} | ||
return results; | ||
}; | ||
})(this); | ||
socketService.socket.onclose = this.socketCloseListener; | ||
this.constructor.generateEndpoints(); | ||
@@ -534,3 +521,3 @@ } | ||
query = args.pop(); | ||
query.subscribe = null; | ||
delete query.subscribe; | ||
} | ||
@@ -571,2 +558,5 @@ updating = []; | ||
}); | ||
if (_this.listeners == null) { | ||
_this.listeners = {}; | ||
} | ||
if ((base = _this.listeners)[socketPath] == null) { | ||
@@ -631,12 +621,12 @@ base[socketPath] = []; | ||
DataService.prototype.unsubscribeListener = function(removed) { | ||
var i, k, ref, results, v; | ||
ref = self.listeners; | ||
var i, ids, path, ref, results; | ||
ref = this.listeners; | ||
results = []; | ||
for (k in ref) { | ||
v = ref[k]; | ||
i = v.indexOf(removed.id); | ||
if (i >= 0) { | ||
v.splice(i, 1); | ||
if (v.length === 0) { | ||
results.push(self.stopConsuming(k)); | ||
for (path in ref) { | ||
ids = ref[path]; | ||
i = ids.indexOf(removed.id); | ||
if (i > -1) { | ||
ids.splice(i, 1); | ||
if (ids.length === 0) { | ||
results.push(this.stopConsuming(path)); | ||
} else { | ||
@@ -652,2 +642,17 @@ results.push(void 0); | ||
DataService.prototype.socketCloseListener = function() { | ||
var ids, path, ref; | ||
if (this.listeners == null) { | ||
return; | ||
} | ||
ref = this.listeners; | ||
for (path in ref) { | ||
ids = ref[path]; | ||
if (ids.length > 0) { | ||
this.startConsuming(path); | ||
} | ||
} | ||
return null; | ||
}; | ||
DataService.prototype.control = function() {}; | ||
@@ -677,23 +682,20 @@ | ||
DataService.prototype.open = function() { | ||
var Group; | ||
return new (Group = (function() { | ||
var DataAccessor; | ||
return new (DataAccessor = (function() { | ||
var rootClasses; | ||
rootClasses = null; | ||
rootClasses = []; | ||
function Group() { | ||
this.rootClasses = []; | ||
rootClasses = this.rootClasses; | ||
function DataAccessor() { | ||
this.rootClasses = rootClasses; | ||
this.constructor.generateEndpoints(); | ||
} | ||
Group.prototype.close = function() { | ||
DataAccessor.prototype.close = function() { | ||
return this.rootClasses.forEach(function(c) { | ||
if (angular.isFunction(c.unsubscribe)) { | ||
return c.unsubscribe(); | ||
} | ||
return c.unsubscribe(); | ||
}); | ||
}; | ||
Group.prototype.closeOnDestroy = function(scope) { | ||
DataAccessor.prototype.closeOnDestroy = function(scope) { | ||
if (!angular.isFunction(scope.$on)) { | ||
@@ -709,3 +711,3 @@ throw new TypeError("Parameter 'scope' doesn't have an $on function"); | ||
Group.generateEndpoints = function() { | ||
DataAccessor.generateEndpoints = function() { | ||
return ENDPOINTS.forEach((function(_this) { | ||
@@ -730,3 +732,3 @@ return function(e) { | ||
return Group; | ||
return DataAccessor; | ||
@@ -751,12 +753,160 @@ })()); | ||
describe('Data service', function() { | ||
var dataService, injected; | ||
var $httpBackend, $q, $rootScope, ENDPOINTS, dataService, injected, restService, socketService; | ||
beforeEach(module('bbData')); | ||
dataService = null; | ||
dataService = restService = socketService = ENDPOINTS = $rootScope = $q = $httpBackend = null; | ||
injected = function($injector) { | ||
return dataService = $injector.get('dataService'); | ||
dataService = $injector.get('dataService'); | ||
restService = $injector.get('restService'); | ||
socketService = $injector.get('socketService'); | ||
ENDPOINTS = $injector.get('ENDPOINTS'); | ||
$rootScope = $injector.get('$rootScope'); | ||
$q = $injector.get('$q'); | ||
return $httpBackend = $injector.get('$httpBackend'); | ||
}; | ||
beforeEach(inject(injected)); | ||
return it('should be defined', function() { | ||
it('should be defined', function() { | ||
return expect(dataService).toBeDefined(); | ||
}); | ||
it('should have getXxx functions for endpoints', function() { | ||
var E, e, i, len, results; | ||
results = []; | ||
for (i = 0, len = ENDPOINTS.length; i < len; i++) { | ||
e = ENDPOINTS[i]; | ||
E = e[0].toUpperCase() + e.slice(1).toLowerCase(); | ||
expect(dataService["get" + E]).toBeDefined(); | ||
results.push(expect(angular.isFunction(dataService["get" + E])).toBeTruthy()); | ||
} | ||
return results; | ||
}); | ||
describe('get()', function() { | ||
it('should return a promise', function() { | ||
var p; | ||
p = dataService.getBuilds(); | ||
expect(angular.isFunction(p.then)).toBeTruthy(); | ||
return expect(angular.isFunction(p.getArray)).toBeTruthy(); | ||
}); | ||
it('should call get for the rest api endpoint', function() { | ||
var d; | ||
d = $q.defer(); | ||
spyOn(restService, 'get').and.returnValue(d.promise); | ||
expect(restService.get).not.toHaveBeenCalled(); | ||
$rootScope.$apply(function() { | ||
return dataService.get('asd', { | ||
subscribe: false | ||
}); | ||
}); | ||
return expect(restService.get).toHaveBeenCalledWith('asd', {}); | ||
}); | ||
it('should send startConsuming with the socket path', function() { | ||
var d; | ||
d = $q.defer(); | ||
spyOn(socketService, 'send').and.returnValue(d.promise); | ||
expect(socketService.send).not.toHaveBeenCalled(); | ||
$rootScope.$apply(function() { | ||
return dataService.get('asd'); | ||
}); | ||
expect(socketService.send).toHaveBeenCalledWith({ | ||
cmd: 'startConsuming', | ||
path: 'asd/*/*' | ||
}); | ||
$rootScope.$apply(function() { | ||
return dataService.get('asd', 1); | ||
}); | ||
return expect(socketService.send).toHaveBeenCalledWith({ | ||
cmd: 'startConsuming', | ||
path: 'asd/1/*' | ||
}); | ||
}); | ||
it('should not call startConsuming when {subscribe: false} is passed in', function() { | ||
var d; | ||
d = $q.defer(); | ||
spyOn(restService, 'get').and.returnValue(d.promise); | ||
spyOn(dataService, 'startConsuming'); | ||
expect(dataService.startConsuming).not.toHaveBeenCalled(); | ||
$rootScope.$apply(function() { | ||
return dataService.getBuilds({ | ||
subscribe: false | ||
}); | ||
}); | ||
return expect(dataService.startConsuming).not.toHaveBeenCalled(); | ||
}); | ||
return it('should add the new instance on /new WebSocket message', function() { | ||
var builds; | ||
spyOn(restService, 'get').and.returnValue($q.resolve({ | ||
builds: [] | ||
})); | ||
builds = null; | ||
$rootScope.$apply(function() { | ||
return builds = dataService.getBuilds({ | ||
subscribe: false | ||
}).getArray(); | ||
}); | ||
socketService.eventStream.push({ | ||
k: 'builds/111/new', | ||
m: { | ||
asd: 111 | ||
} | ||
}); | ||
return expect(builds.pop().asd).toBe(111); | ||
}); | ||
}); | ||
return describe('open()', function() { | ||
var opened; | ||
opened = null; | ||
beforeEach(function() { | ||
return opened = dataService.open(); | ||
}); | ||
it('should return a new accessor', function() { | ||
return expect(opened).toEqual(jasmine.any(Object)); | ||
}); | ||
it('should have getXxx functions for endpoints', function() { | ||
var E, e, i, len, results; | ||
results = []; | ||
for (i = 0, len = ENDPOINTS.length; i < len; i++) { | ||
e = ENDPOINTS[i]; | ||
E = e[0].toUpperCase() + e.slice(1).toLowerCase(); | ||
expect(opened["get" + E]).toBeDefined(); | ||
results.push(expect(angular.isFunction(opened["get" + E])).toBeTruthy()); | ||
} | ||
return results; | ||
}); | ||
it('should call unsubscribe on each root class on close', function() { | ||
var b, builds, i, j, k, len, len1, len2, p, results; | ||
p = $q.resolve({ | ||
builds: [{}, {}, {}] | ||
}); | ||
spyOn(restService, 'get').and.returnValue(p); | ||
builds = null; | ||
$rootScope.$apply(function() { | ||
return builds = opened.getBuilds({ | ||
subscribe: false | ||
}).getArray(); | ||
}); | ||
expect(builds.length).toBe(3); | ||
for (i = 0, len = builds.length; i < len; i++) { | ||
b = builds[i]; | ||
spyOn(b, 'unsubscribe'); | ||
} | ||
for (j = 0, len1 = builds.length; j < len1; j++) { | ||
b = builds[j]; | ||
expect(b.unsubscribe).not.toHaveBeenCalled(); | ||
} | ||
opened.close(); | ||
results = []; | ||
for (k = 0, len2 = builds.length; k < len2; k++) { | ||
b = builds[k]; | ||
results.push(expect(b.unsubscribe).toHaveBeenCalled()); | ||
} | ||
return results; | ||
}); | ||
return it('should call close when the $scope is destroyed', function() { | ||
var scope; | ||
spyOn(opened, 'close'); | ||
scope = $rootScope.$new(); | ||
opened.closeOnDestroy(scope); | ||
expect(opened.close).not.toHaveBeenCalled(); | ||
scope.$destroy(); | ||
return expect(opened.close).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
@@ -1229,12 +1379,8 @@ | ||
WebSocketBackend.prototype.flush = function() { | ||
return $rootScope.$apply((function(_this) { | ||
return function() { | ||
var message, results; | ||
results = []; | ||
while (message = _this.sendQueue.shift()) { | ||
results.push(_this.webSocket.onmessage(message)); | ||
} | ||
return results; | ||
}; | ||
})(this)); | ||
var message, results; | ||
results = []; | ||
while (message = this.sendQueue.shift()) { | ||
results.push(this.webSocket.onmessage(message)); | ||
} | ||
return results; | ||
}; | ||
@@ -1306,5 +1452,3 @@ | ||
expect(socket.send).not.toHaveBeenCalled(); | ||
socketService.send({ | ||
a: 1 | ||
}); | ||
socketService.send({}); | ||
expect(socket.send).toHaveBeenCalledWith(jasmine.any(String)); | ||
@@ -1331,3 +1475,5 @@ argument = socket.send.calls.argsFor(0)[0]; | ||
webSocketBackend.send(response); | ||
webSocketBackend.flush(); | ||
$rootScope.$apply(function() { | ||
return webSocketBackend.flush(); | ||
}); | ||
return expect(handler).toHaveBeenCalled(); | ||
@@ -1354,3 +1500,5 @@ }); | ||
webSocketBackend.send(response); | ||
webSocketBackend.flush(); | ||
$rootScope.$apply(function() { | ||
return webSocketBackend.flush(); | ||
}); | ||
expect(handler).not.toHaveBeenCalled(); | ||
@@ -1357,0 +1505,0 @@ return expect(errorHandler).toHaveBeenCalled(); |
@@ -1,1 +0,1 @@ | ||
(function(){var t;t=function(){function t(){return[]}return t}(),angular.module("bbData",new t)}).call(this),function(){var t;t=function(){function t(t){t.interceptors.push(function(t,e){return{request:function(n){return 0===n.url.indexOf(e)&&t.debug(n.method+" "+n.url),n}}})}return t}(),angular.module("bbData").config(["$httpProvider",t])}.call(this),function(){var t,e;t=function(){function t(){return"api/v2/"}return t}(),e=function(){function t(){return["builders","builds","buildrequests","buildslaves","buildsets","changes","changesources","masters","sourcestamps","schedulers","forceschedulers"]}return t}(),angular.module("bbData").constant("API",t()).constant("ENDPOINTS",e())}.call(this),function(){var t,e=[].slice;t=function(){function t(t,n,r){var o;return o=function(){function o(t,e,n){var o;if(this.endpoint=e,null==n&&(n=[]),!angular.isString(this.endpoint))throw new TypeError("Parameter 'endpoint' must be a string, not "+typeof this.endpoint);this.update(t),this.constructor.generateFunctions(n),o=r.classId(this.endpoint),this.id=this[o],this.subscribe()}return o.prototype.update=function(t){return angular.extend(this,t)},o.prototype.get=function(){var n;return n=1<=arguments.length?e.call(arguments,0):[],t.get.apply(t,[this.endpoint,this.id].concat(e.call(n)))},o.prototype.subscribe=function(){var t;return t=function(t){return function(e){var n,r,o;return n=e.k,r=e.m,o=RegExp("^"+t.endpoint+"\\/"+t.id+"\\/\\w+$","g"),o.test(n)?t.update(r):void 0}}(this),this.unsubscribeEventListener=n.eventStream.subscribe(t),this.listenerId=t.id},o.prototype.unsubscribe=function(){var t,e;for(t in this)e=this[t],angular.isArray(e)&&e.forEach(function(t){return t instanceof o?t.unsubscribe():void 0});return this.unsubscribeEventListener()},o.generateFunctions=function(t){return t.forEach(function(t){return function(n){var o;return o=r.capitalize(n),t.prototype["load"+o]=function(){var t,r;return t=1<=arguments.length?e.call(arguments,0):[],r=this.get.apply(this,[n].concat(e.call(t))),this[n]=r.getArray(),r}}}(this))},o}()}return t}(),angular.module("bbData").factory("Base",["dataService","socketService","dataUtilsService",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){var r;r=["changes","properties","steps"],n.__super__.constructor.call(this,t,e,r)}return e(n,t),n}(t)}return t}(),angular.module("bbData").factory("Build",["Base","dataService",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){var r;r=["builds","buildrequests","forceschedulers","buildslaves","masters"],n.__super__.constructor.call(this,t,e,r)}return e(n,t),n}(t)}return t}(),angular.module("bbData").factory("Builder",["Base","dataService",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){var r;r=["builds"],n.__super__.constructor.call(this,t,e,r)}return e(n,t),n}(t)}return t}(),angular.module("bbData").factory("Buildrequest",["Base","dataService",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){var r;r=["properties"],n.__super__.constructor.call(this,t,e,r)}return e(n,t),n}(t)}return t}(),angular.module("bbData").factory("Buildset",["Base","dataService",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){n.__super__.constructor.call(this,t,e)}return e(n,t),n}(t)}return t}(),angular.module("bbData").factory("Buildslave",["Base","dataService",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){n.__super__.constructor.call(this,t,e)}return e(n,t),n}(t)}return t}(),angular.module("bbData").factory("Change",["Base","dataService",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){n.__super__.constructor.call(this,t,e)}return e(n,t),n}(n)}return t}(),angular.module("bbData").factory("Changesource",["dataService","Base",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){n.__super__.constructor.call(this,t,e)}return e(n,t),n}(t)}return t}(),angular.module("bbData").factory("Forcescheduler",["Base","dataService",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){var r;r=["builders","buildslaves","changesources","schedulers"],n.__super__.constructor.call(this,t,e,r)}return e(n,t),n}(t)}return t}(),angular.module("bbData").factory("Master",["Base","dataService",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){n.__super__.constructor.call(this,t,e)}return e(n,t),n}(t)}return t}(),angular.module("bbData").factory("Scheduler",["Base","dataService",t])}.call(this),function(){var t,e=function(t,e){function r(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n={}.hasOwnProperty;t=function(){function t(t,n){var r;return r=function(t){function n(t,e){var r;r=["changes"],n.__super__.constructor.call(this,t,e,r)}return e(n,t),n}(t)}return t}(),angular.module("bbData").factory("Sourcestamp",["Base","dataService",t])}.call(this),function(){var t,e=[].slice;t=function(){function t(){}return t.prototype.cache=!1,t.prototype.$get=function(t,n,r,o,u,i,s){var c;return new(c=function(){function c(){a=this,u.eventStream.onUnsubscribe=this.unsubscribeListener,this.listeners={},u.socket.onclose=function(t){return function(){var e,n,r,o;r=t.listeners,o=[];for(n in r)e=r[n],o.push(e.length>0?t.startConsuming(n):void 0);return o}}(this),this.constructor.generateEndpoints()}var a;return a=null,c.prototype.get=function(){var s,c,a,l,p,f;return s=1<=arguments.length?e.call(arguments,0):[],s=s.filter(function(t){return null!=t}),c=s[s.length-1],p=c.subscribe||null==c.subscribe,angular.isObject(c)&&(l=s.pop(),l.subscribe=null),f=[],a=r(function(e){return function(c,a){var d,h,b,v;return p?(d=[],v=u.eventStream.subscribe(function(t){return d.push(t)}),h=i.socketPath(s),b=e.startConsuming(h)):b=r.resolve(),b.then(function(){var r,b;return r=i.restPath(s),b=o.get(r,l),b.then(function(o){var l,b,y,g,m,_;_=i.type(r),o=o[_];try{y=i.className(r),l=n.get(y)}catch(S){g=S,l=n.get("Base")}return angular.isArray(o)?(m=i.endpointPath(s),o=o.map(function(t){return new l(t,m)}),null==(b=e.listeners)[h]&&(b[h]=[]),o.forEach(function(t){return e.listeners[h].push(t.listenerId)}),u.eventStream.subscribe(function(t){var n,r,o,u;return n=t.k,r=t.m,u=RegExp("^"+m+"\\/(\\w+|\\d+)\\/new$","g"),u.test(n)?(o=new l(r,m),f.push(o),e.listeners[h].push(o.listenerId)):void 0}),p&&(d.forEach(function(t){return u.eventStream.push(t)}),v()),angular.copy(o,f),c(f)):(g=o+" is not an array",t.error(g),a(g))},function(t){return a(t)})},function(t){return a(t)})}}(this)),a.getArray=function(){return f},a},c.prototype.startConsuming=function(t){return u.send({cmd:"startConsuming",path:t})},c.prototype.stopConsuming=function(t){return u.send({cmd:"stopConsuming",path:t})},c.prototype.unsubscribeListener=function(t){var e,n,r,o,u;r=a.listeners,o=[];for(n in r)u=r[n],e=u.indexOf(t.id),e>=0?(u.splice(e,1),o.push(0===u.length?a.stopConsuming(n):void 0)):o.push(void 0);return o},c.prototype.control=function(){},c.prototype.getNextId=function(){return null==this.jsonrpc&&(this.jsonrpc=0),this.jsonrpc++},c.generateEndpoints=function(){return s.forEach(function(t){return function(n){var r;return r=i.capitalize(n),t.prototype["get"+r]=function(){var t;return t=1<=arguments.length?e.call(arguments,0):[],a.get.apply(a,[n].concat(e.call(t)))}}}(this))},c.prototype.open=function(){var t;return new(t=function(){function t(){this.rootClasses=[],n=this.rootClasses,this.constructor.generateEndpoints()}var n;return n=null,t.prototype.close=function(){return this.rootClasses.forEach(function(t){return angular.isFunction(t.unsubscribe)?t.unsubscribe():void 0})},t.prototype.closeOnDestroy=function(t){if(!angular.isFunction(t.$on))throw new TypeError("Parameter 'scope' doesn't have an $on function");return t.$on("$destroy",function(t){return function(){return t.close()}}(this))},t.generateEndpoints=function(){return s.forEach(function(t){return function(r){var o;return o=i.capitalize(r),t.prototype["get"+o]=function(){var t,r;return t=1<=arguments.length?e.call(arguments,0):[],r=a["get"+o].apply(a,t),r.then(function(t){return t.forEach(function(t){return n.push(t)})}),r}}}(this))},t}())},c}())},t}(),angular.module("bbData").provider("dataProvider",[t])}.call(this),function(){describe("Data service",function(){var t,e;return beforeEach(module("bbData")),t=null,e=function(e){return t=e.get("dataService")},beforeEach(inject(e)),it("should be defined",function(){return expect(t).toBeDefined()})})}.call(this),function(){var t;t=function(){function t(){return new(t=function(){function t(){}return t.prototype.capitalize=function(t){return t[0].toUpperCase()+t.slice(1).toLowerCase()},t.prototype.type=function(t){var e,n,r;for(r=t.split("/");;)if(e=r.pop(),n=parseInt(e),0===r.length||!angular.isNumber(n)||isNaN(n))break;return e},t.prototype.singularType=function(t){return this.type(t).replace(/s$/,"")},t.prototype.classId=function(t){return this.singularType(t)+"id"},t.prototype.className=function(t){return this.capitalize(this.singularType(t))},t.prototype.socketPath=function(t){var e;return e=["*"],t.length%2===1&&e.push("*"),t.concat(e).join("/")},t.prototype.restPath=function(t){return t.slice().join("/")},t.prototype.endpointPath=function(t){var e;return e=t.slice(),e.length%2===0&&e.pop(),e.join("/")},t}())}return t}(),angular.module("bbData").service("dataUtilsService",[t])}.call(this),function(){describe("Helper service",function(){var t,e;return beforeEach(module("bbData")),t=null,e=function(e){return t=e.get("dataUtilsService")},beforeEach(inject(e)),it("should be defined",function(){return expect(t).toBeDefined()}),it("should capitalize the first word",function(){return expect(t.capitalize("abc")).toBe("Abc"),expect(t.capitalize("abc cba")).toBe("Abc cba")}),it("should return the endpoint name for rest endpoints",function(){var e,n,r,o;r={"builders/100/forceschedulers":"forcescheduler","builders/1/builds":"build","builders/2/builds/1":"build"},n=[];for(e in r)o=r[e],n.push(expect(t.singularType(e)).toBe(o));return n}),it("should return the class name for rest endpoints",function(){var e,n,r,o;r={"builders/100/forceschedulers":"Forcescheduler","builders/1/builds":"Build","builders/2/builds/1":"Build"},n=[];for(e in r)o=r[e],n.push(expect(t.className(e)).toBe(o));return n}),it("should return the WebSocket path for an endpoint",function(){var e,n,r,o;r={"builders/100/forceschedulers/*/*":["builders",100,"forceschedulers"],"builders/1/builds/*/*":["builders",1,"builds"],"builders/2/builds/1/*":["builders",2,"builds",1]},n=[];for(e in r)o=r[e],n.push(expect(t.socketPath(o)).toBe(e));return n}),it("should return the path for an endpoint",function(){var e,n,r,o;r={"builders/100/forceschedulers":["builders",100,"forceschedulers"],"builders/1/builds":["builders",1,"builds"],"builders/2/builds":["builders",2,"builds",1]},n=[];for(e in r)o=r[e],n.push(expect(t.endpointPath(o)).toBe(e));return n})})}.call(this),function(){var t,e=[].slice;t=function(){function t(t,n,r){var o;return new(o=function(){function o(){}return o.prototype.execute=function(e){return n(function(n){return function(n,r){return t(e).success(function(t){var e,o;try{return e=angular.fromJson(t),n(e)}catch(u){return o=u,r(o)}}).error(function(t){return r(t)})}}(this))},o.prototype.get=function(t,e){var n;return null==e&&(e={}),n={method:"GET",url:this.parse(r,t),params:e,headers:{Accept:"application/json"}},this.execute(n)},o.prototype.post=function(t,e){var n;return null==e&&(e={}),n={method:"POST",url:this.parse(r,t),data:e,headers:{"Content-Type":"application/json"}},this.execute(n)},o.prototype.parse=function(){var t;return t=1<=arguments.length?e.call(arguments,0):[],t.join("/").replace(/\/\//,"/")},o}())}return t}(),angular.module("bbData").service("restService",["$http","$q","API",t])}.call(this),function(){describe("Rest service",function(){var t,e,n;return beforeEach(module("bbData")),beforeEach(function(){return module(function(t){return t.constant("API","/api/")})}),n=t=null,e=function(e){return n=e.get("restService"),t=e.get("$httpBackend")},beforeEach(inject(e)),afterEach(function(){return t.verifyNoOutstandingExpectation(),t.verifyNoOutstandingRequest()}),it("should be defined",function(){return expect(n).toBeDefined()}),it("should make an ajax GET call to /api/endpoint",function(){var e,r;return r={a:"A"},t.whenGET("/api/endpoint").respond(r),e=null,n.get("endpoint").then(function(t){return e=t}),expect(e).toBeNull(),t.flush(),expect(e).toEqual(r)}),it("should make an ajax GET call to /api/endpoint with parameters",function(){var e;return e={key:"value"},t.whenGET("/api/endpoint?key=value").respond(200),n.get("endpoint",e),t.flush()}),it("should reject the promise on error",function(){var e,r;return e="Internal server error",t.expectGET("/api/endpoint").respond(500,e),r=null,n.get("endpoint").then(function(t){return r=t},function(t){return r=t}),t.flush(),expect(r).toBe(e)}),it("should make an ajax POST call to /api/endpoint",function(){var e,r,o;return o={},e={b:"B"},t.expectPOST("/api/endpoint",e).respond(o),r=null,n.post("endpoint",e).then(function(t){return r=t}),t.flush(),expect(r).toEqual(o)}),it("should reject the promise when the response is not valid JSON",function(){var e,r,o;return o="aaa",e={b:"B"},t.expectPOST("/api/endpoint",e).respond(o),r=null,n.post("endpoint",e).then(function(t){return r=t},function(t){return r=t}),t.flush(),expect(r).not.toBeNull(),expect(r).not.toEqual(o)})})}.call(this),function(){var t;t=function(){function t(t,e,n,r,o,u){var i;return new(i=function(){function i(){this.queue=[],this.deferred={},this.open()}return i.prototype.eventStream=null,i.prototype.open=function(){return null==this.socket&&(this.socket=u.getWebSocket(this.getUrl())),this.socket.onopen=function(t){return function(){return t.flush()}}(this),this.setupEventStream()},i.prototype.setupEventStream=function(){return null==this.eventStream&&(this.eventStream=new o),this.socket.onmessage=function(e){return function(r){var o,u,i,s,c,a;try{return o=angular.fromJson(r.data),t.debug("WS message",o),null!=o.code?(i=o._id,200===o.code?null!=(s=e.deferred[i])?s.resolve(!0):void 0:null!=(c=e.deferred[i])?c.reject(o):void 0):n.$applyAsync(function(){return e.eventStream.push(o)})}catch(l){return u=l,null!=(a=e.deferred[i])?a.reject(u):void 0}}}(this)},i.prototype.close=function(){return this.socket.close()},i.prototype.send=function(n){var r,o;return o=this.nextId(),n._id=o,null==(r=this.deferred)[o]&&(r[o]=e.defer()),n=angular.toJson(n),this.socket.readyState===(this.socket.OPEN||1)?(t.debug("WS send",angular.fromJson(n)),this.socket.send(n)):this.queue.push(n),this.deferred[o].promise},i.prototype.flush=function(){var e,n;for(n=[];e=this.queue.pop();)t.debug("WS send",angular.fromJson(e)),n.push(this.socket.send(e));return n},i.prototype.nextId=function(){return null==this.id&&(this.id=0),this.id=this.id<1e3?this.id+1:0,this.id},i.prototype.getUrl=function(){var t,e;return t=r.host(),e=80===r.port()?"":":"+r.port(),"ws://"+t+e+"/ws"},i}())}return t}(),angular.module("bbData").service("socketService",["$log","$q","$rootScope","$location","Stream","webSocketService",t])}.call(this),function(){describe("Socket service",function(){var t,e,n,r,o,u;return e=function(){function e(){r=this,this.webSocket=new n}var n,r;return e.prototype.sendQueue=[],e.prototype.receiveQueue=[],r=null,e.prototype.send=function(t){var e;return e={data:t},this.sendQueue.push(e)},e.prototype.flush=function(){return t.$apply(function(t){return function(){var e,n;for(n=[];e=t.sendQueue.shift();)n.push(t.webSocket.onmessage(e));return n}}(this))},e.prototype.getWebSocket=function(){return this.webSocket},n=function(){function t(){}return t.prototype.OPEN=1,t.prototype.send=function(t){return r.receiveQueue.push(t)},t}(),e}(),u=new e,beforeEach(function(){return module("bbData"),module(function(t){return t.constant("webSocketService",u)})}),t=o=r=null,n=function(e){return t=e.get("$rootScope"),o=e.get("socketService"),r=o.socket,spyOn(r,"send").and.callThrough(),spyOn(r,"onmessage").and.callThrough()},beforeEach(inject(n)),it("should be defined",function(){return expect(o).toBeDefined()}),it("should send the data, when the WebSocket is open",function(){var t,e,n;return r.readyState=0,t={a:1},e={b:2},n={c:3},o.send(t),o.send(e),expect(r.send).not.toHaveBeenCalled(),r.onopen(),expect(r.send).toHaveBeenCalled(),expect(u.receiveQueue).toContain(angular.toJson(t)),expect(u.receiveQueue).toContain(angular.toJson(e)),expect(u.receiveQueue).not.toContain(angular.toJson(n))}),it("should add an _id to each message",function(){var t;return r.readyState=1,expect(r.send).not.toHaveBeenCalled(),o.send({a:1}),expect(r.send).toHaveBeenCalledWith(jasmine.any(String)),t=r.send.calls.argsFor(0)[0],expect(angular.fromJson(t)._id).toBeDefined()}),it("should resolve the promise when a response message is received with code 200",function(){var t,e,n,i,s,c;return r.readyState=1,i={cmd:"command"},s=o.send(i),e=jasmine.createSpy("handler"),s.then(e),expect(e).not.toHaveBeenCalled(),t=r.send.calls.argsFor(0)[0],n=angular.fromJson(t)._id,c=angular.toJson({_id:n,code:200}),u.send(c),u.flush(),expect(e).toHaveBeenCalled()}),it("should reject the promise when a response message is received, but the code is not 200",function(){var t,e,n,i,s,c,a;return r.readyState=1,s={cmd:"command"},c=o.send(s),n=jasmine.createSpy("handler"),e=jasmine.createSpy("errorHandler"),c.then(n,e),expect(n).not.toHaveBeenCalled(),expect(e).not.toHaveBeenCalled(),t=r.send.calls.argsFor(0)[0],i=angular.fromJson(t)._id,a=angular.toJson({_id:i,code:500}),u.send(a),u.flush(),expect(n).not.toHaveBeenCalled(),expect(e).toHaveBeenCalled()})})}.call(this),function(){var t;t=function(){function t(t){var e;return new(e=function(){function e(){}return e.prototype.getWebSocket=function(e){var n;if(n=/wss?:\/\//.exec(e),!n)throw new Error("Invalid url provided");return null!=t.ReconnectingWebSocket?new t.ReconnectingWebSocket(e):new t.WebSocket(e)},e}())}return t}(),angular.module("bbData").service("webSocketService",["$window",t])}.call(this),function(){var t;t=function(){function t(){var t;return t=function(){function t(){}return t.prototype.onUnsubscribe=null,t.prototype.listeners=[],t.prototype.subscribe=function(t){if(!angular.isFunction(t))throw new TypeError("Parameter 'listener' must be a function, not "+typeof t);return t.id=this.generateId(),this.listeners.push(t),function(e){return function(){var n,r;return n=e.listeners.indexOf(t),r=e.listeners.splice(n,1),angular.isFunction(e.onUnsubscribe)?e.onUnsubscribe(t):void 0}}(this)},t.prototype.push=function(t){var e,n,r,o,u;for(o=this.listeners,u=[],e=0,n=o.length;n>e;e++)r=o[e],u.push(r(t));return u},t.prototype.destroy=function(){var t;for(t=[];this.listeners.length>0;)t.push(this.listeners.pop());return t},t.prototype.generateId=function(){return null==this.lastId&&(this.lastId=0),this.lastId++},t}()}return t}(),angular.module("bbData").factory("Stream",[t])}.call(this),function(){describe("Stream service",function(){var t,e,n;return beforeEach(module("bbData")),t=n=null,e=function(e){return t=e.get("Stream"),n=new t},beforeEach(inject(e)),it("should be defined",function(){return expect(t).toBeDefined(),expect(n).toBeDefined()}),it("should add the listener to listeners on subscribe call",function(){var t;return t=n.listeners,expect(t.length).toBe(0),n.subscribe(function(){}),expect(t.length).toBe(1)}),it("should add a unique id to each listener passed in to subscribe",function(){var t,e,r;return r=n.listeners,t=function(){},e=function(){},n.subscribe(t),n.subscribe(e),expect(t.id).toBeDefined(),expect(e.id).toBeDefined(),expect(t.id).not.toBe(e.id)}),it("should return the unsubscribe function on subscribe call",function(){var t,e,r,o;return e=n.listeners,t=function(){},r=function(){},o=n.subscribe(t),n.subscribe(r),expect(e).toContain(t),o(),expect(e).not.toContain(t),expect(e).toContain(r)}),it("should call all listeners on push call",function(){var t,e;return t={a:"A",b:"B"},e={first:function(t){return expect(t).toEqual({a:"A",b:"B"})},second:function(t){return expect(t).toEqual({a:"A",b:"B"})}},spyOn(e,"first").and.callThrough(),spyOn(e,"second").and.callThrough(),n.subscribe(e.first),n.subscribe(e.second),expect(e.first).not.toHaveBeenCalled(),expect(e.second).not.toHaveBeenCalled(),n.push(t),expect(e.first).toHaveBeenCalled(),expect(e.second).toHaveBeenCalled()}),it("should remove all listeners on destroy call",function(){var t;return t=n.listeners,expect(t.length).toBe(0),n.subscribe(function(){}),n.subscribe(function(){}),expect(t.length).not.toBe(0),n.destroy(),expect(t.length).toBe(0)}),it("should call the unsubscribe listener on unsubscribe call",function(){var t,e;return spyOn(n,"onUnsubscribe"),t=function(){},e=n.subscribe(t),expect(n.onUnsubscribe).not.toHaveBeenCalled(),e(),expect(n.onUnsubscribe).toHaveBeenCalledWith(t)})})}.call(this); | ||
(function(){var e;e=function(){function e(){return[]}return e}(),angular.module("bbData",new e)}).call(this),function(){var e;e=function(){function e(e){e.interceptors.push(function(e,t){return{request:function(n){return 0===n.url.indexOf(t)&&e.debug(n.method+" "+n.url),n}}})}return e}(),angular.module("bbData").config(["$httpProvider",e])}.call(this),function(){var e,t;e=function(){function e(){return"api/v2/"}return e}(),t=function(){function e(){return["builders","builds","buildrequests","buildslaves","buildsets","changes","changesources","masters","sourcestamps","schedulers","forceschedulers"]}return e}(),angular.module("bbData").constant("API",e()).constant("ENDPOINTS",t())}.call(this),function(){var e,t=[].slice;e=function(){function e(e,n,r){var o;return o=function(){function o(e,t,n){var o;if(this.endpoint=t,null==n&&(n=[]),!angular.isString(this.endpoint))throw new TypeError("Parameter 'endpoint' must be a string, not "+typeof this.endpoint);this.update(e),this.constructor.generateFunctions(n),o=r.classId(this.endpoint),this.id=this[o],this.subscribe()}return o.prototype.update=function(e){return angular.merge(this,e)},o.prototype.get=function(){var n;return n=1<=arguments.length?t.call(arguments,0):[],e.get.apply(e,[this.endpoint,this.id].concat(t.call(n)))},o.prototype.subscribe=function(){var e;return e=function(e){return function(t){var n,r,o;return n=t.k,r=t.m,o=RegExp("^"+e.endpoint+"\\/"+e.id+"\\/\\w+$","g"),o.test(n)?e.update(r):void 0}}(this),this.unsubscribeEventListener=n.eventStream.subscribe(e),this.listenerId=e.id},o.prototype.unsubscribe=function(){var e,t;for(e in this)t=this[e],angular.isArray(t)&&t.forEach(function(e){return e instanceof o?e.unsubscribe():void 0});return this.unsubscribeEventListener()},o.generateFunctions=function(e){return e.forEach(function(e){return function(n){var o;return o=r.capitalize(n),e.prototype["load"+o]=function(){var e,r;return e=1<=arguments.length?t.call(arguments,0):[],r=this.get.apply(this,[n].concat(t.call(e))),this[n]=r.getArray(),r}}}(this))},o}()}return e}(),angular.module("bbData").factory("Base",["dataService","socketService","dataUtilsService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["changes","properties","steps"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Build",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["builds","buildrequests","forceschedulers","buildslaves","masters"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Builder",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["builds"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Buildrequest",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["properties"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Buildset",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){n.__super__.constructor.call(this,e,t)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Buildslave",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){n.__super__.constructor.call(this,e,t)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Change",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){n.__super__.constructor.call(this,e,t)}return t(n,e),n}(n)}return e}(),angular.module("bbData").factory("Changesource",["dataService","Base",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){n.__super__.constructor.call(this,e,t)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Forcescheduler",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["builders","buildslaves","changesources","schedulers"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Master",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){n.__super__.constructor.call(this,e,t)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Scheduler",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){function r(){this.constructor=e}for(var o in t)n.call(t,o)&&(e[o]=t[o]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},n={}.hasOwnProperty;e=function(){function e(e,n){var r;return r=function(e){function n(e,t){var r;r=["changes"],n.__super__.constructor.call(this,e,t,r)}return t(n,e),n}(e)}return e}(),angular.module("bbData").factory("Sourcestamp",["Base","dataService",e])}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}},n=[].slice;e=function(){function e(){}return e.prototype.cache=!1,e.prototype.$get=function(e,r,o,u,i,s,c){var a;return new(a=function(){function a(){this.socketCloseListener=t(this.socketCloseListener,this),this.unsubscribeListener=t(this.unsubscribeListener,this),l=this,i.eventStream.onUnsubscribe=this.unsubscribeListener,i.socket.onclose=this.socketCloseListener,this.constructor.generateEndpoints()}var l;return l=null,a.prototype.get=function(){var t,c,a,l,p,f;return t=1<=arguments.length?n.call(arguments,0):[],t=t.filter(function(e){return null!=e}),c=t[t.length-1],p=c.subscribe||null==c.subscribe,angular.isObject(c)&&(l=t.pop(),delete l.subscribe),f=[],a=o(function(n){return function(c,a){var d,h,b,v;return p?(d=[],v=i.eventStream.subscribe(function(e){return d.push(e)}),h=s.socketPath(t),b=n.startConsuming(h)):b=o.resolve(),b.then(function(){var o,b;return o=s.restPath(t),b=u.get(o,l),b.then(function(u){var l,b,g,y,m,_;_=s.type(o),u=u[_];try{g=s.className(o),l=r.get(g)}catch(x){y=x,l=r.get("Base")}return angular.isArray(u)?(m=s.endpointPath(t),u=u.map(function(e){return new l(e,m)}),null==n.listeners&&(n.listeners={}),null==(b=n.listeners)[h]&&(b[h]=[]),u.forEach(function(e){return n.listeners[h].push(e.listenerId)}),i.eventStream.subscribe(function(e){var t,r,o,u;return t=e.k,r=e.m,u=RegExp("^"+m+"\\/(\\w+|\\d+)\\/new$","g"),u.test(t)?(o=new l(r,m),f.push(o),n.listeners[h].push(o.listenerId)):void 0}),p&&(d.forEach(function(e){return i.eventStream.push(e)}),v()),angular.copy(u,f),c(f)):(y=u+" is not an array",e.error(y),a(y))},function(e){return a(e)})},function(e){return a(e)})}}(this)),a.getArray=function(){return f},a},a.prototype.startConsuming=function(e){return i.send({cmd:"startConsuming",path:e})},a.prototype.stopConsuming=function(e){return i.send({cmd:"stopConsuming",path:e})},a.prototype.unsubscribeListener=function(e){var t,n,r,o,u;o=this.listeners,u=[];for(r in o)n=o[r],t=n.indexOf(e.id),t>-1?(n.splice(t,1),u.push(0===n.length?this.stopConsuming(r):void 0)):u.push(void 0);return u},a.prototype.socketCloseListener=function(){var e,t,n;if(null!=this.listeners){n=this.listeners;for(t in n)e=n[t],e.length>0&&this.startConsuming(t);return null}},a.prototype.control=function(){},a.prototype.getNextId=function(){return null==this.jsonrpc&&(this.jsonrpc=0),this.jsonrpc++},a.generateEndpoints=function(){return c.forEach(function(e){return function(t){var r;return r=s.capitalize(t),e.prototype["get"+r]=function(){var e;return e=1<=arguments.length?n.call(arguments,0):[],l.get.apply(l,[t].concat(n.call(e)))}}}(this))},a.prototype.open=function(){var e;return new(e=function(){function e(){this.rootClasses=t,this.constructor.generateEndpoints()}var t;return t=[],e.prototype.close=function(){return this.rootClasses.forEach(function(e){return e.unsubscribe()})},e.prototype.closeOnDestroy=function(e){if(!angular.isFunction(e.$on))throw new TypeError("Parameter 'scope' doesn't have an $on function");return e.$on("$destroy",function(e){return function(){return e.close()}}(this))},e.generateEndpoints=function(){return c.forEach(function(e){return function(r){var o;return o=s.capitalize(r),e.prototype["get"+o]=function(){var e,r;return e=1<=arguments.length?n.call(arguments,0):[],r=l["get"+o].apply(l,e),r.then(function(e){return e.forEach(function(e){return t.push(e)})}),r}}}(this))},e}())},a}())},e}(),angular.module("bbData").provider("dataProvider",[e])}.call(this),function(){describe("Data service",function(){var e,t,n,r,o,u,i,s;return beforeEach(module("bbData")),o=i=s=r=n=t=e=null,u=function(u){return o=u.get("dataService"),i=u.get("restService"),s=u.get("socketService"),r=u.get("ENDPOINTS"),n=u.get("$rootScope"),t=u.get("$q"),e=u.get("$httpBackend")},beforeEach(inject(u)),it("should be defined",function(){return expect(o).toBeDefined()}),it("should have getXxx functions for endpoints",function(){var e,t,n,u,i;for(i=[],n=0,u=r.length;u>n;n++)t=r[n],e=t[0].toUpperCase()+t.slice(1).toLowerCase(),expect(o["get"+e]).toBeDefined(),i.push(expect(angular.isFunction(o["get"+e])).toBeTruthy());return i}),describe("get()",function(){return it("should return a promise",function(){var e;return e=o.getBuilds(),expect(angular.isFunction(e.then)).toBeTruthy(),expect(angular.isFunction(e.getArray)).toBeTruthy()}),it("should call get for the rest api endpoint",function(){var e;return e=t.defer(),spyOn(i,"get").and.returnValue(e.promise),expect(i.get).not.toHaveBeenCalled(),n.$apply(function(){return o.get("asd",{subscribe:!1})}),expect(i.get).toHaveBeenCalledWith("asd",{})}),it("should send startConsuming with the socket path",function(){var e;return e=t.defer(),spyOn(s,"send").and.returnValue(e.promise),expect(s.send).not.toHaveBeenCalled(),n.$apply(function(){return o.get("asd")}),expect(s.send).toHaveBeenCalledWith({cmd:"startConsuming",path:"asd/*/*"}),n.$apply(function(){return o.get("asd",1)}),expect(s.send).toHaveBeenCalledWith({cmd:"startConsuming",path:"asd/1/*"})}),it("should not call startConsuming when {subscribe: false} is passed in",function(){var e;return e=t.defer(),spyOn(i,"get").and.returnValue(e.promise),spyOn(o,"startConsuming"),expect(o.startConsuming).not.toHaveBeenCalled(),n.$apply(function(){return o.getBuilds({subscribe:!1})}),expect(o.startConsuming).not.toHaveBeenCalled()}),it("should add the new instance on /new WebSocket message",function(){var e;return spyOn(i,"get").and.returnValue(t.resolve({builds:[]})),e=null,n.$apply(function(){return e=o.getBuilds({subscribe:!1}).getArray()}),s.eventStream.push({k:"builds/111/new",m:{asd:111}}),expect(e.pop().asd).toBe(111)})}),describe("open()",function(){var e;return e=null,beforeEach(function(){return e=o.open()}),it("should return a new accessor",function(){return expect(e).toEqual(jasmine.any(Object))}),it("should have getXxx functions for endpoints",function(){var t,n,o,u,i;for(i=[],o=0,u=r.length;u>o;o++)n=r[o],t=n[0].toUpperCase()+n.slice(1).toLowerCase(),expect(e["get"+t]).toBeDefined(),i.push(expect(angular.isFunction(e["get"+t])).toBeTruthy());return i}),it("should call unsubscribe on each root class on close",function(){var r,o,u,s,c,a,l,p,f,d;for(f=t.resolve({builds:[{},{},{}]}),spyOn(i,"get").and.returnValue(f),o=null,n.$apply(function(){return o=e.getBuilds({subscribe:!1}).getArray()}),expect(o.length).toBe(3),u=0,a=o.length;a>u;u++)r=o[u],spyOn(r,"unsubscribe");for(s=0,l=o.length;l>s;s++)r=o[s],expect(r.unsubscribe).not.toHaveBeenCalled();for(e.close(),d=[],c=0,p=o.length;p>c;c++)r=o[c],d.push(expect(r.unsubscribe).toHaveBeenCalled());return d}),it("should call close when the $scope is destroyed",function(){var t;return spyOn(e,"close"),t=n.$new(),e.closeOnDestroy(t),expect(e.close).not.toHaveBeenCalled(),t.$destroy(),expect(e.close).toHaveBeenCalled()})})})}.call(this),function(){var e;e=function(){function e(){return new(e=function(){function e(){}return e.prototype.capitalize=function(e){return e[0].toUpperCase()+e.slice(1).toLowerCase()},e.prototype.type=function(e){var t,n,r;for(r=e.split("/");;)if(t=r.pop(),n=parseInt(t),0===r.length||!angular.isNumber(n)||isNaN(n))break;return t},e.prototype.singularType=function(e){return this.type(e).replace(/s$/,"")},e.prototype.classId=function(e){return this.singularType(e)+"id"},e.prototype.className=function(e){return this.capitalize(this.singularType(e))},e.prototype.socketPath=function(e){var t;return t=["*"],e.length%2===1&&t.push("*"),e.concat(t).join("/")},e.prototype.restPath=function(e){return e.slice().join("/")},e.prototype.endpointPath=function(e){var t;return t=e.slice(),t.length%2===0&&t.pop(),t.join("/")},e}())}return e}(),angular.module("bbData").service("dataUtilsService",[e])}.call(this),function(){describe("Helper service",function(){var e,t;return beforeEach(module("bbData")),e=null,t=function(t){return e=t.get("dataUtilsService")},beforeEach(inject(t)),it("should be defined",function(){return expect(e).toBeDefined()}),it("should capitalize the first word",function(){return expect(e.capitalize("abc")).toBe("Abc"),expect(e.capitalize("abc cba")).toBe("Abc cba")}),it("should return the endpoint name for rest endpoints",function(){var t,n,r,o;r={"builders/100/forceschedulers":"forcescheduler","builders/1/builds":"build","builders/2/builds/1":"build"},n=[];for(t in r)o=r[t],n.push(expect(e.singularType(t)).toBe(o));return n}),it("should return the class name for rest endpoints",function(){var t,n,r,o;r={"builders/100/forceschedulers":"Forcescheduler","builders/1/builds":"Build","builders/2/builds/1":"Build"},n=[];for(t in r)o=r[t],n.push(expect(e.className(t)).toBe(o));return n}),it("should return the WebSocket path for an endpoint",function(){var t,n,r,o;r={"builders/100/forceschedulers/*/*":["builders",100,"forceschedulers"],"builders/1/builds/*/*":["builders",1,"builds"],"builders/2/builds/1/*":["builders",2,"builds",1]},n=[];for(t in r)o=r[t],n.push(expect(e.socketPath(o)).toBe(t));return n}),it("should return the path for an endpoint",function(){var t,n,r,o;r={"builders/100/forceschedulers":["builders",100,"forceschedulers"],"builders/1/builds":["builders",1,"builds"],"builders/2/builds":["builders",2,"builds",1]},n=[];for(t in r)o=r[t],n.push(expect(e.endpointPath(o)).toBe(t));return n})})}.call(this),function(){var e,t=[].slice;e=function(){function e(e,n,r){var o;return new(o=function(){function o(){}return o.prototype.execute=function(t){return n(function(n){return function(n,r){return e(t).success(function(e){var t,o;try{return t=angular.fromJson(e),n(t)}catch(u){return o=u,r(o)}}).error(function(e){return r(e)})}}(this))},o.prototype.get=function(e,t){var n;return null==t&&(t={}),n={method:"GET",url:this.parse(r,e),params:t,headers:{Accept:"application/json"}},this.execute(n)},o.prototype.post=function(e,t){var n;return null==t&&(t={}),n={method:"POST",url:this.parse(r,e),data:t,headers:{"Content-Type":"application/json"}},this.execute(n)},o.prototype.parse=function(){var e;return e=1<=arguments.length?t.call(arguments,0):[],e.join("/").replace(/\/\//,"/")},o}())}return e}(),angular.module("bbData").service("restService",["$http","$q","API",e])}.call(this),function(){describe("Rest service",function(){var e,t,n;return beforeEach(module("bbData")),beforeEach(function(){return module(function(e){return e.constant("API","/api/")})}),n=e=null,t=function(t){return n=t.get("restService"),e=t.get("$httpBackend")},beforeEach(inject(t)),afterEach(function(){return e.verifyNoOutstandingExpectation(),e.verifyNoOutstandingRequest()}),it("should be defined",function(){return expect(n).toBeDefined()}),it("should make an ajax GET call to /api/endpoint",function(){var t,r;return r={a:"A"},e.whenGET("/api/endpoint").respond(r),t=null,n.get("endpoint").then(function(e){return t=e}),expect(t).toBeNull(),e.flush(),expect(t).toEqual(r)}),it("should make an ajax GET call to /api/endpoint with parameters",function(){var t;return t={key:"value"},e.whenGET("/api/endpoint?key=value").respond(200),n.get("endpoint",t),e.flush()}),it("should reject the promise on error",function(){var t,r;return t="Internal server error",e.expectGET("/api/endpoint").respond(500,t),r=null,n.get("endpoint").then(function(e){return r=e},function(e){return r=e}),e.flush(),expect(r).toBe(t)}),it("should make an ajax POST call to /api/endpoint",function(){var t,r,o;return o={},t={b:"B"},e.expectPOST("/api/endpoint",t).respond(o),r=null,n.post("endpoint",t).then(function(e){return r=e}),e.flush(),expect(r).toEqual(o)}),it("should reject the promise when the response is not valid JSON",function(){var t,r,o;return o="aaa",t={b:"B"},e.expectPOST("/api/endpoint",t).respond(o),r=null,n.post("endpoint",t).then(function(e){return r=e},function(e){return r=e}),e.flush(),expect(r).not.toBeNull(),expect(r).not.toEqual(o)})})}.call(this),function(){var e;e=function(){function e(e,t,n,r,o,u){var i;return new(i=function(){function i(){this.queue=[],this.deferred={},this.open()}return i.prototype.eventStream=null,i.prototype.open=function(){return null==this.socket&&(this.socket=u.getWebSocket(this.getUrl())),this.socket.onopen=function(e){return function(){return e.flush()}}(this),this.setupEventStream()},i.prototype.setupEventStream=function(){return null==this.eventStream&&(this.eventStream=new o),this.socket.onmessage=function(t){return function(r){var o,u,i,s,c,a;try{return o=angular.fromJson(r.data),e.debug("WS message",o),null!=o.code?(i=o._id,200===o.code?null!=(s=t.deferred[i])?s.resolve(!0):void 0:null!=(c=t.deferred[i])?c.reject(o):void 0):n.$applyAsync(function(){return t.eventStream.push(o)})}catch(l){return u=l,null!=(a=t.deferred[i])?a.reject(u):void 0}}}(this)},i.prototype.close=function(){return this.socket.close()},i.prototype.send=function(n){var r,o;return o=this.nextId(),n._id=o,null==(r=this.deferred)[o]&&(r[o]=t.defer()),n=angular.toJson(n),this.socket.readyState===(this.socket.OPEN||1)?(e.debug("WS send",angular.fromJson(n)),this.socket.send(n)):this.queue.push(n),this.deferred[o].promise},i.prototype.flush=function(){var t,n;for(n=[];t=this.queue.pop();)e.debug("WS send",angular.fromJson(t)),n.push(this.socket.send(t));return n},i.prototype.nextId=function(){return null==this.id&&(this.id=0),this.id=this.id<1e3?this.id+1:0,this.id},i.prototype.getUrl=function(){var e,t;return e=r.host(),t=80===r.port()?"":":"+r.port(),"ws://"+e+t+"/ws"},i}())}return e}(),angular.module("bbData").service("socketService",["$log","$q","$rootScope","$location","Stream","webSocketService",e])}.call(this),function(){describe("Socket service",function(){var e,t,n,r,o,u;return t=function(){function e(){n=this,this.webSocket=new t}var t,n;return e.prototype.sendQueue=[],e.prototype.receiveQueue=[],n=null,e.prototype.send=function(e){var t;return t={data:e},this.sendQueue.push(t)},e.prototype.flush=function(){var e,t;for(t=[];e=this.sendQueue.shift();)t.push(this.webSocket.onmessage(e));return t},e.prototype.getWebSocket=function(){return this.webSocket},t=function(){function e(){}return e.prototype.OPEN=1,e.prototype.send=function(e){return n.receiveQueue.push(e)},e}(),e}(),u=new t,beforeEach(function(){return module("bbData"),module(function(e){return e.constant("webSocketService",u)})}),e=o=r=null,n=function(t){return e=t.get("$rootScope"),o=t.get("socketService"),r=o.socket,spyOn(r,"send").and.callThrough(),spyOn(r,"onmessage").and.callThrough()},beforeEach(inject(n)),it("should be defined",function(){return expect(o).toBeDefined()}),it("should send the data, when the WebSocket is open",function(){var e,t,n;return r.readyState=0,e={a:1},t={b:2},n={c:3},o.send(e),o.send(t),expect(r.send).not.toHaveBeenCalled(),r.onopen(),expect(r.send).toHaveBeenCalled(),expect(u.receiveQueue).toContain(angular.toJson(e)),expect(u.receiveQueue).toContain(angular.toJson(t)),expect(u.receiveQueue).not.toContain(angular.toJson(n))}),it("should add an _id to each message",function(){var e;return r.readyState=1,expect(r.send).not.toHaveBeenCalled(),o.send({}),expect(r.send).toHaveBeenCalledWith(jasmine.any(String)),e=r.send.calls.argsFor(0)[0],expect(angular.fromJson(e)._id).toBeDefined()}),it("should resolve the promise when a response message is received with code 200",function(){var t,n,i,s,c,a;return r.readyState=1,s={cmd:"command"},c=o.send(s),n=jasmine.createSpy("handler"),c.then(n),expect(n).not.toHaveBeenCalled(),t=r.send.calls.argsFor(0)[0],i=angular.fromJson(t)._id,a=angular.toJson({_id:i,code:200}),u.send(a),e.$apply(function(){return u.flush()}),expect(n).toHaveBeenCalled()}),it("should reject the promise when a response message is received, but the code is not 200",function(){var t,n,i,s,c,a,l;return r.readyState=1,c={cmd:"command"},a=o.send(c),i=jasmine.createSpy("handler"),n=jasmine.createSpy("errorHandler"),a.then(i,n),expect(i).not.toHaveBeenCalled(),expect(n).not.toHaveBeenCalled(),t=r.send.calls.argsFor(0)[0],s=angular.fromJson(t)._id,l=angular.toJson({_id:s,code:500}),u.send(l),e.$apply(function(){return u.flush()}),expect(i).not.toHaveBeenCalled(),expect(n).toHaveBeenCalled()})})}.call(this),function(){var e;e=function(){function e(e){var t;return new(t=function(){function t(){}return t.prototype.getWebSocket=function(t){var n;if(n=/wss?:\/\//.exec(t),!n)throw new Error("Invalid url provided");return null!=e.ReconnectingWebSocket?new e.ReconnectingWebSocket(t):new e.WebSocket(t)},t}())}return e}(),angular.module("bbData").service("webSocketService",["$window",e])}.call(this),function(){var e;e=function(){function e(){var e;return e=function(){function e(){}return e.prototype.onUnsubscribe=null,e.prototype.listeners=[],e.prototype.subscribe=function(e){if(!angular.isFunction(e))throw new TypeError("Parameter 'listener' must be a function, not "+typeof e);return e.id=this.generateId(),this.listeners.push(e),function(t){return function(){var n,r;return n=t.listeners.indexOf(e),r=t.listeners.splice(n,1),angular.isFunction(t.onUnsubscribe)?t.onUnsubscribe(e):void 0}}(this)},e.prototype.push=function(e){var t,n,r,o,u;for(o=this.listeners,u=[],t=0,n=o.length;n>t;t++)r=o[t],u.push(r(e));return u},e.prototype.destroy=function(){var e;for(e=[];this.listeners.length>0;)e.push(this.listeners.pop());return e},e.prototype.generateId=function(){return null==this.lastId&&(this.lastId=0),this.lastId++},e}()}return e}(),angular.module("bbData").factory("Stream",[e])}.call(this),function(){describe("Stream service",function(){var e,t,n;return beforeEach(module("bbData")),e=n=null,t=function(t){return e=t.get("Stream"),n=new e},beforeEach(inject(t)),it("should be defined",function(){return expect(e).toBeDefined(),expect(n).toBeDefined()}),it("should add the listener to listeners on subscribe call",function(){var e;return e=n.listeners,expect(e.length).toBe(0),n.subscribe(function(){}),expect(e.length).toBe(1)}),it("should add a unique id to each listener passed in to subscribe",function(){var e,t,r;return r=n.listeners,e=function(){},t=function(){},n.subscribe(e),n.subscribe(t),expect(e.id).toBeDefined(),expect(t.id).toBeDefined(),expect(e.id).not.toBe(t.id)}),it("should return the unsubscribe function on subscribe call",function(){var e,t,r,o;return t=n.listeners,e=function(){},r=function(){},o=n.subscribe(e),n.subscribe(r),expect(t).toContain(e),o(),expect(t).not.toContain(e),expect(t).toContain(r)}),it("should call all listeners on push call",function(){var e,t;return e={a:"A",b:"B"},t={first:function(e){return expect(e).toEqual({a:"A",b:"B"})},second:function(e){return expect(e).toEqual({a:"A",b:"B"})}},spyOn(t,"first").and.callThrough(),spyOn(t,"second").and.callThrough(),n.subscribe(t.first),n.subscribe(t.second),expect(t.first).not.toHaveBeenCalled(),expect(t.second).not.toHaveBeenCalled(),n.push(e),expect(t.first).toHaveBeenCalled(),expect(t.second).toHaveBeenCalled()}),it("should remove all listeners on destroy call",function(){var e;return e=n.listeners,expect(e.length).toBe(0),n.subscribe(function(){}),n.subscribe(function(){}),expect(e.length).not.toBe(0),n.destroy(),expect(e.length).toBe(0)}),it("should call the unsubscribe listener on unsubscribe call",function(){var e,t;return spyOn(n,"onUnsubscribe"),e=function(){},t=n.subscribe(e),expect(n.onUnsubscribe).not.toHaveBeenCalled(),t(),expect(n.onUnsubscribe).toHaveBeenCalledWith(e)})})}.call(this); |
{ | ||
"name": "buildbot-data", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Buildbot AngularJS data module", | ||
@@ -5,0 +5,0 @@ "readme": "README.md", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126522
1474