Skip to content

Commit

Permalink
Merge pull request #33 from hmrc/fixing_tests
Browse files Browse the repository at this point in the history
API-2532: fixing tests
  • Loading branch information
gokyo authored Nov 3, 2017
2 parents 733cce7 + 04777be commit 78d27c3
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions test/acceptance/ApiSubscriptionFieldsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import play.api.libs.json.Json
import play.api.mvc._
import play.api.test.FakeRequest
import play.api.test.Helpers._
import uk.gov.hmrc.apisubscriptionfields.model.{Fields, SubscriptionFieldsRequest, SubscriptionFieldsResponse, _}
import uk.gov.hmrc.apisubscriptionfields.model._
import util.{FieldsDefinitionTestData, RequestHeaders, SubscriptionFieldsTestData}

import scala.concurrent.Future
Expand Down Expand Up @@ -61,7 +61,8 @@ class ApiSubscriptionFieldsSpec extends AcceptanceTestSpec

scenario("the API is called to store some values for a new subscription field") {
Given("a request with valid payload")
val request = validSubscriptionPutRequest(SampleFields1).copyFakeRequest(method = PUT, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))
val request = validSubscriptionPutRequest(SampleFields1)
.copyFakeRequest(method = PUT, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))

When("a PUT request with data is sent to the API")
val result: Option[Future[Result]] = route(app, request)
Expand All @@ -74,15 +75,17 @@ class ApiSubscriptionFieldsSpec extends AcceptanceTestSpec

And("the response body should be a valid response")
val sfr = contentAsJson(resultFuture).validate[SubscriptionFieldsResponse]
val fieldsId = sfr.get.fieldsId

sfr.isSuccess shouldBe true
sfr.get should matchPattern { case SubscriptionFieldsResponse(`fakeRawClientId`, "acontext", "1.0.2", _, SampleFields1) => }
sfr.get shouldBe SubscriptionFieldsResponse(fakeRawClientId, "acontext", "1.0.2", fieldsId, SampleFields1)
}

scenario("the API is called to GET with a known subscription field") {

Given("a request with a known subscription field")
val request = ValidRequest.copyFakeRequest(method = GET, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))
val request = ValidRequest
.copyFakeRequest(method = GET, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))

When("a GET request with data is sent to the API")
val result: Option[Future[Result]] = route(app, request)
Expand All @@ -95,15 +98,17 @@ class ApiSubscriptionFieldsSpec extends AcceptanceTestSpec

And("the response body should be a valid response")
val sfr = contentAsJson(resultFuture).validate[SubscriptionFieldsResponse]
val fieldsId = sfr.get.fieldsId

sfr.isSuccess shouldBe true
sfr.get should matchPattern { case SubscriptionFieldsResponse(`fakeRawClientId`, "acontext", "1.0.2", _, SampleFields1) => }
sfr.get shouldBe SubscriptionFieldsResponse(fakeRawClientId, "acontext", "1.0.2", fieldsId, SampleFields1)
}

scenario("the API is called to GET with a known fieldsId") {

Given("a request with a known fieldsId")
val requestId = ValidRequest.copyFakeRequest(method = GET, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))
val requestId = ValidRequest
.copyFakeRequest(method = GET, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))

When("an id GET request with data is sent to the API")
val result: Option[Future[Result]] = route(app, requestId)
Expand Down Expand Up @@ -132,7 +137,7 @@ class ApiSubscriptionFieldsSpec extends AcceptanceTestSpec
val sfrFieldsId = contentAsJson(resultFuture).validate[SubscriptionFieldsResponse]

sfrFieldsId.isSuccess shouldBe true
sfrFieldsId.get should matchPattern { case SubscriptionFieldsResponse(`fakeRawClientId`, "acontext", "1.0.2", `fieldsId`, SampleFields1) => }
sfrFieldsId.get shouldBe SubscriptionFieldsResponse(fakeRawClientId, "acontext", "1.0.2", fieldsId, SampleFields1)
}

