Skip to content

Commit

Permalink
Added sandbox endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
flashingpumpkin committed Jun 29, 2017
1 parent cba9863 commit 78faf3a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/uk/gov/hmrc/epayeapi/controllers/ApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import scala.concurrent.{ExecutionContext, Future}

trait ApiController extends BaseController with AuthorisedFunctions {
val epayeEnrolment = Enrolment("IR-PAYE")
val epayeRetrieval = authorisedEnrolments
def authConnector: AuthConnector
implicit def ec: ExecutionContext
implicit def mat: Materializer
Expand All @@ -52,7 +53,7 @@ trait ApiController extends BaseController with AuthorisedFunctions {


def EmpRefsAction(action: Set[EmpRef] => EssentialAction): EssentialAction =
EnrolmentsAction(epayeEnrolment, authorisedEnrolments) { enrolments =>
EnrolmentsAction(epayeEnrolment, epayeRetrieval) { enrolments =>
EssentialAction { request =>
action(enrolments.enrolments.flatMap(enrolmentToEmpRef))(request)
}
Expand Down
12 changes: 12 additions & 0 deletions app/uk/gov/hmrc/epayeapi/controllers/GetEmpRefs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import akka.stream.Materializer
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent, EssentialAction}
import uk.gov.hmrc.auth.core.AuthConnector
import uk.gov.hmrc.domain.EmpRef
import uk.gov.hmrc.epayeapi.models.EmpRefsResponse
import uk.gov.hmrc.epayeapi.models.Formats._

Expand All @@ -41,4 +42,15 @@ case class GetEmpRefs @Inject() (
}
}

def sandbox(): EssentialAction =
EnrolmentsAction(epayeEnrolment, epayeRetrieval) { _ =>
Action { _ =>
Ok(Json.toJson(EmpRefsResponse.fromSeq(Seq(
EmpRef("001", "0000001"),
EmpRef("002", "0000002"),
EmpRef("003", "0000003")
))))
}
}

}
17 changes: 17 additions & 0 deletions app/uk/gov/hmrc/epayeapi/controllers/GetTotals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import uk.gov.hmrc.epayeapi.connectors.EpayeConnector
import uk.gov.hmrc.epayeapi.models.Formats._
import uk.gov.hmrc.epayeapi.models.{ApiError, TotalsResponse}
import uk.gov.hmrc.epayeapi.models.api.{ApiJsonError, ApiSuccess}
import uk.gov.hmrc.epayeapi.models.domain.AggregatedTotals

import scala.concurrent.ExecutionContext

Expand All @@ -54,4 +55,20 @@ case class GetTotals @Inject() (
}
}
}

def sandbox(empRef: EmpRef): EssentialAction =
EnrolmentsAction(epayeEnrolment, epayeRetrieval) { _ =>
Action { _ =>
empRef match {
case EmpRef("001", "0000001") =>
Ok(Json.toJson(TotalsResponse(empRef, AggregatedTotals(debit = 10000, credit = 0))))
case EmpRef("002", "0000002") =>
Ok(Json.toJson(TotalsResponse(empRef, AggregatedTotals(debit = 0, credit = 10000))))
case EmpRef("003", "0000003") =>
Ok(Json.toJson(TotalsResponse(empRef, AggregatedTotals(debit = 0, credit = 0))))
case _ =>
Unauthorized(Json.toJson(ApiError.InvalidEmpRef))
}
}
}
}
18 changes: 18 additions & 0 deletions test/uk/gov/hmrc/epayeapi/controllers/GetEmpRefsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class GetEmpRefsSpec extends AppSpec {
def request(implicit a: Application): Future[Result] =
inject[GetEmpRefs].getEmpRefs()(FakeRequest())

def sandboxRequest(implicit a: Application): Future[Result] =
inject[GetEmpRefs].sandbox()(FakeRequest())

"The EmpRefs endpoint" should {
"return 200 OK on active enrolments" in new App(build(AuthOk(activeEnrolment))) {
status(request) shouldBe OK
Expand All @@ -75,4 +78,19 @@ class GetEmpRefsSpec extends AppSpec {
contentAsJson(request) shouldBe Json.toJson(ApiError.InsufficientEnrolments)
}
}

"The EmpRefs sandbox" should {
"return 200 OK with 3 empRefs" in new App(build(AuthOk(activeEnrolment))) {
contentAsJson(sandboxRequest).validate[EmpRefsResponse].asOpt shouldEqual Some(
EmpRefsResponse.fromSeq(Seq(
EmpRef("001", "0000001"),
EmpRef("002", "0000002"),
EmpRef("003", "0000003")
))
)
}
"return 401 Unauthorized on insufficient enrolments" in new App(build(AuthFail(new InsufficientEnrolments))) {
status(sandboxRequest) shouldBe UNAUTHORIZED
}
}
}
8 changes: 8 additions & 0 deletions test/uk/gov/hmrc/epayeapi/controllers/GetTotalsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class GetTotalsSpec extends AppSpec with BeforeAndAfterEach {

def request(implicit a: Application): Future[Result] =
inject[GetTotals].getTotals(empRef)(FakeRequest())
def sandboxRequest(empRef: EmpRef)(implicit a: Application): Future[Result] =
inject[GetTotals].sandbox(empRef)(FakeRequest())


override protected def beforeEach(): FixtureParam = {
Expand All @@ -91,5 +93,11 @@ class GetTotalsSpec extends AppSpec with BeforeAndAfterEach {
}
}

"The Totals sandbox endpoint" should {
"return 200 OK and a debit" in new App(app.withAuth(activeEnrolment).build){

}
}


}

0 comments on commit 78faf3a

Please sign in to comment.