summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2020-06-23 10:54:12 -0400
committerNicoleYarroch <nicole@livio.io>2020-06-23 10:54:12 -0400
commitfbf5744a2cafa023deaa6766fdbe81c143459515 (patch)
tree3fd8cbd4fbccd92a369ffd93d17c933850c6f1ba
parent0d2b18c8c63ba656f1b941acb481875d4f10b199 (diff)
downloadsdl_ios-fbf5744a2cafa023deaa6766fdbe81c143459515.tar.gz
Subscriber is removed if subscription fails
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r--SmartDeviceLink/SDLSubscribeButtonManager.m3
-rw-r--r--SmartDeviceLinkTests/SDLSubscribeButtonManagerSpec.m10
2 files changed, 10 insertions, 3 deletions
diff --git a/SmartDeviceLink/SDLSubscribeButtonManager.m b/SmartDeviceLink/SDLSubscribeButtonManager.m
index c2ab8a002..3660a1064 100644
--- a/SmartDeviceLink/SDLSubscribeButtonManager.m
+++ b/SmartDeviceLink/SDLSubscribeButtonManager.m
@@ -164,9 +164,10 @@ NS_ASSUME_NONNULL_BEGIN
[self.connectionManager sendConnectionRequest:subscribeButton withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if (error == nil) { return; }
- // If there was an error during the subscription attempt, return the error message.
+ // If there was an error during the subscription attempt, return the error message and remove the observer.
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf sdl_invokeObserver:observerObject withButtonName:buttonName buttonPress:nil buttonEvent:nil error:error];
+ [strongSelf sdl_removeSubscribedObserver:observerObject.observer forButtonName:buttonName];
}];
}
diff --git a/SmartDeviceLinkTests/SDLSubscribeButtonManagerSpec.m b/SmartDeviceLinkTests/SDLSubscribeButtonManagerSpec.m
index 77c662185..5b7bdbf48 100644
--- a/SmartDeviceLinkTests/SDLSubscribeButtonManagerSpec.m
+++ b/SmartDeviceLinkTests/SDLSubscribeButtonManagerSpec.m
@@ -120,7 +120,7 @@ describe(@"subscribe button manager", ^{
expect(testHandler1Called).to(beFalse());
});
- it(@"should notify the observer with the error when a failure response is recieved for the subscribe button request", ^{
+ it(@"should notify the observer with the error and remove the observer when a failure response is recieved for the subscribe button request", ^{
[testManager subscribeButton:testButtonName withUpdateHandler:testUpdateHandler1];
SDLSubscribeButtonResponse *testFailureResponse = [[SDLSubscribeButtonResponse alloc] init];
@@ -130,6 +130,9 @@ describe(@"subscribe button manager", ^{
expect(testHandler1Called).to(beTrue());
expect(testHandle1Error).to(equal(testError));
+
+ NSArray<SDLSubscribeButtonObserver *> *observers = testManager.subscribeButtonObservers[testButtonName];
+ expect(observers.count).to(equal(0));
});
});
@@ -184,7 +187,7 @@ describe(@"subscribe button manager", ^{
expect(testSubscribeButtonObserver1.selectorCalledCount).to(equal(0));
});
- it(@"should notify the observer with the error when a failure response is recieved for the subscribe button request", ^{
+ it(@"should notify the observer with the error and remove the observer when a failure response is recieved for the subscribe button request", ^{
[testManager subscribeButton:testButtonName withObserver:testSubscribeButtonObserver1 selector:testSelector2];
SDLSubscribeButtonResponse *testFailureResponse = [[SDLSubscribeButtonResponse alloc] init];
@@ -196,6 +199,9 @@ describe(@"subscribe button manager", ^{
expect(testSubscribeButtonObserver1.buttonErrorsReceived.count).to(equal(1));
expect(testSubscribeButtonObserver1.buttonErrorsReceived[0]).to(equal(testError));
expect(testSubscribeButtonObserver1.buttonNamesReceived[0]).to(equal(testButtonName));
+
+ NSArray<SDLSubscribeButtonObserver *> *observers = testManager.subscribeButtonObservers[testButtonName];
+ expect(observers.count).to(equal(0));
});
it(@"should ignore a subscription attempt with an invalid selector - selector has too many parameters", ^{