-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APIS-4691 - Add Url validation rule (#68)
* APIS-4691 - Initial commit * APIS-4691 - Add url validation rule and rework tests to utilize * APIS-4691 - Fix case object use * APIS-4691 - Apply review comment
- Loading branch information
1 parent
47fc4f9
commit 658231a
Showing
11 changed files
with
115 additions
and
46 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
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
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
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
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
49 changes: 49 additions & 0 deletions
49
test/uk/gov/hmrc/apisubscriptionfields/model/ModelSpec.scala
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,49 @@ | ||
/* | ||
* Copyright 2020 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 uk.gov.hmrc.apisubscriptionfields.model | ||
|
||
import uk.gov.hmrc.play.test.UnitSpec | ||
import uk.gov.hmrc.apisubscriptionfields.SubscriptionFieldsTestData | ||
import uk.gov.hmrc.apisubscriptionfields.FieldsDefinitionTestData | ||
|
||
|
||
class ModelSpec extends UnitSpec with SubscriptionFieldsTestData with FieldsDefinitionTestData with ValidationRuleTestData { | ||
"RegexValidationRule" should { | ||
|
||
"return true when the value is valid - correct case" in { | ||
lowerCaseRule.validate(lowerCaseValue) shouldBe true | ||
} | ||
"return true when the value is valid - long enough" in { | ||
atLeastThreeLongRule.validate(lowerCaseValue) shouldBe true | ||
} | ||
"return false when the value is invalid - wrong case" in { | ||
lowerCaseRule.validate(mixedCaseValue) shouldBe false | ||
} | ||
"return false when the value is invalid - too short" in { | ||
atLeastTenLongRule.validate(mixedCaseValue) shouldBe false | ||
} | ||
} | ||
|
||
"UrlValidationRule" should { | ||
"pass for a matching value" in { | ||
UrlValidationRule.validate(validUrl) shouldBe true | ||
} | ||
"fail for a value that does not match" in { | ||
UrlValidationRule.validate(invalidUrl) shouldBe false | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
test/uk/gov/hmrc/apisubscriptionfields/model/ValidationRuleTestData.scala
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,32 @@ | ||
/* | ||
* Copyright 2020 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 uk.gov.hmrc.apisubscriptionfields.model | ||
|
||
trait ValidationRuleTestData { | ||
|
||
val lowerCaseValue = "bob" | ||
val mixedCaseValue = "Bob" | ||
|
||
val lowerCaseRule: ValidationRule = RegexValidationRule("""^[a-z]+$""") | ||
val mixedCaseRule: ValidationRule = RegexValidationRule("""^[a-zA-Z]+$""") | ||
|
||
val atLeastThreeLongRule: ValidationRule = RegexValidationRule("""^.{3}.*$""") | ||
val atLeastTenLongRule: ValidationRule = RegexValidationRule("""^.{10}.*$""") | ||
|
||
val validUrl = "https://www.example.com/here/and/there" | ||
val invalidUrl = "www.example.com" | ||
} |
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