Skip to content

Commit 78faf3a

Browse files
Added sandbox endpoints
1 parent cba9863 commit 78faf3a

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

app/uk/gov/hmrc/epayeapi/controllers/ApiController.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import scala.concurrent.{ExecutionContext, Future}
3333

3434
trait ApiController extends BaseController with AuthorisedFunctions {
3535
val epayeEnrolment = Enrolment("IR-PAYE")
36+
val epayeRetrieval = authorisedEnrolments
3637
def authConnector: AuthConnector
3738
implicit def ec: ExecutionContext
3839
implicit def mat: Materializer
@@ -52,7 +53,7 @@ trait ApiController extends BaseController with AuthorisedFunctions {
5253

5354

5455
def EmpRefsAction(action: Set[EmpRef] => EssentialAction): EssentialAction =
55-
EnrolmentsAction(epayeEnrolment, authorisedEnrolments) { enrolments =>
56+
EnrolmentsAction(epayeEnrolment, epayeRetrieval) { enrolments =>
5657
EssentialAction { request =>
5758
action(enrolments.enrolments.flatMap(enrolmentToEmpRef))(request)
5859
}

app/uk/gov/hmrc/epayeapi/controllers/GetEmpRefs.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import akka.stream.Materializer
2222
import play.api.libs.json.Json
2323
import play.api.mvc.{Action, AnyContent, EssentialAction}
2424
import uk.gov.hmrc.auth.core.AuthConnector
25+
import uk.gov.hmrc.domain.EmpRef
2526
import uk.gov.hmrc.epayeapi.models.EmpRefsResponse
2627
import uk.gov.hmrc.epayeapi.models.Formats._
2728

@@ -41,4 +42,15 @@ case class GetEmpRefs @Inject() (
4142
}
4243
}
4344

45+
def sandbox(): EssentialAction =
46+
EnrolmentsAction(epayeEnrolment, epayeRetrieval) { _ =>
47+
Action { _ =>
48+
Ok(Json.toJson(EmpRefsResponse.fromSeq(Seq(
49+
EmpRef("001", "0000001"),
50+
EmpRef("002", "0000002"),
51+
EmpRef("003", "0000003")
52+
))))
53+
}
54+
}
55+
4456
}

app/uk/gov/hmrc/epayeapi/controllers/GetTotals.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import uk.gov.hmrc.epayeapi.connectors.EpayeConnector
2828
import uk.gov.hmrc.epayeapi.models.Formats._
2929
import uk.gov.hmrc.epayeapi.models.{ApiError, TotalsResponse}
3030
import uk.gov.hmrc.epayeapi.models.api.{ApiJsonError, ApiSuccess}
31+
import uk.gov.hmrc.epayeapi.models.domain.AggregatedTotals
3132

3233
import scala.concurrent.ExecutionContext
3334

@@ -54,4 +55,20 @@ case class GetTotals @Inject() (
5455
}
5556
}
5657
}
58+
59+
def sandbox(empRef: EmpRef): EssentialAction =
60+
EnrolmentsAction(epayeEnrolment, epayeRetrieval) { _ =>
61+
Action { _ =>
62+
empRef match {
63+
case EmpRef("001", "0000001") =>
64+
Ok(Json.toJson(TotalsResponse(empRef, AggregatedTotals(debit = 10000, credit = 0))))
65+
case EmpRef("002", "0000002") =>
66+
Ok(Json.toJson(TotalsResponse(empRef, AggregatedTotals(debit = 0, credit = 10000))))
67+
case EmpRef("003", "0000003") =>
68+
Ok(Json.toJson(TotalsResponse(empRef, AggregatedTotals(debit = 0, credit = 0))))
69+
case _ =>
70+
Unauthorized(Json.toJson(ApiError.InvalidEmpRef))
71+
}
72+
}
73+
}
5774
}

test/uk/gov/hmrc/epayeapi/controllers/GetEmpRefsSpec.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class GetEmpRefsSpec extends AppSpec {
4949
def request(implicit a: Application): Future[Result] =
5050
inject[GetEmpRefs].getEmpRefs()(FakeRequest())
5151

52+
def sandboxRequest(implicit a: Application): Future[Result] =
53+
inject[GetEmpRefs].sandbox()(FakeRequest())
54+
5255
"The EmpRefs endpoint" should {
5356
"return 200 OK on active enrolments" in new App(build(AuthOk(activeEnrolment))) {
5457
status(request) shouldBe OK
@@ -75,4 +78,19 @@ class GetEmpRefsSpec extends AppSpec {
7578
contentAsJson(request) shouldBe Json.toJson(ApiError.InsufficientEnrolments)
7679
}
7780
}
81+
82+
"The EmpRefs sandbox" should {
83+
"return 200 OK with 3 empRefs" in new App(build(AuthOk(activeEnrolment))) {
84+
contentAsJson(sandboxRequest).validate[EmpRefsResponse].asOpt shouldEqual Some(
85+
EmpRefsResponse.fromSeq(Seq(
86+
EmpRef("001", "0000001"),
87+
EmpRef("002", "0000002"),
88+
EmpRef("003", "0000003")
89+
))
90+
)
91+
}
92+
"return 401 Unauthorized on insufficient enrolments" in new App(build(AuthFail(new InsufficientEnrolments))) {
93+
status(sandboxRequest) shouldBe UNAUTHORIZED
94+
}
95+
}
7896
}

test/uk/gov/hmrc/epayeapi/controllers/GetTotalsSpec.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class GetTotalsSpec extends AppSpec with BeforeAndAfterEach {
6767

6868
def request(implicit a: Application): Future[Result] =
6969
inject[GetTotals].getTotals(empRef)(FakeRequest())
70+
def sandboxRequest(empRef: EmpRef)(implicit a: Application): Future[Result] =
71+
inject[GetTotals].sandbox(empRef)(FakeRequest())
7072

7173

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

96+
"The Totals sandbox endpoint" should {
97+
"return 200 OK and a debit" in new App(app.withAuth(activeEnrolment).build){
98+
99+
}
100+
}
101+
94102

95103
}

0 commit comments

Comments
 (0)