Skip to content

Commit

Permalink
Merge pull request #58 from hmrc/DC-3349I
Browse files Browse the repository at this point in the history
DC-3349: IT test to include filter for inbox
  • Loading branch information
muralishub authored May 17, 2021
2 parents 3956dc0 + d4f7be1 commit a0ab690
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ lazy val externalServices = List(
ExternalService("IDENTITY_VERIFICATION"),
ExternalService("USER_DETAILS"),
ExternalService("SECURE_MESSAGE"),
ExternalService("SECURE_MESSAGE_FRONTEND"),
ExternalService("EMAIL"),
ExternalService("CHANNEL_PREFERENCES"),
ExternalService("ENTITY_RESOLVER")
Expand Down
93 changes: 90 additions & 3 deletions it/ConversationInboxPartialISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,35 @@ import org.mockito.Mockito.when
import org.scalatest.BeforeAndAfterEach
import org.scalatestplus.mockito.MockitoSugar
import org.scalatestplus.play.PlaySpec
import play.api.http.{ ContentTypes, HeaderNames }
import play.api.inject.guice.GuiceableModule
import play.api.libs.json.{ Json, Reads }
import play.api.libs.ws.WSClient
import play.api.http.Status.{ BAD_REQUEST, OK }
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.integration.ServiceSpec

import controllers.Assets.CREATED
import java.io.File
import scala.concurrent.{ ExecutionContext, Future }

@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements"))
class ConversationInboxPartialISpec extends PlaySpec with ServiceSpec with MockitoSugar with BeforeAndAfterEach {

override def externalServices: Seq[String] = Seq.empty
val secureMessagePort: Int = 9051
val secureMessageFrontendPort: Int = 9055
override protected def beforeEach() = {
(wsClient
.url(s"http://localhost:$secureMessagePort/test-only/delete/conversation/SMF123456789/CDCM")
.withHttpHeaders((HeaderNames.CONTENT_TYPE, ContentTypes.JSON))
.delete
.futureValue)
(wsClient
.url(s"http://localhost:$secureMessagePort/test-only/delete/message/609d1359aa0200d12c73950a")
.withHttpHeaders((HeaderNames.CONTENT_TYPE, ContentTypes.JSON))
.delete
.futureValue)
()
}

private val mockSecureMessageConnector = mock[SecureMessageConnector]

Expand All @@ -50,7 +66,55 @@ class ConversationInboxPartialISpec extends PlaySpec with ServiceSpec with Mocki
bind[SecureMessageConnector].toInstance(mockSecureMessageConnector)
})

