buildbot-data
Advanced tools
Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "buildbot-data", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"homepage": "https://github.com/tothandras/buildbot-data", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -589,2 +589,5 @@ (function() { | ||
/* @ngInject */ | ||
Data.prototype.$get = function($log, $injector, $q, restService, socketService, dataUtilsService, ENDPOINTS) { | ||
@@ -591,0 +594,0 @@ var DataService; |
@@ -1,1 +0,1 @@ | ||
(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(){describe("Base class",function(){var e,t,n,r,o;return beforeEach(module("bbData")),t=n=o=e=null,r=function(r){return t=r.get("Base"),n=r.get("dataService"),o=r.get("socketService"),e=r.get("$q")},beforeEach(inject(r)),it("should be defined",function(){return expect(t).toBeDefined()}),it("should merge the passed in object with the instance",function(){var e,n;return n={a:1,b:2},e=new t(n,"ab"),expect(e.a).toEqual(n.a),expect(e.b).toEqual(n.b)}),it("should have loadXxx function for child endpoints",function(){var e,n,r,o,u,i,s;for(r=["a","bcd","ccc"],n=new t({},"ab",r),s=[],u=0,i=r.length;i>u;u++)o=r[u],e=o[0].toUpperCase()+o.slice(1).toLowerCase(),s.push(expect(angular.isFunction(n["load"+e])).toBeTruthy());return s}),it("should subscribe a listener to socket service events",function(){var e;return expect(o.eventStream.listeners.length).toBe(0),e=new t({},"ab"),expect(o.eventStream.listeners.length).toBe(1)}),it("should remove the listener on unsubscribe",function(){var e;return expect(o.eventStream.listeners.length).toBe(0),e=new t({},"ab"),expect(o.eventStream.listeners.length).toBe(1),e.unsubscribe(),expect(o.eventStream.listeners.length).toBe(0)}),it("should update the instance when the event key matches",function(){var e,n;return n={buildid:1,a:2,b:3},e=new t(n,"builds"),expect(e.a).toEqual(n.a),o.eventStream.push({k:"builds/2/update",m:{a:3}}),expect(e.a).toEqual(n.a),o.eventStream.push({k:"builds/1/update",m:{a:3,c:4}}),expect(e.a).toEqual(3),expect(e.c).toEqual(4)}),it("should remove the listeners of child endpoints on unsubscribe",function(){var r,u,i,s;return r=new t({},"",["ccc"]),u=new t({},""),s=[u],i=e.resolve(s),i.getArray=function(){return s},spyOn(n,"get").and.returnValue(i),r.loadCcc(),expect(r.ccc).toEqual(s),expect(o.eventStream.listeners.length).toBe(2),r.unsubscribe(),expect(o.eventStream.listeners.length).toBe(0)})})}.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,d;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),d=[],a=o(function(n){return function(c,a){var f,h,b,v;return p?(f=[],v=i.eventStream.subscribe(function(e){return f.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,x;x=s.type(o),u=u[x];try{g=s.className(o),l=r.get(g)}catch(B){y=B,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),d.push(o),n.listeners[h].push(o.listenerId)):void 0}),p&&(f.forEach(function(e){return i.eventStream.push(e)}),v()),angular.copy(u,d),c(d)):(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 d},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(e,t){return u.post({id:this.getNextId(),jsonrpc:"2.0",method:e,params:t})},a.prototype.getNextId=function(){return null==this.jsonrpc&&(this.jsonrpc=1),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("control(method, params)",function(){return it("should send a jsonrpc message using POST",function(){var e,t;return spyOn(i,"post"),expect(i.post).not.toHaveBeenCalled(),e="force",t={a:1},o.control(e,t),expect(i.post).toHaveBeenCalledWith({id:1,jsonrpc:"2.0",method:e,params:t})})}),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,d,f;for(d=t.resolve({builds:[{},{},{}]}),spyOn(i,"get").and.returnValue(d),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(),f=[],c=0,p=o.length;p>c;c++)r=o[c],f.push(expect(r.unsubscribe).toHaveBeenCalled());return f}),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); | ||
(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(){describe("Base class",function(){var e,t,n,r,o;return beforeEach(module("bbData")),t=n=o=e=null,r=function(r){return t=r.get("Base"),n=r.get("dataService"),o=r.get("socketService"),e=r.get("$q")},beforeEach(inject(r)),it("should be defined",function(){return expect(t).toBeDefined()}),it("should merge the passed in object with the instance",function(){var e,n;return n={a:1,b:2},e=new t(n,"ab"),expect(e.a).toEqual(n.a),expect(e.b).toEqual(n.b)}),it("should have loadXxx function for child endpoints",function(){var e,n,r,o,u,i,s;for(r=["a","bcd","ccc"],n=new t({},"ab",r),s=[],u=0,i=r.length;i>u;u++)o=r[u],e=o[0].toUpperCase()+o.slice(1).toLowerCase(),s.push(expect(angular.isFunction(n["load"+e])).toBeTruthy());return s}),it("should subscribe a listener to socket service events",function(){var e;return expect(o.eventStream.listeners.length).toBe(0),e=new t({},"ab"),expect(o.eventStream.listeners.length).toBe(1)}),it("should remove the listener on unsubscribe",function(){var e;return expect(o.eventStream.listeners.length).toBe(0),e=new t({},"ab"),expect(o.eventStream.listeners.length).toBe(1),e.unsubscribe(),expect(o.eventStream.listeners.length).toBe(0)}),it("should update the instance when the event key matches",function(){var e,n;return n={buildid:1,a:2,b:3},e=new t(n,"builds"),expect(e.a).toEqual(n.a),o.eventStream.push({k:"builds/2/update",m:{a:3}}),expect(e.a).toEqual(n.a),o.eventStream.push({k:"builds/1/update",m:{a:3,c:4}}),expect(e.a).toEqual(3),expect(e.c).toEqual(4)}),it("should remove the listeners of child endpoints on unsubscribe",function(){var r,u,i,s;return r=new t({},"",["ccc"]),u=new t({},""),s=[u],i=e.resolve(s),i.getArray=function(){return s},spyOn(n,"get").and.returnValue(i),r.loadCcc(),expect(r.ccc).toEqual(s),expect(o.eventStream.listeners.length).toBe(2),r.unsubscribe(),expect(o.eventStream.listeners.length).toBe(0)})})}.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,d;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),d=[],a=o(function(n){return function(c,a){var f,h,b,v;return p?(f=[],v=i.eventStream.subscribe(function(e){return f.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,x;x=s.type(o),u=u[x];try{g=s.className(o),l=r.get(g)}catch(B){y=B,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),d.push(o),n.listeners[h].push(o.listenerId)):void 0}),p&&(f.forEach(function(e){return i.eventStream.push(e)}),v()),angular.copy(u,d),c(d)):(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 d},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(e,t){return u.post({id:this.getNextId(),jsonrpc:"2.0",method:e,params:t})},a.prototype.getNextId=function(){return null==this.jsonrpc&&(this.jsonrpc=1),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.prototype.$get.$inject=["$log","$injector","$q","restService","socketService","dataUtilsService","ENDPOINTS"],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("control(method, params)",function(){return it("should send a jsonrpc message using POST",function(){var e,t;return spyOn(i,"post"),expect(i.post).not.toHaveBeenCalled(),e="force",t={a:1},o.control(e,t),expect(i.post).toHaveBeenCalledWith({id:1,jsonrpc:"2.0",method:e,params:t})})}),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,d,f;for(d=t.resolve({builds:[{},{},{}]}),spyOn(i,"get").and.returnValue(d),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(),f=[],c=0,p=o.length;p>c;c++)r=o[c],f.push(expect(r.unsubscribe).toHaveBeenCalled());return f}),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.6", | ||
"version": "1.0.7", | ||
"description": "Buildbot AngularJS data module", | ||
@@ -5,0 +5,0 @@ "readme": "README.md", |
Sorry, the diff of this file is not supported yet
135915
1595