AJS.test.require(["jira.webresources:viewissue-watchers-and-voters"],function(){"use strict";function e(e,t,s){var r=e+"/rest/api/2/issue/"+s+"/votes",n={self:r,votes:1,hasVoted:!0,voters:[]};return t.forEach(function(t){n.voters.push({self:e+"/rest/api/2/user?username="+t,key:t,name:t,avatarUrls:{"16x16":e+"/secure/useravatar?size=xsmall&avatarId=10052","24x24":e+"/secure/useravatar?size=small&avatarId=10052","32x32":e+"/secure/useravatar?size=medium&avatarId=10052","48x48":e+"/secure/useravatar?avatarId=10052"},displayName:t,active:!0})}),[r,n]}function t(e,t,s){var r=e+"/rest/api/2/issue/"+s+"/watchers",n={self:r,watchCount:1,isWatching:!0,watchers:[]};return t.forEach(function(t){n.watchers.push({self:e+"/rest/api/2/user?username="+t,key:t,name:t,avatarUrls:{"16x16":e+"/secure/useravatar?size=xsmall&avatarId=10052","24x24":e+"/secure/useravatar?size=small&avatarId=10052","32x32":e+"/secure/useravatar?size=medium&avatarId=10052","48x48":e+"/secure/useravatar?avatarId=10052"},displayName:t,active:!0})}),[r,n]}var s=require("jira/viewissue/watchers-voters/entities/voters-user-collection"),r=require("wrm/context-path"),n=r();module("Voters",{setup:function(){this.server=sinon.fakeServer.create()}}),test("Voter construnction",function(){try{new s,ok(!1,"should have thrown an error")}catch(e){ok(/issue key/.test(e.message),"Error should relate to the issue key")}var e=new s("test-123");ok(/test-123/.test(e.url()),"collection url contains our issue key")}),test("Can retrieve voters from server",function(){var t=e(n,["admin"],"HSP-3");this.server.respondWith("GET",new RegExp(t[0]+"*"),[200,{"Content-Type":"application/json"},JSON.stringify(t[1])]);var r=new s("HSP-3");r.fetch(),this.server.respond(),this.server.respond(),equal(r.size(),1),equal(r.at(0).get("name"),"admin","the admin voted for this issue"),equal(r.get("admin"),r.at(0),"getting by id vs. getting by index")}),test("Can retrieve voters for multiple issues",function(){var t=e(n,["admin"],"HSP-3"),r=e(n,["cleese"],"SOMETHINGDIFFERENT-1");this.server.respondWith("GET",new RegExp(t[0]+"*"),[200,{"Content-Type":"application/json"},JSON.stringify(t[1])]),this.server.respondWith("GET",new RegExp(r[0]+"*"),[200,{"Content-Type":"application/json"},JSON.stringify(r[1])]);var a=new s("HSP-3"),i=new s("SOMETHINGDIFFERENT-1");a.fetch(),i.fetch(),this.server.respond(),this.server.respond(),equal(a.at(0).get("name"),"admin"),equal(i.at(0).get("name"),"cleese")}),test("Can vote for an issue",function(){var t=e(n,["admin"],"HSP-3");this.server.respondWith("GET",new RegExp(t[0]+"*"),[200,{"Content-Type":"application/json"},JSON.stringify(t[1])]),this.server.respondWith("POST",new RegExp(t[0]+"*"),[204,{},""]);var r=new s("HSP-3");r.vote(),this.server.respond(),this.server.respond(),ok(void 0!==r.get("admin"),"admin should be in the collection now")}),test("Can unvote for an issue",function(){var t=e(n,["admin"],"HSP-3");this.server.respondWith("GET",new RegExp(t[0]+"*"),function(e){e.respond(200,{"Content-Type":"application/json"},JSON.stringify(t[1]))}),this.server.respondWith("DELETE",new RegExp(t[0]+"*"),[204,{},""]);var r=new s("HSP-3");r.fetch(),this.server.respond(),ok(void 0!==r.get("admin"),"admin should be in the collection to start with"),t=e(n,[],"HSP-3"),r.unvote(),this.server.respond(),this.server.respond(),ok(void 0===r.get("admin"),"admin should not be in the collection now")});var a;module("Watchers",{setup:function(){this.server=sinon.fakeServer.create(),a=JIRA.WatchersUsersCollection}}),test("Watcher construnction",function(){try{new a,ok(!1,"should have thrown an error")}catch(e){ok(/issue key/.test(e.message),"Error should relate to the issue key")}var e=new a("test-123");ok(/test-123/.test(e.url()),"collection url contains our issue key")}),test("Can get watchers",function(){var e=t(n,["admin"],"HSP-3");this.server.respondWith("GET",new RegExp(e[0]+"*"),[200,{"Content-Type":"application/json"},JSON.stringify(e[1])]);var s=new a("HSP-3");s.fetch(),this.server.respond(),equal(s.size(),1),equal(s.at(0).get("name"),"admin","the admin is watching this issue"),equal(s.get("admin"),s.at(0),"getting by id vs. getting by index")}),test("Can add watchers",function(){var e=t(n,[],"HSP-3");this.server.respondWith("GET",new RegExp(e[0]+"*"),function(t){t.respond(200,{"Content-Type":"application/json"},JSON.stringify(e[1]))}),this.server.respondWith("POST",new RegExp(e[0]+"*"),[204,{},""]);var s=new a("HSP-3");s.fetch(),this.server.respond(),e=t(n,["admin"],"HSP-3"),s.addWatcher("admin"),this.server.respond(),this.server.respond(),equal(s.get("admin").get("name"),"admin","the admin is watching this issue")}),test("Can remove watchers",function(){var e=t(n,["admin"],"HSP-3");this.server.respondWith("GET",new RegExp(e[0]+"*"),function(t){t.respond(200,{"Content-Type":"application/json"},JSON.stringify(e[1]))}),this.server.respondWith("DELETE",new RegExp(e[0]+"*"),[204,{},""]);var s=new a("HSP-3");s.fetch(),this.server.respond(),e=t(n,[],"HSP-3"),s.removeWatcher("admin"),this.server.respond(),this.server.respond(),equal(s.size(),0,"there should be no one left now")})});