|
16 | 16 |
|
17 | 17 | package acceptance.specs |
18 | 18 |
|
19 | | -import acceptance.BaseSpec |
20 | | -import acceptance.pages.{LoginPage, AuthorizedApplicationsPage} |
21 | | -import acceptance.stubs.LoginStub |
| 19 | +import acceptance.pages.{AuthorizedApplicationsPage, LoginPage} |
| 20 | +import acceptance.stubs.{DelegatedAuthorityStub, LoginStub} |
| 21 | +import acceptance.{BaseSpec, NavigationSugar} |
| 22 | +import models.{AppAuthorisation, Scope, ThirdPartyApplication} |
| 23 | +import org.joda.time.DateTime |
22 | 24 |
|
23 | | -class AuthorizedApplicationsSpec extends BaseSpec { |
| 25 | +class AuthorizedApplicationsSpec extends BaseSpec with NavigationSugar { |
24 | 26 |
|
25 | 27 | feature("Logged in") { |
26 | 28 |
|
27 | 29 | scenario("User is redirected to the sign in page when not logged in") { |
28 | 30 |
|
29 | 31 | go(AuthorizedApplicationsPage) |
30 | | - |
31 | 32 | redirectedTo(LoginPage) |
32 | 33 | } |
33 | 34 |
|
34 | 35 | scenario("User sees his authorized applications when logged in") { |
35 | 36 |
|
| 37 | + val applications = Seq( |
| 38 | + applicationAuthority("firstAppId", "First Application", |
| 39 | + Set(Scope("read:api-1", "scope name", "Access personal information"), |
| 40 | + Scope("read:api-3", "scope name", "Access tax information")), DateTime.now), |
| 41 | + |
| 42 | + applicationAuthority("secondAppId", "Second Application", |
| 43 | + Set(Scope("read:api-2", "scope name", "Access confidential information")), DateTime.now.minusDays(2)), |
| 44 | + |
| 45 | + applicationAuthority("thirdAppId", "Third Application", |
| 46 | + Set(), DateTime.now.minusMonths(2)) |
| 47 | + ) |
| 48 | + |
36 | 49 | LoginStub.stubSuccessfulLogin() |
| 50 | + DelegatedAuthorityStub.stubSuccessfulFetchApplicationAuthorities(applications) |
37 | 51 |
|
38 | 52 | go(AuthorizedApplicationsPage) |
| 53 | + on(AuthorizedApplicationsPage) |
| 54 | + |
| 55 | + verifyText("data-info-message", "You have granted permission to the following software applications to access HMRC data. You can with withdraw this permission at any time.") |
| 56 | + applications.foreach(assertApplication) |
| 57 | + } |
39 | 58 |
|
| 59 | + scenario("User sees correct message if there are not authorized applications") { |
| 60 | + LoginStub.stubSuccessfulLogin() |
| 61 | + DelegatedAuthorityStub.stubSuccessfulFetchApplicationAuthorities(Seq.empty) |
| 62 | + |
| 63 | + go(AuthorizedApplicationsPage) |
40 | 64 | on(AuthorizedApplicationsPage) |
| 65 | + |
| 66 | + verifyText("data-info-message", "There are currently no applications which have access to HMRC data. If you want to grant permission to an application, you must do so in the application itself.") |
41 | 67 | } |
| 68 | + } |
| 69 | + |
| 70 | + private def assertApplication(app: AppAuthorisation) = { |
| 71 | + verifyText(s"data-name-${app.application.id}", app.application.name) |
| 72 | + clickOnElement(s"data-name-${app.application.id}") |
| 73 | + app.scopes.foreach(scope => verifyText(s"data-scope-${app.application.id}='${scope.key}'", scope.description)) |
| 74 | + verifyText(s"data-grant-date-${app.application.id}", app.earliestGrantDate.toString("dd MMMM yyyy")) |
| 75 | + } |
42 | 76 |
|
| 77 | + private def applicationAuthority(appId: String, appName: String, scopes: Set[Scope], earliestGrantDate: DateTime) = { |
| 78 | + AppAuthorisation(ThirdPartyApplication(appId, appName), scopes, earliestGrantDate) |
43 | 79 | } |
44 | 80 | } |
0 commit comments