From 5c22cf249afef9bcbd9cf0b15cd320a5a5968fbf Mon Sep 17 00:00:00 2001 From: Matthew Clark <36630558+mattclark-zerogravit@users.noreply.github.com> Date: Fri, 14 Aug 2020 15:14:25 +0100 Subject: [PATCH] API-4542: empty values are now handled in PPNS so allowing empty values to be sent. (#87) --- .../service/SubscriptionFieldsService.scala | 2 +- .../PushPullNotificationServiceConnectorSpec.scala | 14 ++++++++++++++ .../service/SubscriptionFieldsServiceSpec.scala | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsService.scala b/app/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsService.scala index 34e4010..537c973 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsService.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsService.scala @@ -68,7 +68,7 @@ class SubscriptionFieldsService @Inject() ( ppnsFieldDefinition match { case Some(fieldDefinition) => - val oFieldValue: Option[FieldValue] = fields.get(fieldDefinition.name).filterNot(_.isEmpty) + val oFieldValue: Option[FieldValue] = fields.get(fieldDefinition.name) pushPullNotificationService.subscribeToPPNS(clientId, apiContext, apiVersion, oFieldValue, fieldDefinition).flatMap { case PPNSCallBackUrlSuccessResponse => upsertSubscriptionFields(clientId, apiContext, apiVersion, fields) case PPNSCallBackUrlFailedResponse(error) => Future.successful(FailedValidationSubsFieldsUpsertResponse(Map(fieldDefinition.name -> error))) diff --git a/test/uk/gov/hmrc/apisubscriptionfields/connector/PushPullNotificationServiceConnectorSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/connector/PushPullNotificationServiceConnectorSpec.scala index cafe9a1..eb8abd3 100644 --- a/test/uk/gov/hmrc/apisubscriptionfields/connector/PushPullNotificationServiceConnectorSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/connector/PushPullNotificationServiceConnectorSpec.scala @@ -140,6 +140,20 @@ class PushPullNotificationServiceConnectorSpec verifyMock(path) } + "send proper request to update callback (when callback is empty) and map response on success" in new Setup { + val callbackUrl = "" + val requestBody: String = Json.stringify(Json.toJson(UpdateCallBackUrlRequest(clientId, callbackUrl))) + val responseBody: String = Json.stringify(Json.toJson(UpdateCallBackUrlResponse(successful = true, None))) + + val path = s"/box/${boxId.value}/callback" + primeStub(path, requestBody, responseBody) + + val ret: PPNSCallBackUrlValidationResponse = await(connector.updateCallBackUrl(clientId, boxId, callbackUrl)) + ret shouldBe PPNSCallBackUrlSuccessResponse + + verifyMock(path) + } + "send proper request to update callback and map response on failure" in new Setup { val callbackUrl = "my-callback" diff --git a/test/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala index 3afa34c..8246211 100644 --- a/test/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/service/SubscriptionFieldsServiceSpec.scala @@ -151,7 +151,7 @@ class SubscriptionFieldsServiceSpec extends AsyncHmrcSpec with SubscriptionField result shouldBe SuccessfulSubsFieldsUpsertResponse(SubscriptionFields(FakeClientId, FakeContext, FakeVersion, FakeFieldsId, fields), isInsert = false) - verify(mockPushPullNotificationService).subscribeToPPNS(eqTo(FakeClientId), eqTo(FakeContext), eqTo(FakeVersion), any, any[FieldDefinition])(any) + verify(mockPushPullNotificationService).subscribeToPPNS(eqTo(FakeClientId), eqTo(FakeContext), eqTo(FakeVersion), eqTo(Some("https://www.mycallbackurl.com")), any[FieldDefinition])(any) verify(mockSubscriptionFieldsRepository).saveAtomic(*) } @@ -165,7 +165,7 @@ class SubscriptionFieldsServiceSpec extends AsyncHmrcSpec with SubscriptionField result shouldBe SuccessfulSubsFieldsUpsertResponse(SubscriptionFields(FakeClientId, FakeContext, FakeVersion, FakeFieldsId, fields), isInsert = false) - verify(mockPushPullNotificationService).subscribeToPPNS(eqTo(FakeClientId), eqTo(FakeContext), eqTo(FakeVersion), any, any[FieldDefinition])(any) + verify(mockPushPullNotificationService).subscribeToPPNS(eqTo(FakeClientId), eqTo(FakeContext), eqTo(FakeVersion),eqTo(Some("")), any[FieldDefinition])(any) verify(mockSubscriptionFieldsRepository).saveAtomic(*) }