scenario("the API is called to GET existing subscription fields by application clientId") {
Expand All @@ -151,15 +156,17 @@ class ApiSubscriptionFieldsSpec extends AcceptanceTestSpec

And("the response body should be a valid response")
val sfr = contentAsJson(resultFuture).validate[BulkSubscriptionFieldsResponse]
val fieldsId = sfr.get.subscriptions.head.fieldsId

sfr.isSuccess shouldBe true
sfr.get should matchPattern { case BulkSubscriptionFieldsResponse(Seq(SubscriptionFieldsResponse(`fakeRawClientId`, "acontext", "1.0.2", _, SampleFields1))) => }
sfr.get shouldBe BulkSubscriptionFieldsResponse(Seq(SubscriptionFieldsResponse(fakeRawClientId, "acontext", "1.0.2", fieldsId, SampleFields1)))
}

scenario("the API is called to update existing subscription fields") {

Given("a request with valid payload")
val request = validSubscriptionPutRequest(SampleFields2).copyFakeRequest(method = PUT, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))
val request = validSubscriptionPutRequest(SampleFields2)
.copyFakeRequest(method = PUT, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))

When("a PUT request with data is sent to the API")
val result: Option[Future[Result]] = route(app, request)
Expand All @@ -172,15 +179,17 @@ class ApiSubscriptionFieldsSpec extends AcceptanceTestSpec

And("the response body should be a valid response")
val sfr = contentAsJson(resultFuture).validate[SubscriptionFieldsResponse]
val fieldsId = sfr.get.fieldsId

sfr.isSuccess shouldBe true
sfr.get should matchPattern { case SubscriptionFieldsResponse(`fakeRawClientId`, "acontext", "1.0.2", _, SampleFields2) => }
sfr.get shouldBe SubscriptionFieldsResponse(fakeRawClientId, "acontext", "1.0.2", fieldsId, SampleFields2)
}

scenario("the API is called to DELETE existing subscription fields") {

Given("a request with existing subscription fields")
val request = ValidRequest.copyFakeRequest(method = DELETE, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))
val request = ValidRequest
.copyFakeRequest(method = DELETE, uri = subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion))

When("a GET request with data is sent to the API")
val result: Option[Future[Result]] = route(app, request)
Expand All @@ -201,7 +210,8 @@ class ApiSubscriptionFieldsSpec extends AcceptanceTestSpec
scenario("the API is called to store some new fields definitions") {

Given("a request with valid payload")
val request = validDefinitionPutRequest(FakeFieldsDefinitions).copyFakeRequest(method = PUT, uri = definitionEndpoint(fakeRawContext, fakeRawVersion))
val request = validDefinitionPutRequest(FakeFieldsDefinitions)
.copyFakeRequest(method = PUT, uri = definitionEndpoint(fakeRawContext, fakeRawVersion))

When("a PUT request with data is sent to the API")
val result: Option[Future[Result]] = route(app, request)
Expand Down Expand Up @@ -231,7 +241,7 @@ class ApiSubscriptionFieldsSpec extends AcceptanceTestSpec
val fdr = contentAsJson(resultFuture).validate[FieldsDefinitionResponse]

fdr.isSuccess shouldBe true
fdr.get should matchPattern { case FieldsDefinitionResponse(FakeFieldsDefinitionResponse) => }
fdr.get shouldBe FakeFieldsDefinitionResponse
}

scenario("the API is called to GET all fields definitions") {
Expand All @@ -252,13 +262,14 @@ class ApiSubscriptionFieldsSpec extends AcceptanceTestSpec
val allFdr = contentAsJson(resultFuture).validate[BulkFieldsDefinitionsResponse]

allFdr.isSuccess shouldBe true
allFdr.get should matchPattern { case BulkFieldsDefinitionsResponse(List(FakeFieldsDefinitionResponse)) => }
allFdr.get shouldBe BulkFieldsDefinitionsResponse(List(FakeFieldsDefinitionResponse))
}

scenario("the API is called to update some existing fields definitions") {

Given("a request with valid payload")
val request = validDefinitionPutRequest(Seq.empty).copyFakeRequest(method = PUT, uri = definitionEndpoint(fakeRawContext, fakeRawVersion))
val request = validDefinitionPutRequest(Seq.empty)
.copyFakeRequest(method = PUT, uri = definitionEndpoint(fakeRawContext, fakeRawVersion))

When("a PUT request with data is sent to the API")
val result: Option[Future[Result]] = route(app, request)
Expand Down

0 comments on commit 78d27c3

Please sign in to comment.