@@ -1157,17 +1157,34 @@ func TestHandleUnsubscribe(t *testing.T) {
11571157 assert .Equal (t , "Encountered an error trying to unsubscribe. Please try again." , result )
11581158 },
11591159 },
1160+ {
1161+ name : "No subscription exists for repo in the channel" ,
1162+ parameters : []string {"owner/repo" },
1163+ setup : func () {
1164+ mockKVStore .EXPECT ().Get (SubscriptionsKey , gomock .Any ()).DoAndReturn (func (key string , value * * Subscriptions ) error {
1165+ * value = & Subscriptions {Repositories : map [string ][]* Subscription {}}
1166+ return nil
1167+ }).Times (1 )
1168+ mockAPI .On ("GetUser" , MockUserID ).Return (nil , & model.AppError {Message : "error getting user" }).Times (1 )
1169+ mockAPI .On ("LogWarn" , "Error while fetching user details" , "error" , "error getting user" ).Times (1 )
1170+ mockKVStore .EXPECT ().SetAtomicWithRetries (SubscriptionsKey , gomock .Any ()).Return (nil ).Times (1 )
1171+ },
1172+ assertions : func (result string ) {
1173+ assert .Equal (t , "no subscription exists for `owner/repo` in the channel" , result )
1174+ },
1175+ },
11601176 {
11611177 name : "Error getting user details" ,
11621178 parameters : []string {"owner/repo" },
11631179 setup : func () {
11641180 mockKVStore .EXPECT ().Get (SubscriptionsKey , gomock .Any ()).DoAndReturn (func (key string , value * * Subscriptions ) error {
11651181 * value = & Subscriptions {Repositories : map [string ][]* Subscription {
1166- "owner/repo" : {{ChannelID : "dummyChannelID" , CreatorID : MockCreatorID , Repository : "owner/repo" }}}}
1182+ "owner/repo" : {{ChannelID : MockChannelID , CreatorID : MockCreatorID , Repository : "owner/repo" }}}}
11671183 return nil
11681184 }).Times (1 )
11691185 mockAPI .On ("GetUser" , MockUserID ).Return (nil , & model.AppError {Message : "error getting user" }).Times (1 )
11701186 mockAPI .On ("LogWarn" , "Error while fetching user details" , "error" , "error getting user" ).Times (1 )
1187+ mockKVStore .EXPECT ().SetAtomicWithRetries (SubscriptionsKey , gomock .Any ()).Return (nil ).Times (1 )
11711188 },
11721189 assertions : func (result string ) {
11731190 assert .Equal (t , "error while fetching user details: error getting user" , result )
@@ -1179,13 +1196,14 @@ func TestHandleUnsubscribe(t *testing.T) {
11791196 setup : func () {
11801197 mockKVStore .EXPECT ().Get (SubscriptionsKey , gomock .Any ()).DoAndReturn (func (key string , value * * Subscriptions ) error {
11811198 * value = & Subscriptions {Repositories : map [string ][]* Subscription {
1182- "owner" : {{ChannelID : "dummyChannelID" , CreatorID : MockCreatorID , Repository : "" }}}}
1199+ "owner/ " : {{ChannelID : MockChannelID , CreatorID : MockCreatorID , Repository : "owner " }}}}
11831200 return nil
11841201 }).Times (1 )
11851202 mockAPI .On ("GetUser" , MockUserID ).Return (& model.User {Username : MockUsername }, nil ).Times (1 )
11861203 mockAPI .On ("CreatePost" , mock .Anything ).Return (nil , & model.AppError {Message : "error creating post" }).Times (1 )
11871204 post .Message = "@mockUsername unsubscribed this channel from [owner](https://github.com/owner)"
11881205 mockAPI .On ("LogWarn" , "Error while creating post" , "post" , post , "error" , "error creating post" ).Times (1 )
1206+ mockKVStore .EXPECT ().SetAtomicWithRetries (SubscriptionsKey , gomock .Any ()).Return (nil ).Times (1 )
11891207 },
11901208 assertions : func (result string ) {
11911209 assert .Equal (t , "@mockUsername unsubscribed this channel from [owner](https://github.com/owner) error creating the public post: error creating post" , result )
@@ -1197,11 +1215,12 @@ func TestHandleUnsubscribe(t *testing.T) {
11971215 setup : func () {
11981216 mockKVStore .EXPECT ().Get (SubscriptionsKey , gomock .Any ()).DoAndReturn (func (key string , value * * Subscriptions ) error {
11991217 * value = & Subscriptions {Repositories : map [string ][]* Subscription {
1200- "owner" : {{ChannelID : "dummyChannelID" , CreatorID : MockCreatorID , Repository : "" }}}}
1218+ "owner/ " : {{ChannelID : MockChannelID , CreatorID : MockCreatorID , Repository : "" }}}}
12011219 return nil
12021220 }).Times (1 )
12031221 mockAPI .On ("GetUser" , MockUserID ).Return (& model.User {Username : MockUsername }, nil ).Times (1 )
12041222 mockAPI .On ("CreatePost" , mock .Anything ).Return (post , nil ).Times (1 )
1223+ mockKVStore .EXPECT ().SetAtomicWithRetries (SubscriptionsKey , gomock .Any ()).Return (nil ).Times (1 )
12051224 },
12061225 assertions : func (result string ) {
12071226 assert .Empty (t , result )
@@ -1213,13 +1232,14 @@ func TestHandleUnsubscribe(t *testing.T) {
12131232 setup : func () {
12141233 mockKVStore .EXPECT ().Get (SubscriptionsKey , gomock .Any ()).DoAndReturn (func (key string , value * * Subscriptions ) error {
12151234 * value = & Subscriptions {Repositories : map [string ][]* Subscription {
1216- "owner/repo" : {{ChannelID : "dummyChannelID" , CreatorID : MockCreatorID , Repository : "owner/repo" }}}}
1235+ "owner/repo" : {{ChannelID : MockChannelID , CreatorID : MockCreatorID , Repository : "owner/repo" }}}}
12171236 return nil
12181237 }).Times (1 )
12191238 mockAPI .On ("GetUser" , MockUserID ).Return (& model.User {Username : MockUsername }, nil ).Times (1 )
12201239 mockAPI .On ("CreatePost" , mock .Anything ).Return (nil , & model.AppError {Message : "error creating post" }).Times (1 )
12211240 post .Message = "@mockUsername Unsubscribed this channel from [owner/repo](https://github.com/owner/repo)\n Please delete the [webhook](https://github.com/owner/repo/settings/hooks) for this subscription unless it's required for other subscriptions."
12221241 mockAPI .On ("LogWarn" , "Error while creating post" , "post" , post , "error" , "error creating post" ).Times (1 )
1242+ mockKVStore .EXPECT ().SetAtomicWithRetries (SubscriptionsKey , gomock .Any ()).Return (nil ).Times (1 )
12231243 },
12241244 assertions : func (result string ) {
12251245 assert .Equal (t , "@mockUsername Unsubscribed this channel from [owner/repo](https://github.com/owner/repo)\n Please delete the [webhook](https://github.com/owner/repo/settings/hooks) for this subscription unless it's required for other subscriptions. error creating the public post: error creating post" , result )
@@ -1231,12 +1251,13 @@ func TestHandleUnsubscribe(t *testing.T) {
12311251 setup : func () {
12321252 mockKVStore .EXPECT ().Get (SubscriptionsKey , gomock .Any ()).DoAndReturn (func (key string , value * * Subscriptions ) error {
12331253 * value = & Subscriptions {Repositories : map [string ][]* Subscription {
1234- "owner/repo" : {{ChannelID : "dummyChannelID" , CreatorID : MockCreatorID , Repository : "owner/repo" }}}}
1254+ "owner/repo" : {{ChannelID : MockChannelID , CreatorID : MockCreatorID , Repository : "owner/repo" }}}}
12351255 return nil
12361256 }).Times (1 )
12371257 mockAPI .ExpectedCalls = nil
12381258 mockAPI .On ("GetUser" , MockUserID ).Return (& model.User {Username : MockUsername }, nil ).Times (1 )
12391259 mockAPI .On ("CreatePost" , mock .Anything ).Return (post , nil ).Times (1 )
1260+ mockKVStore .EXPECT ().SetAtomicWithRetries (SubscriptionsKey , gomock .Any ()).Return (nil ).Times (1 )
12401261 post .Message = ""
12411262 },
12421263 assertions : func (result string ) {
0 commit comments