"Getting the conversation list partial" should {
"Getting the message inbox list partial" should {

"return list with correct filter" in new TestSetUp {

val responseWithOutFilter = wsClient
.url(s"http://localhost:$secureMessageFrontendPort/secure-message-frontend/something/messages?")
.withHttpHeaders(AuthUtil.buildEoriToken)
.get()
.futureValue
responseWithOutFilter.status mustBe OK
val bodyWithOutFilter = responseWithOutFilter.body
bodyWithOutFilter must include("CDS-EXPORTS Subject")
bodyWithOutFilter must include("Direct Debit Subject")

val responseWithCDSExportFilter = wsClient
.url(s"http://localhost:$secureMessageFrontendPort/secure-message-frontend/" +
s"something/messages?enrolment=HMRC-CUS-ORG~EORINumber~GB1234567890&tag=notificationType~CDS-EXPORTS")
.withHttpHeaders(AuthUtil.buildEoriToken)
.get()
.futureValue
responseWithCDSExportFilter.status mustBe OK
val bodyWithCDSFilter = responseWithCDSExportFilter.body
bodyWithCDSFilter must include("CDS-EXPORTS Subject")
bodyWithCDSFilter must not include ("Direct Debit Subject")

val responseWithDDFilter = wsClient
.url(s"http://localhost:$secureMessageFrontendPort/secure-message-frontend/" +
s"something/messages?enrolment=HMRC-CUS-ORG~EORINumber~GB1234567890&tag=notificationType~Direct Debit")
.withHttpHeaders(AuthUtil.buildEoriToken)
.get()
.futureValue
responseWithDDFilter.status mustBe OK
val bodyWithDDFilter = responseWithDDFilter.body
bodyWithDDFilter must not include ("CDS-EXPORTS Subject")
bodyWithDDFilter must include("Direct Debit Subject")

val responseWithDifferentEori = wsClient
.url(s"http://localhost:$secureMessageFrontendPort/secure-message-frontend/" +
s"something/messages?enrolment=HMRC-CUS-ORG~EORINumber~GB1234567999&tag=notificationType~Direct Debit")
.withHttpHeaders(AuthUtil.buildEoriToken)
.get()
.futureValue
responseWithDifferentEori.status mustBe OK
val bodyWithWithDifferentUser = responseWithDifferentEori.body
bodyWithWithDifferentUser must not include ("CDS-EXPORTS Subject")
bodyWithWithDifferentUser must not include ("Direct Debit Subject")

}

"return status code OK 200" in {
when(
mockSecureMessageConnector.getConversationList(
Expand Down Expand Up @@ -98,6 +162,29 @@ class ConversationInboxPartialISpec extends PlaySpec with ServiceSpec with Mocki
}
}

class TestSetUp {
val createConversationUrl =
s"http://localhost:$secureMessagePort/secure-messaging/conversation/CDCM/SMF123456789"

wsClient
.url(createConversationUrl)
.withHttpHeaders((HeaderNames.CONTENT_TYPE, ContentTypes.JSON))
.put(new File("./it/resources/create-conversation.json"))
.futureValue
.status mustBe CREATED

val createMessageUrl =
s"http://localhost:$secureMessagePort/test-only/create/message/609d1359aa0200d12c73950a"

val responseFromSecureMessage =
wsClient
.url(createMessageUrl)
.withHttpHeaders((HeaderNames.CONTENT_TYPE, ContentTypes.JSON))
.put(new File("./it/resources/create-letter.json"))
.futureValue
responseFromSecureMessage.status mustBe CREATED
}

object AuthUtil {

lazy val ggAuthPort: Int = 8585
Expand Down
2 changes: 1 addition & 1 deletion it/ConversationPartialISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ConversationPartialISpec extends PlaySpec with ServiceSpec with MockitoSug
val pageContent = Jsoup.parse(response.body)
pageContent
.select("h1.govuk-heading-l.margin-top-small.margin-bottom-small")
.text() mustBe "This subject needs action"
.text() mustBe "CDS-EXPORTS Subject"
response.body must include("CDS Exports Team sent")
pageContent.select("div.govuk-body").first().text() mustBe "Message body!!"
pageContent
Expand Down
2 changes: 1 addition & 1 deletion it/resources/create-conversation.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"mrn": "DMS7324874993",
"notificationType": "CDS-EXPORTS"
},
"subject": "This subject needs action",
"subject": "CDS-EXPORTS Subject",
"message": "TWVzc2FnZSBib2R5ISE=",
"language": "en"
}
45 changes: 45 additions & 0 deletions it/resources/create-letter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"recipient" : {
"regime" : "cds",
"identifier" : {
"name" : "HMRC-CUS-ORG",
"value" : "GB1234567890"
},
"email" : "[email protected]"
},

"subject" : "Direct Debit Subject",
"renderUrl" : {
"service" : "message",
"url" : "/messages/6086dc1f4700009fed2f5745/content"
},
"validFrom" : "2021-04-26",
"externalRef" : {
"id" : "1234567891234567892",
"source" : "mdtp"
},
"hash" : "LfK755SXhY2rlc9kL50ohJZ2dvRzZGjU74kjcdJMAcY=",
"alertQueue" : "DEFAULT",
"alertFrom" : "2021-04-26",
"status" : "succeeded",
"content" : "<h2>Test content</h2>",
"statutory" : false,
"alertDetails" : {
"templateId" : "cds_ddi_setup_dcs_alert",
"recipientName" : {
"title" : "Dr",
"forename" : "Bruce",
"secondForename" : "Hulk",
"surname" : "Banner",
"honours" : "Green",
"line1" : "Line1"
}
},
"alerts" : {
"emailAddress" : "[email protected]",
"success" : true
},
"tags": {
"notificationType": "Direct Debit"
}
}

0 comments on commit a0ab690

Please sign in to comment.