-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from hmrc/SAR-672
SAR-672 - Component Tests for user access
- Loading branch information
Showing
4 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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 controllers.throttling | ||
|
||
import helpers.ComponentSpecBase | ||
import helpers.WireMockDSL.HTTPVerbMapping.Get | ||
import helpers.WireMockDSL._ | ||
import helpers.servicemocks.AuthStub._ | ||
import helpers.IntegrationTestConstants._ | ||
import play.api.http.Status._ | ||
import helpers.DatabaseHelpers._ | ||
import play.api.libs.concurrent.Execution.Implicits._ | ||
|
||
class UserAccessControllerISpec extends ComponentSpecBase { | ||
"GET /throttle/:nino" should { | ||
"return OK when the service has not received any requests" in { | ||
stub when Get(authority) thenReturn stubbedAuthResponse | ||
stub when Get(authIDs) thenReturn stubbedIDs | ||
|
||
IncomeTaxSubscription.checkUserAccess(testNino) should have ( | ||
httpStatus(OK) | ||
) | ||
} | ||
|
||
"return OK when the service has not received too many requests" in { | ||
IncomeTaxSubscription.insertUserCount(nonFullUserCount) | ||
|
||
stub when Get(authority) thenReturn stubbedAuthResponse | ||
stub when Get(authIDs) thenReturn stubbedIDs | ||
|
||
IncomeTaxSubscription.checkUserAccess(testNino) should have ( | ||
httpStatus(OK) | ||
) | ||
} | ||
|
||
"return OK for a returning user" in { | ||
IncomeTaxSubscription.insertUserCount(matchingUserCount) | ||
|
||
stub when Get(authority) thenReturn stubbedAuthResponse | ||
stub when Get(authIDs) thenReturn stubbedIDs | ||
|
||
IncomeTaxSubscription.checkUserAccess(testNino) should have ( | ||
httpStatus(OK) | ||
) | ||
} | ||
|
||
"return TOO_MANY_REQUESTS when the service has received too many requests and it is a new userID" in { | ||
IncomeTaxSubscription.insertUserCount(maxUserCount) | ||
|
||
stub when Get(authority) thenReturn stubbedAuthResponse | ||
stub when Get(authIDs) thenReturn stubbedIDs | ||
|
||
IncomeTaxSubscription.checkUserAccess(testNino) should have ( | ||
httpStatus(TOO_MANY_REQUESTS) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 helpers | ||
|
||
import models.throttling.UserCount | ||
import helpers.servicemocks.AuthStub._ | ||
import uk.gov.hmrc.time.DateTimeUtils | ||
|
||
object DatabaseHelpers { | ||
val id = DateTimeUtils.now.toString("yyyy-MM-dd") | ||
|
||
val maxUserCount = UserCount(id, Set("otherID1", "otherID2"), 0) | ||
val matchingUserCount = UserCount(id, Set(internalID, "otherID"), 0) | ||
val nonFullUserCount = UserCount(id, Set("otherID"), 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters