Skip to content

Commit

Permalink
API-4542: empty values are now handled in PPNS so allowing empty valu…
Browse files Browse the repository at this point in the history
…es to be sent. (#87)
  • Loading branch information
mattclark-zerogravit authored Aug 14, 2020
1 parent 79bd5c6 commit 5c22cf2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(*)
}

Expand All @@ -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(*)
}

Expand Down

0 comments on commit 5c22cf2

Please sign in to comment.