From d8f940bd30b0cddca6153212fe45c867fc820073 Mon Sep 17 00:00:00 2001 From: "christopher.walker" Date: Tue, 2 May 2017 16:37:20 +0100 Subject: [PATCH 1/7] SCRS-6165 CR connector --- .../CompanyRegistrationConnector.scala | 53 +++++++++++ .../CompanyRegistrationConnectorSpec.scala | 93 +++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 app/connectors/CompanyRegistrationConnector.scala create mode 100644 test/connectors/CompanyRegistrationConnectorSpec.scala diff --git a/app/connectors/CompanyRegistrationConnector.scala b/app/connectors/CompanyRegistrationConnector.scala new file mode 100644 index 00000000..35846ada --- /dev/null +++ b/app/connectors/CompanyRegistrationConnector.scala @@ -0,0 +1,53 @@ +/* + * Copyright 2017 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package connectors + +import javax.inject.{Inject, Singleton} + +import config.WSHttp +import play.api.Logger +import uk.gov.hmrc.play.config.ServicesConfig +import uk.gov.hmrc.play.http.ws.WSHttp +import uk.gov.hmrc.play.http.{ForbiddenException, HeaderCarrier, HttpResponse, NotFoundException} + +import scala.concurrent.Future +import scala.concurrent.ExecutionContext.Implicits.global + +@Singleton +class CompanyRegistrationConnector @Inject()() extends CompanyRegistrationConnect with ServicesConfig{ + val compRegUrl = baseUrl("company-registration") + val http: WSHttp = WSHttp +} + +trait CompanyRegistrationConnect { + val compRegUrl: String + val http: WSHttp + + def fetchCompanyRegistrationDocument(regId: String)(implicit hc: HeaderCarrier): Future[HttpResponse] = { + http.GET[HttpResponse](s"$compRegUrl/company-registration/corporation-tax-registration/$regId/corporation-tax-registration") recover { + case e: NotFoundException => + Logger.error(s"[CompanyRegistrationConnector] - [fetchCompanyRegistrationDocument] : Received a NotFound status code when expecting reg document from Company-Registration") + throw e + case e: ForbiddenException => + Logger.error(s"[CompanyRegistrationConnector] - [fetchCompanyRegistrationDocument] : Received a Forbidden status code when expecting reg document from Company-Registration") + throw e + case e: Exception => + Logger.error(s"[CompanyRegistrationConnector] - [fetchCompanyRegistrationDocument] : Received error when expecting reg document from Company-Registration - Error ${e.getMessage}") + throw e + } + } +} diff --git a/test/connectors/CompanyRegistrationConnectorSpec.scala b/test/connectors/CompanyRegistrationConnectorSpec.scala new file mode 100644 index 00000000..92332a78 --- /dev/null +++ b/test/connectors/CompanyRegistrationConnectorSpec.scala @@ -0,0 +1,93 @@ +/* + * Copyright 2017 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package connectors + +import helpers.PAYERegSpec +import mocks.WSHTTPMock +import models.external.BusinessProfile +import org.mockito.ArgumentMatchers +import org.mockito.Mockito.when +import org.scalatestplus.play.guice.GuiceOneAppPerSuite +import play.api.libs.json.{JsValue, Json} +import uk.gov.hmrc.play.http.{ForbiddenException, HeaderCarrier, HttpResponse, NotFoundException} +import uk.gov.hmrc.play.http.ws.WSHttp +import play.api.test.Helpers._ + +import scala.concurrent.Future + +class CompanyRegistrationConnectorSpec extends PAYERegSpec with WSHTTPMock with GuiceOneAppPerSuite { + + val testJson = Json.parse( + """ + |{ + | "testKey" : "testValue" + |} + """.stripMargin + ) + + val okResponse = new HttpResponse { + override def status: Int = OK + override def json: JsValue = testJson + } + + implicit val hc = HeaderCarrier() + + class Setup { + val connector = new CompanyRegistrationConnect { + override val compRegUrl: String = "/testUrl" + override val http: WSHttp = mockWSHttp + } + } + + "fetchCompanyRegistrationDocument" should { + "return an OK with JSON body" when { + "given a valid regId" in new Setup { + mockHttpGet[HttpResponse]("testUrl", okResponse) + + val result = await(connector.fetchCompanyRegistrationDocument("testRegId")) + result shouldBe okResponse + } + } + + "throw a not found exception" when { + "the reg document cant be found" in new Setup { + when(mockWSHttp.GET[BusinessProfile](ArgumentMatchers.any())(ArgumentMatchers.any(), ArgumentMatchers.any())) + .thenReturn(Future.failed(new NotFoundException("Bad request"))) + + intercept[NotFoundException](await(connector.fetchCompanyRegistrationDocument("testRegId"))) + } + } + + "throw a forbidden exception" when { + "the request is not authorised" in new Setup { + when(mockWSHttp.GET[BusinessProfile](ArgumentMatchers.any())(ArgumentMatchers.any(), ArgumentMatchers.any())) + .thenReturn(Future.failed(new ForbiddenException("Forbidden"))) + + intercept[ForbiddenException](await(connector.fetchCompanyRegistrationDocument("testRegId"))) + } + } + + "throw an unchecked exception" when { + "an unexpected response code was returned" in new Setup { + when(mockWSHttp.GET[BusinessProfile](ArgumentMatchers.any())(ArgumentMatchers.any(), ArgumentMatchers.any())) + .thenReturn(Future.failed(new RuntimeException("Runtime Exception"))) + + intercept[Throwable](await(connector.fetchCompanyRegistrationDocument("testRegId"))) + } + } + } +} From 177c09b06416f968f08526ef22ee89c21bf72036 Mon Sep 17 00:00:00 2001 From: "christopher.walker" Date: Tue, 2 May 2017 16:56:32 +0100 Subject: [PATCH 2/7] SCRS-6165 xtract optional ctutr from CR doc --- app/services/SubmissionService.scala | 17 ++++++- test/services/SubmissionServiceSpec.scala | 58 ++++++++++++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/app/services/SubmissionService.scala b/app/services/SubmissionService.scala index 254c9d8c..c7dec20b 100644 --- a/app/services/SubmissionService.scala +++ b/app/services/SubmissionService.scala @@ -23,7 +23,7 @@ import common.exceptions.DBExceptions.MissingRegDocument import common.exceptions.RegistrationExceptions._ import common.exceptions.SubmissionExceptions._ import config.MicroserviceAuditConnector -import connectors.{AuthConnect, AuthConnector, BusinessRegistrationConnect, BusinessRegistrationConnector, DESConnect, DESConnector, IncorporationInformationConnect, IncorporationInformationConnector} +import connectors._ import enums.PAYEStatus import models._ import models.incorporation.IncorpStatusUpdate @@ -38,6 +38,7 @@ import uk.gov.hmrc.play.http.HeaderCarrier import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global +import scala.util.{Failure, Success, Try} import scala.util.control.NoStackTrace class RejectedIncorporationException(msg: String) extends NoStackTrace { @@ -50,7 +51,8 @@ class SubmissionService @Inject()(injSequenceMongoRepository: SequenceMongo, injDESConnector: DESConnector, injIncorprorationInformationConnector: IncorporationInformationConnector, injAuthConnector: AuthConnector, - injBusinessRegistrationConnector: BusinessRegistrationConnector) extends SubmissionSrv { + injBusinessRegistrationConnector: BusinessRegistrationConnector, + injCompanyRegistrationConnector: CompanyRegistrationConnector) extends SubmissionSrv { val sequenceRepository = injSequenceMongoRepository.store val registrationRepository = injRegistrationMongoRepository.store val desConnector = injDESConnector @@ -58,6 +60,7 @@ class SubmissionService @Inject()(injSequenceMongoRepository: SequenceMongo, val authConnector = injAuthConnector val auditConnector = MicroserviceAuditConnector val businessRegistrationConnector = injBusinessRegistrationConnector + val companyRegistrationConnector = injCompanyRegistrationConnector } trait SubmissionSrv { @@ -69,6 +72,7 @@ trait SubmissionSrv { val authConnector: AuthConnect val auditConnector: AuditConnector val businessRegistrationConnector: BusinessRegistrationConnect + val companyRegistrationConnector: CompanyRegistrationConnect private val REGIME = "paye" private val SUBSCRIBER = "SCRS" @@ -298,4 +302,13 @@ trait SubmissionSrv { val s = hc.headers.collect{case ("X-Session-ID", x) => x} if( s.nonEmpty ) s.head else throw new SessionIDNotExists } + + private[services] def fetchCtUtr(regId: String)(implicit hc: HeaderCarrier): Future[Option[String]] = { + companyRegistrationConnector.fetchCompanyRegistrationDocument(regId) map { response => + Try((response.json \ "acknowledgementReferences" \ "ctUtr").as[String]) match { + case Success(ctutr) => Some(ctutr) + case Failure(_) => None + } + } + } } diff --git a/test/services/SubmissionServiceSpec.scala b/test/services/SubmissionServiceSpec.scala index 3f629b3c..fffa295a 100644 --- a/test/services/SubmissionServiceSpec.scala +++ b/test/services/SubmissionServiceSpec.scala @@ -21,7 +21,7 @@ import java.time.LocalDate import common.exceptions.DBExceptions.MissingRegDocument import common.exceptions.RegistrationExceptions._ import common.exceptions.SubmissionExceptions._ -import connectors.{Authority, BusinessRegistrationConnector, DESConnector, IncorporationInformationConnector, UserIds} +import connectors._ import enums.PAYEStatus import models._ import models.submission._ @@ -31,7 +31,9 @@ import models.incorporation.IncorpStatusUpdate import org.joda.time.DateTime import org.mockito.ArgumentMatchers import org.mockito.Mockito._ +import play.api.libs.json.{JsValue, Json} import play.api.test.FakeRequest +import play.api.test.Helpers._ import uk.gov.hmrc.play.audit.http.connector.AuditConnector import uk.gov.hmrc.play.audit.http.connector.AuditResult.Success import uk.gov.hmrc.play.http.logging.SessionId @@ -45,6 +47,7 @@ class SubmissionServiceSpec extends PAYERegSpec { val mockIIConnector = mock[IncorporationInformationConnector] val mockAuditConnector = mock[AuditConnector] val mockBusinessRegistrationConnector = mock[BusinessRegistrationConnector] + val mockCompanyRegistrationConnector = mock[CompanyRegistrationConnector] implicit val hc = HeaderCarrier(sessionId = Some(SessionId("session-123"))) implicit val req = FakeRequest("GET", "/test-path") @@ -58,6 +61,7 @@ class SubmissionServiceSpec extends PAYERegSpec { override val authConnector = mockAuthConnector override val auditConnector = mockAuditConnector override val businessRegistrationConnector = mockBusinessRegistrationConnector + override val companyRegistrationConnector = mockCompanyRegistrationConnector } } @@ -462,4 +466,56 @@ class SubmissionServiceSpec extends PAYERegSpec { intercept[service.SessionIDNotExists](service.retrieveSessionID(HeaderCarrier())) } } + + "fetchCtUtr" should { + "return some ctutr" when { + "the ctutr is part of the CR doc" in new Setup { + val testJson = Json.parse( + """ + |{ + | "acknowledgementReferences": { + | "ctUtr" : "testCtUtr" + | } + |} + """.stripMargin + ) + + val okResponse = new HttpResponse { + override def status: Int = OK + override def json: JsValue = testJson + } + + when(mockCompanyRegistrationConnector.fetchCompanyRegistrationDocument(ArgumentMatchers.any())(ArgumentMatchers.any())) + .thenReturn(Future.successful(okResponse)) + + val result = await(service.fetchCtUtr("testRegId")) + result shouldBe Some("testCtUtr") + } + } + + "return none" when { + "the ctutr isn't part of the CR doc" in new Setup { + val testJson = Json.parse( + """ + |{ + | "acknowledgementReferences": { + | "invalidKey" : "testCtUtr" + | } + |} + """.stripMargin + ) + + val okResponse = new HttpResponse { + override def status: Int = OK + override def json: JsValue = testJson + } + + when(mockCompanyRegistrationConnector.fetchCompanyRegistrationDocument(ArgumentMatchers.any())(ArgumentMatchers.any())) + .thenReturn(Future.successful(okResponse)) + + val result = await(service.fetchCtUtr("testRegId")) + result shouldBe None + } + } + } } From a57e30ecd800f5be019b9a264bb6f812517ad81f Mon Sep 17 00:00:00 2001 From: "christopher.walker" Date: Wed, 3 May 2017 10:07:07 +0100 Subject: [PATCH 3/7] SCRS-6165 updated paye reg model to include a ct utr --- app/models/PAYERegistration.scala | 2 + conf/application.conf | 5 + it/api/CompanyDetailsISpec.scala | 4 + it/api/DirectorsISpec.scala | 4 + it/api/EmploymentISpec.scala | 4 + it/api/PAYEContactISpec.scala | 4 + it/api/PayeRegistrationISpec.scala | 2 + it/api/SICCodesISpec.scala | 4 + .../RegistrationControllerISpec.scala | 3 + .../TestEndpointControllerISpec.scala | 7 + .../RegistrationMongoRepositoryISpec.scala | 422 +++++++++++++++++- .../CompanyRegistrationConnectorSpec.scala | 14 +- test/fixtures/RegistrationFixture.scala | 2 +- test/models/PAYERegistrationSpec.scala | 178 ++++++++ 14 files changed, 623 insertions(+), 32 deletions(-) diff --git a/app/models/PAYERegistration.scala b/app/models/PAYERegistration.scala index 1d10e2ac..84c83e19 100644 --- a/app/models/PAYERegistration.scala +++ b/app/models/PAYERegistration.scala @@ -25,6 +25,7 @@ case class PAYERegistration(registrationID: String, internalID : String, acknowledgementReference: Option[String], crn: Option[String], + ctUtr: Option[String] = None, registrationConfirmation: Option[EmpRefNotification], formCreationTimestamp: String, eligibility: Option[Eligibility], @@ -44,6 +45,7 @@ object PAYERegistration extends { (__ \ "internalID").format[String] and (__ \ "acknowledgementReference").formatNullable[String] and (__ \ "crn").formatNullable[String] and + (__ \ "ctUtr").formatNullable[String] and (__ \ "registrationConfirmation").formatNullable[EmpRefNotification] and (__ \ "formCreationTimestamp").format[String] and (__ \ "eligibility").formatNullable[Eligibility] and diff --git a/conf/application.conf b/conf/application.conf index 11d36e42..2a9dfb2c 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -188,6 +188,11 @@ microservice { port = 9660 } + company-registration { + host = localhost + port = 9973 + } + paye-registration { host = localhost port = 9873 diff --git a/it/api/CompanyDetailsISpec.scala b/it/api/CompanyDetailsISpec.scala index 12a46fcd..af14c50f 100644 --- a/it/api/CompanyDetailsISpec.scala +++ b/it/api/CompanyDetailsISpec.scala @@ -85,6 +85,7 @@ class CompanyDetailsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -121,6 +122,7 @@ class CompanyDetailsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -165,6 +167,7 @@ class CompanyDetailsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -200,6 +203,7 @@ class CompanyDetailsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/api/DirectorsISpec.scala b/it/api/DirectorsISpec.scala index 04f22a77..0ee9d0d9 100644 --- a/it/api/DirectorsISpec.scala +++ b/it/api/DirectorsISpec.scala @@ -96,6 +96,7 @@ class DirectorsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -132,6 +133,7 @@ class DirectorsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -176,6 +178,7 @@ class DirectorsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -211,6 +214,7 @@ class DirectorsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/api/EmploymentISpec.scala b/it/api/EmploymentISpec.scala index 8c984f74..c91e14c1 100644 --- a/it/api/EmploymentISpec.scala +++ b/it/api/EmploymentISpec.scala @@ -86,6 +86,7 @@ class EmploymentISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -122,6 +123,7 @@ class EmploymentISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -166,6 +168,7 @@ class EmploymentISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -201,6 +204,7 @@ class EmploymentISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/api/PAYEContactISpec.scala b/it/api/PAYEContactISpec.scala index 5f37df3c..697c2e0e 100644 --- a/it/api/PAYEContactISpec.scala +++ b/it/api/PAYEContactISpec.scala @@ -84,6 +84,7 @@ class PAYEContactISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -120,6 +121,7 @@ class PAYEContactISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -164,6 +166,7 @@ class PAYEContactISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -199,6 +202,7 @@ class PAYEContactISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/api/PayeRegistrationISpec.scala b/it/api/PayeRegistrationISpec.scala index 6dcd56ea..463e3118 100644 --- a/it/api/PayeRegistrationISpec.scala +++ b/it/api/PayeRegistrationISpec.scala @@ -78,6 +78,7 @@ class PayeRegistrationISpec extends IntegrationSpecBase { Some(ackRef), None, None, + None, timestamp, None, PAYEStatus.draft, @@ -118,6 +119,7 @@ class PayeRegistrationISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/api/SICCodesISpec.scala b/it/api/SICCodesISpec.scala index b00dadf2..595c4ca2 100644 --- a/it/api/SICCodesISpec.scala +++ b/it/api/SICCodesISpec.scala @@ -80,6 +80,7 @@ class SICCodesISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -116,6 +117,7 @@ class SICCodesISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -160,6 +162,7 @@ class SICCodesISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -195,6 +198,7 @@ class SICCodesISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/controllers/RegistrationControllerISpec.scala b/it/controllers/RegistrationControllerISpec.scala index f16aea72..f904211e 100644 --- a/it/controllers/RegistrationControllerISpec.scala +++ b/it/controllers/RegistrationControllerISpec.scala @@ -88,6 +88,7 @@ class RegistrationControllerISpec extends IntegrationSpecBase { intId, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -150,6 +151,7 @@ class RegistrationControllerISpec extends IntegrationSpecBase { intId, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -174,6 +176,7 @@ class RegistrationControllerISpec extends IntegrationSpecBase { intId, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/controllers/TestEndpointControllerISpec.scala b/it/controllers/TestEndpointControllerISpec.scala index 300d3817..e5c21b2e 100644 --- a/it/controllers/TestEndpointControllerISpec.scala +++ b/it/controllers/TestEndpointControllerISpec.scala @@ -74,6 +74,7 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -98,6 +99,7 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef2"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -140,6 +142,7 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -164,6 +167,7 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef2"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -213,6 +217,7 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -238,6 +243,7 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -314,6 +320,7 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, + None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/repositories/RegistrationMongoRepositoryISpec.scala b/it/repositories/RegistrationMongoRepositoryISpec.scala index 3a115f2b..0577dc8e 100644 --- a/it/repositories/RegistrationMongoRepositoryISpec.scala +++ b/it/repositories/RegistrationMongoRepositoryISpec.scala @@ -1,5 +1,5 @@ /* - * Copyright 2016 HM Revenue & Customs + * Copyright 2017 HM Revenue & Customs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,26 +37,215 @@ class RegistrationMongoRepositoryISpec extends UnitSpec with MongoSpecSupport with BeforeAndAfterEach with ScalaFutures with Eventually with WithFakeApplication { private val date = LocalDate.of(2016, 12, 20) - private val address = Address("14 St Test Walk", "Testley", Some("Testford"), Some("Testshire"), Some("TE1 1ST"), None) - private val ppobAddress = Address("15 St Walk", "Testley", Some("Testford"), Some("Testshire"), None, Some("UK")) - private val businessContact = DigitalContactDetails(Some("test@email.com"), Some("012345"), Some("543210")) - private val companyDetails: CompanyDetails = CompanyDetails(companyName = "tstCcompany", tradingName = Some("tstTradingName"), roAddress = address, ppobAddress = ppobAddress, businessContactDetails = businessContact) - private val employmentDetails: Employment = Employment(employees = false, companyPension = None, subcontractors = false, date) - private val reg = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) - private val reg2 = PAYERegistration(registrationID = "AC234567", transactionID = "NN5678", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.held, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) + + private val address = Address( + "14 St Test Walk", + "Testley", + Some("Testford"), + Some("Testshire"), + Some("TE1 1ST"), + Some("UK") + ) + + private val ppobAddress = Address( + "15 St Walk", + "Testley", + Some("Testford"), + Some("Testshire"), + Some("TE4 1ST"), + Some("UK") + ) + private val businessContact = DigitalContactDetails( + Some("test@email.com"), + Some("012345"), + Some("543210") + ) + + private val companyDetails: CompanyDetails = CompanyDetails( + companyName = "tstCcompany", + tradingName = Some("tstTradingName"), + roAddress = address, + ppobAddress = ppobAddress, + businessContactDetails = businessContact + ) + + private val employmentDetails: Employment = Employment( + employees = false, + companyPension = None, + subcontractors = false, + firstPaymentDate= date + ) + + private val reg = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus") + ), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty) + + private val reg2 = PAYERegistration( + registrationID = "AC234567", + transactionID = "NN5678", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus") + ), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.held, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) // Company Details - private val regNoCompanyDetails = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = None, directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) - private val companyDetails2: CompanyDetails = CompanyDetails(companyName = "tstCcompany2", tradingName = Some("tstTradingName2"), roAddress = address, ppobAddress = ppobAddress, businessContactDetails = businessContact) - private val regUpdatedCompanyDetails = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails2), directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) + private val regNoCompanyDetails = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus") + ), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = None, + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) + + private val companyDetails2: CompanyDetails = CompanyDetails( + companyName = "tstCcompany2", + tradingName = Some("tstTradingName2"), + roAddress = address, + ppobAddress = ppobAddress, + businessContactDetails = businessContact + ) + + private val regUpdatedCompanyDetails = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus") + ), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails2), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) // Employment - private val regNoEmployment = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) - private val employmentDetails2: Employment = Employment(employees = true, companyPension = Some(false), subcontractors = true, date) - private val regUpdatedEmployment = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, Some(employmentDetails2), sicCodes = Seq.empty) + private val regNoEmployment = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus") + ), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) + private val employmentDetails2: Employment = Employment( + employees = true, + companyPension = Some(false), + subcontractors = true, + firstPaymentDate = date + ) + + private val regUpdatedEmployment = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus") + ), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = Some(employmentDetails2), + sicCodes = Seq.empty + ) // Directors - private val regNoDirectors = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) + private val regNoDirectors = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus" + )), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) + private val directors: Seq[Director] = Seq( Director( Name( @@ -77,18 +266,101 @@ class RegistrationMongoRepositoryISpec Some("SR000009C") ) ) - private val regUpdatedDirectors = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails), directors = directors, payeContact = None, None, sicCodes = Seq.empty) + private val regUpdatedDirectors = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus" + )), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = directors, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) //SIC Codes - private val regNoSICCodes = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) + private val regNoSICCodes = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus" + )), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) + private val sicCodes: Seq[SICCode] = Seq( SICCode(code = Some("123"), description = Some("consulting")), SICCode(code = None, description = Some("something")) ) - private val regUpdatedSICCodes = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, None, sicCodes = sicCodes) + + private val regUpdatedSICCodes = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus" + )), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = sicCodes + ) //PAYE Contact - private val regNoPAYEContact = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) + private val regNoPAYEContact = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus" + )), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) + private val payeContact = PAYEContact( contactDetails = PAYEContactDetails( name = "toto tata", @@ -100,15 +372,97 @@ class RegistrationMongoRepositoryISpec ), correspondenceAddress = Address("19 St Walk", "Testley CA", Some("Testford"), Some("Testshire"), Some("TE4 1ST")) ) - private val regUpdatedPAYEContact = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = Some(payeContact), None, sicCodes = Seq.empty) + + private val regUpdatedPAYEContact = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus" + )), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = Some(payeContact), + employment = None, + sicCodes = Seq.empty + ) //Completion Capacity - private val regNoCompletionCapacity = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) + private val regNoCompletionCapacity = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus" + )), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) private val completionCapacity = "Director" - private val regUpdatedCompletionCapacity = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.draft, completionCapacity = Some(completionCapacity), companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) + + private val regUpdatedCompletionCapacity = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus" + )), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.draft, + completionCapacity = Some(completionCapacity), + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) //Registration Status - private val regUpdatedRegistrationStatus = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.held, completionCapacity = None, companyDetails = Some(companyDetails), directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) + private val regUpdatedRegistrationStatus = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus" + )), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.held, + completionCapacity = None, + companyDetails = Some(companyDetails), + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) class Setup { lazy val mockMetrics = Play.current.injector.instanceOf[MetricsService] @@ -523,7 +877,27 @@ class RegistrationMongoRepositoryISpec } } - val clearedRegistration = PAYERegistration(registrationID = "AC123456", transactionID = "NN1234", internalID = "09876", acknowledgementReference = Some("testAckRef"), crn = None, registrationConfirmation = Some(EmpRefNotification(Some("testEmpRef"), "2017-01-01T12:00:00Z", "testStatus")), formCreationTimestamp = "timestamp", eligibility = Some(Eligibility(false, false)), status = PAYEStatus.held, completionCapacity = None, companyDetails = None, directors = Seq.empty, payeContact = None, None, sicCodes = Seq.empty) + val clearedRegistration = PAYERegistration( + registrationID = "AC123456", + transactionID = "NN1234", + internalID = "09876", + acknowledgementReference = Some("testAckRef"), + crn = None, + registrationConfirmation = Some(EmpRefNotification( + Some("testEmpRef"), + "2017-01-01T12:00:00Z", + "testStatus" + )), + formCreationTimestamp = "timestamp", + eligibility = Some(Eligibility(false, false)), + status = PAYEStatus.held, + completionCapacity = None, + companyDetails = None, + directors = Seq.empty, + payeContact = None, + employment = None, + sicCodes = Seq.empty + ) "Calling cleardownRegistration" should { "clear all information apart from Status and Ackref" in new Setup { diff --git a/test/connectors/CompanyRegistrationConnectorSpec.scala b/test/connectors/CompanyRegistrationConnectorSpec.scala index 92332a78..76e4263c 100644 --- a/test/connectors/CompanyRegistrationConnectorSpec.scala +++ b/test/connectors/CompanyRegistrationConnectorSpec.scala @@ -21,15 +21,15 @@ import mocks.WSHTTPMock import models.external.BusinessProfile import org.mockito.ArgumentMatchers import org.mockito.Mockito.when -import org.scalatestplus.play.guice.GuiceOneAppPerSuite import play.api.libs.json.{JsValue, Json} import uk.gov.hmrc.play.http.{ForbiddenException, HeaderCarrier, HttpResponse, NotFoundException} import uk.gov.hmrc.play.http.ws.WSHttp import play.api.test.Helpers._ +import uk.gov.hmrc.play.test.WithFakeApplication import scala.concurrent.Future -class CompanyRegistrationConnectorSpec extends PAYERegSpec with WSHTTPMock with GuiceOneAppPerSuite { +class CompanyRegistrationConnectorSpec extends PAYERegSpec with WSHTTPMock with WithFakeApplication { val testJson = Json.parse( """ @@ -39,11 +39,6 @@ class CompanyRegistrationConnectorSpec extends PAYERegSpec with WSHTTPMock with """.stripMargin ) - val okResponse = new HttpResponse { - override def status: Int = OK - override def json: JsValue = testJson - } - implicit val hc = HeaderCarrier() class Setup { @@ -56,6 +51,11 @@ class CompanyRegistrationConnectorSpec extends PAYERegSpec with WSHTTPMock with "fetchCompanyRegistrationDocument" should { "return an OK with JSON body" when { "given a valid regId" in new Setup { + val okResponse = new HttpResponse { + override def status: Int = OK + override def json: JsValue = testJson + } + mockHttpGet[HttpResponse]("testUrl", okResponse) val result = await(connector.fetchCompanyRegistrationDocument("testRegId")) diff --git a/test/fixtures/RegistrationFixture.scala b/test/fixtures/RegistrationFixture.scala index e21ffd34..4edfe674 100644 --- a/test/fixtures/RegistrationFixture.scala +++ b/test/fixtures/RegistrationFixture.scala @@ -94,6 +94,6 @@ trait RegistrationFixture { directors = validDirectors, payeContact = Some(validPAYEContact), employment = Some(validEmployment), - validSICCodes + sicCodes = validSICCodes ) } diff --git a/test/models/PAYERegistrationSpec.scala b/test/models/PAYERegistrationSpec.scala index a1bc5fde..49c51c06 100644 --- a/test/models/PAYERegistrationSpec.scala +++ b/test/models/PAYERegistrationSpec.scala @@ -37,6 +37,7 @@ class PAYERegistrationSpec extends UnitSpec with JsonFormatValidation { | "transactionID" : "NNASD9789F", | "internalID" : "09876", | "formCreationTimestamp":"2016-05-31", + | "ctUtr" : "testctUtr", | "registrationConfirmation" : { | "empRef":"testEmpRef", | "timestamp":"2017-01-01T12:00:00Z", @@ -133,6 +134,182 @@ class PAYERegistrationSpec extends UnitSpec with JsonFormatValidation { internalID = "09876", acknowledgementReference = None, crn = None, + ctUtr = Some("testctUtr"), + formCreationTimestamp = "2016-05-31", + eligibility = Some(Eligibility( + companyEligibility = false, + directorEligibility = false + )), + registrationConfirmation = Some(EmpRefNotification( + empRef = Some("testEmpRef"), + timestamp = "2017-01-01T12:00:00Z", + status = "testStatus" + )), + status = PAYEStatus.draft, + completionCapacity = Some("Director"), + companyDetails = Some( + CompanyDetails( + companyName = "Test Company", + tradingName = Some("Test Trading Name"), + Address("14 St Test Walk", "Testley", Some("Testford"), Some("Testshire"), Some("TE1 1ST"), Some("UK")), + Address("15 St Walk", "Testley", Some("Testford"), Some("Testshire"), Some("TE4 1ST"), Some("UK")), + DigitalContactDetails(Some("email@test.co.uk"), Some("999"), Some("00000")) + ) + ), + directors = Seq( + Director( + Name( + forename = Some("Thierry"), + otherForenames = Some("Dominique"), + surname = Some("Henry"), + title = Some("Sir") + ), + Some("SR123456C") + ), + Director( + Name( + forename = Some("David"), + otherForenames = Some("Jesus"), + surname = Some("Trezeguet"), + title = Some("Mr") + ), + Some("SR000009C") + ) + ), + payeContact = Some( + PAYEContact( + contactDetails = PAYEContactDetails( + name = "toto tata", + digitalContactDetails = DigitalContactDetails( + Some("payeemail@test.co.uk"), + Some("654"), + Some("12345") + ) + ), + correspondenceAddress = Address("19 St Walk", "Testley CA", Some("Testford"), Some("Testshire"), Some("TE4 1ST"), Some("UK")) + ) + ), + employment = Some(Employment(employees = true, Some(true), subcontractors = true, firstPaymentDate = date)), + sicCodes = Seq( + SICCode(code = Some("666"), description = Some("demolition")), + SICCode(code = None, description = Some("laundring")) + ) + ) + + Json.fromJson[PAYERegistration](json) shouldBe JsSuccess(tstPAYERegistration) + } + + "complete successfully from full Json except the ct utr" in { + + val date = LocalDate.of(2016, 12, 20) + + val json = Json.parse( + s""" + |{ + | "registrationID":"12345", + | "transactionID" : "NNASD9789F", + | "internalID" : "09876", + | "formCreationTimestamp":"2016-05-31", + | "registrationConfirmation" : { + | "empRef":"testEmpRef", + | "timestamp":"2017-01-01T12:00:00Z", + | "status":"testStatus" + | }, + | "eligibility" : { + | "companyEligibility" : false, + | "directorEligibility" : false + | }, + | "status":"draft", + | "completionCapacity":"Director", + | "companyDetails": + | { + | "companyName":"Test Company", + | "tradingName":"Test Trading Name", + | "roAddress": { + | "line1":"14 St Test Walk", + | "line2":"Testley", + | "line3":"Testford", + | "line4":"Testshire", + | "postCode":"TE1 1ST", + | "country":"UK" + | }, + | "ppobAddress": { + | "line1":"15 St Walk", + | "line2":"Testley", + | "line3":"Testford", + | "line4":"Testshire", + | "postCode":"TE4 1ST", + | "country":"UK" + | }, + | "businessContactDetails": { + | "email":"email@test.co.uk", + | "phoneNumber":"999", + | "mobileNumber":"00000" + | } + | }, + | "directors" : [ + | { + | "nino":"SR123456C", + | "director": { + | "forename":"Thierry", + | "other_forenames":"Dominique", + | "surname":"Henry", + | "title":"Sir" + | } + | }, + | { + | "nino":"SR000009C", + | "director": { + | "forename":"David", + | "other_forenames":"Jesus", + | "surname":"Trezeguet", + | "title":"Mr" + | } + | } + | ], + | "payeContact": { + | "contactDetails": { + | "name": "toto tata", + | "digitalContactDetails": { + | "email": "payeemail@test.co.uk", + | "phoneNumber": "654", + | "mobileNumber": "12345" + | } + | }, + | "correspondenceAddress": { + | "line1":"19 St Walk", + | "line2":"Testley CA", + | "line3":"Testford", + | "line4":"Testshire", + | "postCode":"TE4 1ST", + | "country":"UK" + | } + | }, + | "employment": { + | "first-payment-date": "$date", + | "cis": true, + | "employees": true, + | "ocpn": true + | }, + | "sicCodes": [ + | { + | "code":"666", + | "description":"demolition" + | }, + | { + | "description":"laundring" + | } + | ] + |} + """.stripMargin) + + val tstPAYERegistration = PAYERegistration( + registrationID = "12345", + transactionID = "NNASD9789F", + internalID = "09876", + acknowledgementReference = None, + crn = None, + ctUtr = None, formCreationTimestamp = "2016-05-31", eligibility = Some(Eligibility( companyEligibility = false, @@ -217,6 +394,7 @@ class PAYERegistrationSpec extends UnitSpec with JsonFormatValidation { internalID = "09876", acknowledgementReference = None, crn = None, + ctUtr = None, registrationConfirmation = None, formCreationTimestamp = "2016-05-31", eligibility = None, From 48043c982104f4b37550776c71aa31a8326b4cde Mon Sep 17 00:00:00 2001 From: "christopher.walker" Date: Wed, 3 May 2017 10:44:56 +0100 Subject: [PATCH 4/7] removed ctutr from paye model --- app/models/PAYERegistration.scala | 2 - it/api/CompanyDetailsISpec.scala | 4 - it/api/DirectorsISpec.scala | 4 - it/api/EmploymentISpec.scala | 4 - it/api/PAYEContactISpec.scala | 4 - it/api/PayeRegistrationISpec.scala | 2 - it/api/SICCodesISpec.scala | 4 - .../RegistrationControllerISpec.scala | 3 - .../TestEndpointControllerISpec.scala | 7 - test/models/PAYERegistrationSpec.scala | 178 ------------------ 10 files changed, 212 deletions(-) diff --git a/app/models/PAYERegistration.scala b/app/models/PAYERegistration.scala index 84c83e19..1d10e2ac 100644 --- a/app/models/PAYERegistration.scala +++ b/app/models/PAYERegistration.scala @@ -25,7 +25,6 @@ case class PAYERegistration(registrationID: String, internalID : String, acknowledgementReference: Option[String], crn: Option[String], - ctUtr: Option[String] = None, registrationConfirmation: Option[EmpRefNotification], formCreationTimestamp: String, eligibility: Option[Eligibility], @@ -45,7 +44,6 @@ object PAYERegistration extends { (__ \ "internalID").format[String] and (__ \ "acknowledgementReference").formatNullable[String] and (__ \ "crn").formatNullable[String] and - (__ \ "ctUtr").formatNullable[String] and (__ \ "registrationConfirmation").formatNullable[EmpRefNotification] and (__ \ "formCreationTimestamp").format[String] and (__ \ "eligibility").formatNullable[Eligibility] and diff --git a/it/api/CompanyDetailsISpec.scala b/it/api/CompanyDetailsISpec.scala index af14c50f..12a46fcd 100644 --- a/it/api/CompanyDetailsISpec.scala +++ b/it/api/CompanyDetailsISpec.scala @@ -85,7 +85,6 @@ class CompanyDetailsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -122,7 +121,6 @@ class CompanyDetailsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -167,7 +165,6 @@ class CompanyDetailsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -203,7 +200,6 @@ class CompanyDetailsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/api/DirectorsISpec.scala b/it/api/DirectorsISpec.scala index 0ee9d0d9..04f22a77 100644 --- a/it/api/DirectorsISpec.scala +++ b/it/api/DirectorsISpec.scala @@ -96,7 +96,6 @@ class DirectorsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -133,7 +132,6 @@ class DirectorsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -178,7 +176,6 @@ class DirectorsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -214,7 +211,6 @@ class DirectorsISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/api/EmploymentISpec.scala b/it/api/EmploymentISpec.scala index c91e14c1..8c984f74 100644 --- a/it/api/EmploymentISpec.scala +++ b/it/api/EmploymentISpec.scala @@ -86,7 +86,6 @@ class EmploymentISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -123,7 +122,6 @@ class EmploymentISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -168,7 +166,6 @@ class EmploymentISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -204,7 +201,6 @@ class EmploymentISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/api/PAYEContactISpec.scala b/it/api/PAYEContactISpec.scala index 697c2e0e..5f37df3c 100644 --- a/it/api/PAYEContactISpec.scala +++ b/it/api/PAYEContactISpec.scala @@ -84,7 +84,6 @@ class PAYEContactISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -121,7 +120,6 @@ class PAYEContactISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -166,7 +164,6 @@ class PAYEContactISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -202,7 +199,6 @@ class PAYEContactISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/api/PayeRegistrationISpec.scala b/it/api/PayeRegistrationISpec.scala index 463e3118..6dcd56ea 100644 --- a/it/api/PayeRegistrationISpec.scala +++ b/it/api/PayeRegistrationISpec.scala @@ -78,7 +78,6 @@ class PayeRegistrationISpec extends IntegrationSpecBase { Some(ackRef), None, None, - None, timestamp, None, PAYEStatus.draft, @@ -119,7 +118,6 @@ class PayeRegistrationISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/api/SICCodesISpec.scala b/it/api/SICCodesISpec.scala index 595c4ca2..b00dadf2 100644 --- a/it/api/SICCodesISpec.scala +++ b/it/api/SICCodesISpec.scala @@ -80,7 +80,6 @@ class SICCodesISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -117,7 +116,6 @@ class SICCodesISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -162,7 +160,6 @@ class SICCodesISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -198,7 +195,6 @@ class SICCodesISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/controllers/RegistrationControllerISpec.scala b/it/controllers/RegistrationControllerISpec.scala index f904211e..f16aea72 100644 --- a/it/controllers/RegistrationControllerISpec.scala +++ b/it/controllers/RegistrationControllerISpec.scala @@ -88,7 +88,6 @@ class RegistrationControllerISpec extends IntegrationSpecBase { intId, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -151,7 +150,6 @@ class RegistrationControllerISpec extends IntegrationSpecBase { intId, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -176,7 +174,6 @@ class RegistrationControllerISpec extends IntegrationSpecBase { intId, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/it/controllers/TestEndpointControllerISpec.scala b/it/controllers/TestEndpointControllerISpec.scala index e5c21b2e..300d3817 100644 --- a/it/controllers/TestEndpointControllerISpec.scala +++ b/it/controllers/TestEndpointControllerISpec.scala @@ -74,7 +74,6 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -99,7 +98,6 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef2"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -142,7 +140,6 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -167,7 +164,6 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef2"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -217,7 +213,6 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -243,7 +238,6 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", @@ -320,7 +314,6 @@ class TestEndpointControllerISpec extends IntegrationSpecBase { intID, Some("testAckRef"), None, - None, Some(EmpRefNotification( Some("testEmpRef"), "2017-01-01T12:00:00Z", diff --git a/test/models/PAYERegistrationSpec.scala b/test/models/PAYERegistrationSpec.scala index 49c51c06..a1bc5fde 100644 --- a/test/models/PAYERegistrationSpec.scala +++ b/test/models/PAYERegistrationSpec.scala @@ -37,7 +37,6 @@ class PAYERegistrationSpec extends UnitSpec with JsonFormatValidation { | "transactionID" : "NNASD9789F", | "internalID" : "09876", | "formCreationTimestamp":"2016-05-31", - | "ctUtr" : "testctUtr", | "registrationConfirmation" : { | "empRef":"testEmpRef", | "timestamp":"2017-01-01T12:00:00Z", @@ -134,182 +133,6 @@ class PAYERegistrationSpec extends UnitSpec with JsonFormatValidation { internalID = "09876", acknowledgementReference = None, crn = None, - ctUtr = Some("testctUtr"), - formCreationTimestamp = "2016-05-31", - eligibility = Some(Eligibility( - companyEligibility = false, - directorEligibility = false - )), - registrationConfirmation = Some(EmpRefNotification( - empRef = Some("testEmpRef"), - timestamp = "2017-01-01T12:00:00Z", - status = "testStatus" - )), - status = PAYEStatus.draft, - completionCapacity = Some("Director"), - companyDetails = Some( - CompanyDetails( - companyName = "Test Company", - tradingName = Some("Test Trading Name"), - Address("14 St Test Walk", "Testley", Some("Testford"), Some("Testshire"), Some("TE1 1ST"), Some("UK")), - Address("15 St Walk", "Testley", Some("Testford"), Some("Testshire"), Some("TE4 1ST"), Some("UK")), - DigitalContactDetails(Some("email@test.co.uk"), Some("999"), Some("00000")) - ) - ), - directors = Seq( - Director( - Name( - forename = Some("Thierry"), - otherForenames = Some("Dominique"), - surname = Some("Henry"), - title = Some("Sir") - ), - Some("SR123456C") - ), - Director( - Name( - forename = Some("David"), - otherForenames = Some("Jesus"), - surname = Some("Trezeguet"), - title = Some("Mr") - ), - Some("SR000009C") - ) - ), - payeContact = Some( - PAYEContact( - contactDetails = PAYEContactDetails( - name = "toto tata", - digitalContactDetails = DigitalContactDetails( - Some("payeemail@test.co.uk"), - Some("654"), - Some("12345") - ) - ), - correspondenceAddress = Address("19 St Walk", "Testley CA", Some("Testford"), Some("Testshire"), Some("TE4 1ST"), Some("UK")) - ) - ), - employment = Some(Employment(employees = true, Some(true), subcontractors = true, firstPaymentDate = date)), - sicCodes = Seq( - SICCode(code = Some("666"), description = Some("demolition")), - SICCode(code = None, description = Some("laundring")) - ) - ) - - Json.fromJson[PAYERegistration](json) shouldBe JsSuccess(tstPAYERegistration) - } - - "complete successfully from full Json except the ct utr" in { - - val date = LocalDate.of(2016, 12, 20) - - val json = Json.parse( - s""" - |{ - | "registrationID":"12345", - | "transactionID" : "NNASD9789F", - | "internalID" : "09876", - | "formCreationTimestamp":"2016-05-31", - | "registrationConfirmation" : { - | "empRef":"testEmpRef", - | "timestamp":"2017-01-01T12:00:00Z", - | "status":"testStatus" - | }, - | "eligibility" : { - | "companyEligibility" : false, - | "directorEligibility" : false - | }, - | "status":"draft", - | "completionCapacity":"Director", - | "companyDetails": - | { - | "companyName":"Test Company", - | "tradingName":"Test Trading Name", - | "roAddress": { - | "line1":"14 St Test Walk", - | "line2":"Testley", - | "line3":"Testford", - | "line4":"Testshire", - | "postCode":"TE1 1ST", - | "country":"UK" - | }, - | "ppobAddress": { - | "line1":"15 St Walk", - | "line2":"Testley", - | "line3":"Testford", - | "line4":"Testshire", - | "postCode":"TE4 1ST", - | "country":"UK" - | }, - | "businessContactDetails": { - | "email":"email@test.co.uk", - | "phoneNumber":"999", - | "mobileNumber":"00000" - | } - | }, - | "directors" : [ - | { - | "nino":"SR123456C", - | "director": { - | "forename":"Thierry", - | "other_forenames":"Dominique", - | "surname":"Henry", - | "title":"Sir" - | } - | }, - | { - | "nino":"SR000009C", - | "director": { - | "forename":"David", - | "other_forenames":"Jesus", - | "surname":"Trezeguet", - | "title":"Mr" - | } - | } - | ], - | "payeContact": { - | "contactDetails": { - | "name": "toto tata", - | "digitalContactDetails": { - | "email": "payeemail@test.co.uk", - | "phoneNumber": "654", - | "mobileNumber": "12345" - | } - | }, - | "correspondenceAddress": { - | "line1":"19 St Walk", - | "line2":"Testley CA", - | "line3":"Testford", - | "line4":"Testshire", - | "postCode":"TE4 1ST", - | "country":"UK" - | } - | }, - | "employment": { - | "first-payment-date": "$date", - | "cis": true, - | "employees": true, - | "ocpn": true - | }, - | "sicCodes": [ - | { - | "code":"666", - | "description":"demolition" - | }, - | { - | "description":"laundring" - | } - | ] - |} - """.stripMargin) - - val tstPAYERegistration = PAYERegistration( - registrationID = "12345", - transactionID = "NNASD9789F", - internalID = "09876", - acknowledgementReference = None, - crn = None, - ctUtr = None, formCreationTimestamp = "2016-05-31", eligibility = Some(Eligibility( companyEligibility = false, @@ -394,7 +217,6 @@ class PAYERegistrationSpec extends UnitSpec with JsonFormatValidation { internalID = "09876", acknowledgementReference = None, crn = None, - ctUtr = None, registrationConfirmation = None, formCreationTimestamp = "2016-05-31", eligibility = None, From d36ce394358b73180114f65394e1d48ae2560554 Mon Sep 17 00:00:00 2001 From: "christopher.walker" Date: Wed, 3 May 2017 14:26:08 +0100 Subject: [PATCH 5/7] updated its --- app/services/SubmissionService.scala | 2 + .../RegistrationControllerISpec.scala | 95 ++++++++++++++++++- test/services/SubmissionServiceSpec.scala | 16 ++++ 3 files changed, 112 insertions(+), 1 deletion(-) diff --git a/app/services/SubmissionService.scala b/app/services/SubmissionService.scala index c7dec20b..1f40062b 100644 --- a/app/services/SubmissionService.scala +++ b/app/services/SubmissionService.scala @@ -86,6 +86,7 @@ trait SubmissionSrv { updatePAYERegistrationDocument(regId, PAYEStatus.cancelled) throw ex } + ctutr = if(incUpdate.isEmpty) fetchCtUtr(regId) else Future.successful(None) submission <- buildADesSubmission(regId, incUpdate) _ <- desConnector.submitToDES(submission) _ <- auditDESSubmission(regId, incUpdate.fold("partial")(_ => "full"), Json.toJson[DESSubmission](submission).as[JsObject]) @@ -96,6 +97,7 @@ trait SubmissionSrv { def submitTopUpToDES(regId: String, incorpStatusUpdate: IncorpStatusUpdate)(implicit hc: HeaderCarrier): Future[PAYEStatus.Value] = { for { + ctutr <- fetchCtUtr(regId) desSubmission <- buildTopUpDESSubmission(regId, incorpStatusUpdate) _ <- desConnector.submitToDES(desSubmission) _ <- auditDESTopUp(regId, Json.toJson[DESSubmission](desSubmission).as[JsObject]) diff --git a/it/controllers/RegistrationControllerISpec.scala b/it/controllers/RegistrationControllerISpec.scala index f16aea72..bc78bd30 100644 --- a/it/controllers/RegistrationControllerISpec.scala +++ b/it/controllers/RegistrationControllerISpec.scala @@ -51,7 +51,9 @@ class RegistrationControllerISpec extends IntegrationSpecBase { "microservice.services.incorporation-information.host" -> s"$mockHost", "microservice.services.incorporation-information.port" -> s"$mockPort", "microservice.services.business-registration.host" -> s"$mockHost", - "microservice.services.business-registration.port" -> s"$mockPort" + "microservice.services.business-registration.port" -> s"$mockPort", + "microservice.services.company-registration.host" -> s"$mockHost", + "microservice.services.company-registration.port" -> s"$mockPort" ) override implicit lazy val app: Application = new GuiceApplicationBuilder() @@ -471,6 +473,21 @@ class RegistrationControllerISpec extends IntegrationSpecBase { "return a 200 with a crn" in new Setup { setupSimpleAuthMocks() + stubFor(get(urlMatching(s"/company-registration/corporation-tax-registration/12345/corporation-tax-registration")) + .willReturn( + aResponse() + .withStatus(200) + .withBody( + """{ + | "acknowledgementReferences" : { + | "ctUtr" : "testCtUtr" + | } + |} + |""".stripMargin + ) + ) + ) + stubFor(post(urlMatching("/business-registration/pay-as-you-earn")) .willReturn( aResponse(). @@ -491,6 +508,21 @@ class RegistrationControllerISpec extends IntegrationSpecBase { "return a 404 status when registration is not found" in new Setup { setupSimpleAuthMocks() + stubFor(get(urlMatching(s"/company-registration/corporation-tax-registration/12345/corporation-tax-registration")) + .willReturn( + aResponse() + .withStatus(200) + .withBody( + """{ + | "acknowledgementReferences" : { + | "ctUtr" : "testCtUtr" + | } + |} + |""".stripMargin + ) + ) + ) + val jsonIncorpStatusUpdate2 = Json.parse( s""" |{ @@ -522,6 +554,21 @@ class RegistrationControllerISpec extends IntegrationSpecBase { "return a 500 status when registration is already submitted" in new Setup { setupSimpleAuthMocks() + stubFor(get(urlMatching(s"/company-registration/corporation-tax-registration/12345/corporation-tax-registration")) + .willReturn( + aResponse() + .withStatus(200) + .withBody( + """{ + | "acknowledgementReferences" : { + | "ctUtr" : "testCtUtr" + | } + |} + |""".stripMargin + ) + ) + ) + await(repository.insert(processedTopUpSubmission)) await(client(s"test-only/feature-flag/desServiceFeature/true").get()) @@ -534,6 +581,22 @@ class RegistrationControllerISpec extends IntegrationSpecBase { "return a 500 status when registration is not yet submitted with partial" in new Setup { setupSimpleAuthMocks() + + stubFor(get(urlMatching(s"/company-registration/corporation-tax-registration/12345/corporation-tax-registration")) + .willReturn( + aResponse() + .withStatus(200) + .withBody( + """{ + | "acknowledgementReferences" : { + | "ctUtr" : "testCtUtr" + | } + |} + |""".stripMargin + ) + ) + ) + await(repository.insert(submission)) await(client(s"test-only/feature-flag/desServiceFeature/true").get()) @@ -551,6 +614,21 @@ class RegistrationControllerISpec extends IntegrationSpecBase { setupSimpleAuthMocks() + stubFor(get(urlMatching(s"/company-registration/corporation-tax-registration/12345/corporation-tax-registration")) + .willReturn( + aResponse() + .withStatus(200) + .withBody( + """{ + | "acknowledgementReferences" : { + | "ctUtr" : "testCtUtr" + | } + |} + |""".stripMargin + ) + ) + ) + stubFor(post(urlMatching("/business-registration/pay-as-you-earn")) .willReturn( aResponse(). @@ -572,6 +650,21 @@ class RegistrationControllerISpec extends IntegrationSpecBase { setupSimpleAuthMocks() + stubFor(get(urlMatching(s"/company-registration/corporation-tax-registration/12345/corporation-tax-registration")) + .willReturn( + aResponse() + .withStatus(200) + .withBody( + """{ + | "acknowledgementReferences" : { + | "ctUtr" : "testCtUtr" + | } + |} + |""".stripMargin + ) + ) + ) + stubFor(post(urlMatching("/business-registration/pay-as-you-earn")) .willReturn( aResponse(). diff --git a/test/services/SubmissionServiceSpec.scala b/test/services/SubmissionServiceSpec.scala index fffa295a..0ae48e19 100644 --- a/test/services/SubmissionServiceSpec.scala +++ b/test/services/SubmissionServiceSpec.scala @@ -421,6 +421,22 @@ class SubmissionServiceSpec extends PAYERegSpec { "Calling submitTopUpToDES" should { "return the PAYE status" in new Setup { + val okResponse = new HttpResponse { + override def status: Int = OK + override def json: JsValue = Json.parse( + """ + |{ + | "acknowledgementReferences" : { + | "ctUtr" : "testCtUtr" + | } + |} + """.stripMargin + ) + } + + when(mockCompanyRegistrationConnector.fetchCompanyRegistrationDocument(ArgumentMatchers.any())(ArgumentMatchers.any())) + .thenReturn(Future.successful(okResponse)) + when(mockRegistrationRepository.retrieveAcknowledgementReference(ArgumentMatchers.anyString())) .thenReturn(Future.successful(Some("ackRef"))) From 73cc1d47dcf6a4e6da20e6cb86a27d636f939c2f Mon Sep 17 00:00:00 2001 From: "christopher.walker" Date: Thu, 4 May 2017 09:23:37 +0100 Subject: [PATCH 6/7] SCRS-6165 updated ITests --- app/audit/DesSubmissionAuditEventDetail.scala | 8 ++++- app/services/SubmissionService.scala | 30 +++++++++++-------- .../RegistrationControllerISpec.scala | 15 ++++++++++ .../DesSubmissionAuditEventDetailSpec.scala | 1 + test/services/SubmissionServiceSpec.scala | 16 +++++----- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/app/audit/DesSubmissionAuditEventDetail.scala b/app/audit/DesSubmissionAuditEventDetail.scala index 7c58cb55..2c8efab5 100644 --- a/app/audit/DesSubmissionAuditEventDetail.scala +++ b/app/audit/DesSubmissionAuditEventDetail.scala @@ -22,6 +22,7 @@ import uk.gov.hmrc.play.http.HeaderCarrier case class DesSubmissionAuditEventDetail(externalId: String, authProviderId: String, regId: String, + ctutr: Option[String], desSubmissionState: String, jsSubmission: JsObject) @@ -32,13 +33,18 @@ object DesSubmissionAuditEventDetail { implicit val writes = new Writes[DesSubmissionAuditEventDetail] { def writes(detail: DesSubmissionAuditEventDetail) = { val regMetadata = Json.obj("businessType" -> "Limited company") + val ctutrTuple = detail.ctutr map( utr => + Json.obj("ctutr" -> utr) + ) - Json.obj( + val event = Json.obj( EXTERNAL_ID -> detail.externalId, AUTH_PROVIDER_ID -> detail.authProviderId, JOURNEY_ID -> detail.regId, DES_SUBMISSION_STATE -> detail.desSubmissionState ) ++ detail.jsSubmission + + if(ctutrTuple.isDefined) event ++ ctutrTuple.get else event } } } diff --git a/app/services/SubmissionService.scala b/app/services/SubmissionService.scala index 1f40062b..a7765d86 100644 --- a/app/services/SubmissionService.scala +++ b/app/services/SubmissionService.scala @@ -86,10 +86,13 @@ trait SubmissionSrv { updatePAYERegistrationDocument(regId, PAYEStatus.cancelled) throw ex } - ctutr = if(incUpdate.isEmpty) fetchCtUtr(regId) else Future.successful(None) - submission <- buildADesSubmission(regId, incUpdate) + ctutr <- incUpdate match { + case Some(_) => fetchCtUtr(regId) + case _ => Future.successful(None) + } + submission <- buildADesSubmission(regId, incUpdate, ctutr) _ <- desConnector.submitToDES(submission) - _ <- auditDESSubmission(regId, incUpdate.fold("partial")(_ => "full"), Json.toJson[DESSubmission](submission).as[JsObject]) + _ <- auditDESSubmission(regId, incUpdate.fold("partial")(_ => "full"), Json.toJson[DESSubmission](submission).as[JsObject], ctutr) updatedStatus = incUpdate.fold(PAYEStatus.held)(_ => PAYEStatus.submitted) _ <- updatePAYERegistrationDocument(regId, updatedStatus) } yield ackRef @@ -97,7 +100,6 @@ trait SubmissionSrv { def submitTopUpToDES(regId: String, incorpStatusUpdate: IncorpStatusUpdate)(implicit hc: HeaderCarrier): Future[PAYEStatus.Value] = { for { - ctutr <- fetchCtUtr(regId) desSubmission <- buildTopUpDESSubmission(regId, incorpStatusUpdate) _ <- desConnector.submitToDES(desSubmission) _ <- auditDESTopUp(regId, Json.toJson[DESSubmission](desSubmission).as[JsObject]) @@ -132,15 +134,15 @@ trait SubmissionSrv { .map(ref => f"BRPY$ref%011d") } - private[services] def buildADesSubmission(regId: String, incorpStatusUpdate: Option[IncorpStatusUpdate])(implicit hc: HeaderCarrier): Future[DESSubmissionModel] = { + private[services] def buildADesSubmission(regId: String, incorpStatusUpdate: Option[IncorpStatusUpdate], ctutr: Option[String])(implicit hc: HeaderCarrier): Future[DESSubmissionModel] = { registrationRepository.retrieveRegistration(regId) flatMap { case Some(payeReg) if payeReg.status == PAYEStatus.draft => incorpStatusUpdate match { case Some(statusUpdate) => Logger.info("[SubmissionService] - [buildPartialOrFullDesSubmission]: building a full DES submission") - payeReg2DESSubmission(payeReg, DateTime.now(DateTimeZone.UTC), statusUpdate.crn) + payeReg2DESSubmission(payeReg, DateTime.now(DateTimeZone.UTC), statusUpdate.crn, ctutr) case None => Logger.info("[SubmissionService] - [buildPartialOrFullDesSubmission]: building a partial DES submission") - payeReg2DESSubmission(payeReg, DateTime.now(DateTimeZone.UTC), None) + payeReg2DESSubmission(payeReg, DateTime.now(DateTimeZone.UTC), None, ctutr) } case Some(payeReg) if payeReg.status == PAYEStatus.invalid => throw new InvalidRegistrationException(regId) case None => @@ -171,7 +173,8 @@ trait SubmissionSrv { } } - private[services] def payeReg2DESSubmission(payeReg: PAYERegistration, timestamp: DateTime, incorpUpdateCrn: Option[String])(implicit hc: HeaderCarrier): Future[DESSubmissionModel] = { + private[services] def payeReg2DESSubmission(payeReg: PAYERegistration, timestamp: DateTime, incorpUpdateCrn: Option[String], ctutr: Option[String]) + (implicit hc: HeaderCarrier): Future[DESSubmissionModel] = { val companyDetails = payeReg.companyDetails.getOrElse { throw new CompanyDetailsNotDefinedException } @@ -186,7 +189,7 @@ trait SubmissionSrv { DESSubmissionModel( acknowledgementReference = ackRef, metaData = desMetaData, - limitedCompany = buildDESLimitedCompany(companyDetails, payeReg.sicCodes, incorpUpdateCrn, payeReg.directors, payeReg.employment), + limitedCompany = buildDESLimitedCompany(companyDetails, payeReg.sicCodes, incorpUpdateCrn, payeReg.directors, payeReg.employment, ctutr), employingPeople = buildDESEmployingPeople(payeReg.registrationID, payeReg.employment, payeReg.payeContact) ) } @@ -238,9 +241,10 @@ trait SubmissionSrv { sicCodes: Seq[SICCode], incorpUpdateCrn: Option[String], directors: Seq[Director], - employment: Option[Employment]): DESLimitedCompany = { + employment: Option[Employment], + ctutr: Option[String]): DESLimitedCompany = { DESLimitedCompany( - companyUTR = None, + companyUTR = ctutr, companiesHouseCompanyName = companyDetails.companyName, nameOfBusiness = companyDetails.tradingName, businessAddress = companyDetails.ppobAddress, @@ -267,13 +271,13 @@ trait SubmissionSrv { ) } - private[services] def auditDESSubmission(regId: String, desSubmissionState: String, jsSubmission: JsObject)(implicit hc: HeaderCarrier, req: Request[AnyContent]) = { + private[services] def auditDESSubmission(regId: String, desSubmissionState: String, jsSubmission: JsObject, ctutr: Option[String])(implicit hc: HeaderCarrier, req: Request[AnyContent]) = { for { authority <- authConnector.getCurrentAuthority userDetails <- authConnector.getUserDetails authProviderId = userDetails.get.authProviderId } yield { - val event = new DesSubmissionEvent(DesSubmissionAuditEventDetail(authority.get.ids.externalId, authProviderId, regId, desSubmissionState, jsSubmission)) + val event = new DesSubmissionEvent(DesSubmissionAuditEventDetail(authority.get.ids.externalId, authProviderId, regId, ctutr, desSubmissionState, jsSubmission)) auditConnector.sendEvent(event) } } diff --git a/it/controllers/RegistrationControllerISpec.scala b/it/controllers/RegistrationControllerISpec.scala index bc78bd30..01a45f7f 100644 --- a/it/controllers/RegistrationControllerISpec.scala +++ b/it/controllers/RegistrationControllerISpec.scala @@ -282,6 +282,21 @@ class RegistrationControllerISpec extends IntegrationSpecBase { "return a 200 with an ack ref when a full DES submission completes successfully" in new Setup { setupSimpleAuthMocks() + stubFor(get(urlMatching(s"/company-registration/corporation-tax-registration/12345/corporation-tax-registration")) + .willReturn( + aResponse() + .withStatus(200) + .withBody( + """{ + | "acknowledgementReferences" : { + | "ctUtr" : "testCtUtr" + | } + |} + |""".stripMargin + ) + ) + ) + stubFor(post(urlMatching("/business-registration/pay-as-you-earn")) .willReturn( aResponse(). diff --git a/test/audit/DesSubmissionAuditEventDetailSpec.scala b/test/audit/DesSubmissionAuditEventDetailSpec.scala index 266bcff0..76a3a036 100644 --- a/test/audit/DesSubmissionAuditEventDetailSpec.scala +++ b/test/audit/DesSubmissionAuditEventDetailSpec.scala @@ -209,6 +209,7 @@ class DesSubmissionAuditEventDetailSpec extends UnitSpec { externalId, authProviderId, regId, + None, desSubmissionState, Json.toJson[DESSubmission](validPartialDESSubmissionModel).as[JsObject] ) diff --git a/test/services/SubmissionServiceSpec.scala b/test/services/SubmissionServiceSpec.scala index 0ae48e19..9dbbeff5 100644 --- a/test/services/SubmissionServiceSpec.scala +++ b/test/services/SubmissionServiceSpec.scala @@ -274,7 +274,7 @@ class SubmissionServiceSpec extends PAYERegSpec { when(mockAuthConnector.getCurrentAuthority()(ArgumentMatchers.any())) .thenReturn(Future.successful(Some(Authority("/test", "cred-123", "/test-user", UserIds("Int-xxx", "Ext-xxx"))))) - val result = await(service.payeReg2DESSubmission(validRegistration, DateTime.parse("2017-01-01"), None)) + val result = await(service.payeReg2DESSubmission(validRegistration, DateTime.parse("2017-01-01"), None, None)) result shouldBe validPartialDESSubmissionModel } @@ -285,20 +285,20 @@ class SubmissionServiceSpec extends PAYERegSpec { when(mockAuthConnector.getCurrentAuthority()(ArgumentMatchers.any())) .thenReturn(Future.successful(Some(Authority("/test", "cred-123", "/test-user", UserIds("Int-xxx", "Ext-xxx"))))) - val result = await(service.payeReg2DESSubmission(validRegistration, DateTime.parse("2017-01-01"), Some("OC123456"))) + val result = await(service.payeReg2DESSubmission(validRegistration, DateTime.parse("2017-01-01"), Some("OC123456"), None)) result shouldBe validPartialDESSubmissionModel.copy(limitedCompany = validDESLimitedCompanyWithoutCRN.copy(crn = Some("OC123456"))) } } "throw a CompanyDetailsNotDefinedException" when { "a paye reg doc is passed in that doesn't have a company details block" in new Setup { - intercept[CompanyDetailsNotDefinedException](service.payeReg2DESSubmission(validRegistration.copy(companyDetails = None), DateTime.parse("2017-01-01"), None)) + intercept[CompanyDetailsNotDefinedException](service.payeReg2DESSubmission(validRegistration.copy(companyDetails = None), DateTime.parse("2017-01-01"), None, None)) } } "throw a AcknowledgementReferenceNotExistsException" when { "the paye reg doc is missing an ack ref" in new Setup { - intercept[AcknowledgementReferenceNotExistsException](service.payeReg2DESSubmission(validRegistration.copy(acknowledgementReference = None), DateTime.parse("2017-01-01"), None)) + intercept[AcknowledgementReferenceNotExistsException](service.payeReg2DESSubmission(validRegistration.copy(acknowledgementReference = None), DateTime.parse("2017-01-01"), None, None)) } } } @@ -328,14 +328,14 @@ class SubmissionServiceSpec extends PAYERegSpec { when(mockRegistrationRepository.retrieveRegistration(ArgumentMatchers.anyString())) .thenReturn(Future.successful(Some(validRegistration.copy(status = PAYEStatus.invalid)))) - intercept[InvalidRegistrationException](await(service.buildADesSubmission("regId", Some(incorpStatusUpdate)))) + intercept[InvalidRegistrationException](await(service.buildADesSubmission("regId", Some(incorpStatusUpdate), None))) } "throw the correct exception when there is no registration in mongo" in new Setup { when(mockRegistrationRepository.retrieveRegistration(ArgumentMatchers.anyString())) .thenReturn(Future.successful(None)) - intercept[MissingRegDocument](await(service.buildADesSubmission("regId", Some(incorpStatusUpdate)))) + intercept[MissingRegDocument](await(service.buildADesSubmission("regId", Some(incorpStatusUpdate), None))) } } @@ -364,10 +364,10 @@ class SubmissionServiceSpec extends PAYERegSpec { "Building DES Limited Company" should { "throw the correct exception for SIC Code when missing" in new Setup { - intercept[SICCodeNotDefinedException](service.buildDESLimitedCompany(validCompanyDetails, Seq.empty, None, Seq.empty, Some(validEmployment))) + intercept[SICCodeNotDefinedException](service.buildDESLimitedCompany(validCompanyDetails, Seq.empty, None, Seq.empty, Some(validEmployment), None)) } "throw the correct exception for Employment when missing" in new Setup { - intercept[EmploymentDetailsNotDefinedException](service.buildDESLimitedCompany(validCompanyDetails, validSICCodes, None, Seq.empty, None)) + intercept[EmploymentDetailsNotDefinedException](service.buildDESLimitedCompany(validCompanyDetails, validSICCodes, None, Seq.empty, None, None)) } } From 5c305696d67931d9c571e3776fa10a1adca3389d Mon Sep 17 00:00:00 2001 From: "christopher.walker" Date: Thu, 4 May 2017 10:15:15 +0100 Subject: [PATCH 7/7] SCRS --- it/repositories/RegistrationMongoRepositoryISpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/it/repositories/RegistrationMongoRepositoryISpec.scala b/it/repositories/RegistrationMongoRepositoryISpec.scala index 0577dc8e..f7966c40 100644 --- a/it/repositories/RegistrationMongoRepositoryISpec.scala +++ b/it/repositories/RegistrationMongoRepositoryISpec.scala @@ -44,7 +44,7 @@ class RegistrationMongoRepositoryISpec Some("Testford"), Some("Testshire"), Some("TE1 1ST"), - Some("UK") + None ) private val ppobAddress = Address( @@ -53,7 +53,7 @@ class RegistrationMongoRepositoryISpec Some("Testford"), Some("Testshire"), Some("TE4 1ST"), - Some("UK") + None ) private val businessContact = DigitalContactDetails( Some("test@email.com"),