Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/no-carrier.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChris Rebert <code@rebertia.com>2015-04-25 01:19:43 +0300
committerChris Rebert <code@rebertia.com>2015-04-25 01:19:43 +0300
commitb96d5caebf2fd9d4881be6b9c29514b8dc207049 (patch)
treef26c0bc5d43ac369c95805d03c1ccede1e88d47c /src
parent1690c0b649692d50c8fe7a3d266c567ba8d4a3fa (diff)
add FancyIssueSpec tests
Diffstat (limited to 'src')
-rw-r--r--src/test/scala/FancyIssueSpec.scala112
-rw-r--r--src/test/scala/test_implicits/package.scala22
2 files changed, 134 insertions, 0 deletions
diff --git a/src/test/scala/FancyIssueSpec.scala b/src/test/scala/FancyIssueSpec.scala
new file mode 100644
index 0000000..956c987
--- /dev/null
+++ b/src/test/scala/FancyIssueSpec.scala
@@ -0,0 +1,112 @@
+import java.time.{Clock, Instant}
+import scala.collection.JavaConverters._
+import org.specs2.mutable._
+import com.jcabi.github.mock.MkGithub
+import com.getbootstrap.no_carrier.github.util._
+import test_implicits._
+
+class FancyIssueSpec extends Specification {
+ implicit val clock = Clock.systemUTC
+ val github = new MkGithub("mock_gh")
+ val repo = github.repos.create("foobar")
+ val label = "waiting-for-OP"
+ val twoSecsInMs = 2000
+ def newIssue() = repo.issues.create("Title here", "Description here")
+ def delay() {
+ Thread.sleep(twoSecsInMs)
+ }
+
+ "lastCommentedOnAt" should {
+ "give the only value when there is exactly one comment" in {
+ val issue = newIssue()
+ val comment = issue.comments.post("First comment").smart
+ issue.fancy.lastCommentedOnAt mustEqual Some(comment.createdAt.toInstant)
+ }
+ "give the maximum when there are several comments" in {
+ val issue = newIssue()
+ issue.comments.post("First comment")
+ delay()
+ issue.comments.post("Second comment")
+ delay()
+ val lastComment = issue.comments.post("Third comment").smart
+ issue.fancy.lastCommentedOnAt mustEqual Some(lastComment.createdAt.toInstant)
+ }
+ }
+
+ "lastLabelledAt" should {
+ "give the maximum when there have been several labellings" in {
+ val issue = newIssue()
+ issue.labels.add(label)
+ issue.labels.remove(label)
+ delay()
+ issue.labels.add(label)
+ issue.labels.remove(label)
+ delay()
+ val before = clock.instant()
+ issue.labels.add(label)
+ val after = clock.instant()
+ issue.fancy.lastLabelledAt must beGreaterThanOrEqualTo(before.truncatedToSecs)
+ issue.fancy.lastLabelledAt must beLessThanOrEqualTo(after.truncatedToSecs)
+ }
+ }
+
+ "lastClosedAt" should {
+ "be None when the issue is open" in {
+ val issue = newIssue()
+ issue.fancy.lastClosedAt must beNone
+ }
+ "be the closure instant when the issue has been closed once" in {
+ val issue = newIssue()
+ val before = clock.instant()
+ issue.smart.close()
+ val after = clock.instant()
+ issue.fancy.lastClosedAt must beSome(greaterThanOrEqualTo(before.truncatedToSecs))
+ issue.fancy.lastClosedAt must beSome(lessThanOrEqualTo(after.truncatedToSecs))
+ }
+ "be the last closure instant when the issue has been closed and reopened multiple times" in {
+ val issue = newIssue()
+ val smartIssue = issue.smart
+ smartIssue.close()
+ smartIssue.open()
+ delay()
+ smartIssue.close()
+ smartIssue.open()
+ delay()
+ val before = clock.instant()
+ smartIssue.close()
+ val after = clock.instant()
+ smartIssue.open()
+ issue.fancy.lastClosedAt must beSome(greaterThanOrEqualTo(before.truncatedToSecs))
+ issue.fancy.lastClosedAt must beSome(lessThanOrEqualTo(after.truncatedToSecs))
+ }
+ }
+
+ "wasClosedAfterLabelling" should {
+ "be false when the issue has never been closed" in {
+ val issue = newIssue()
+ issue.fancy.wasClosedAfterLabelling must beFalse
+ issue.labels.add(label)
+ issue.fancy.wasClosedAfterLabelling must beFalse
+ }
+ "be false when the issue was closed prior to the labelling" in {
+ val issue = newIssue()
+ issue.smart.close()
+ issue.smart.open()
+ delay()
+ issue.labels.add(label)
+ issue.fancy.wasClosedAfterLabelling must beFalse
+ }
+ "be true when the issue was closed after the labelling" in {
+ val issue = newIssue()
+ issue.labels.add(label)
+ delay()
+ issue.smart.close()
+ issue.smart.open()
+ issue.fancy.wasClosedAfterLabelling must beTrue
+ }
+ "be correct when the issue has been labelled, closed, and reopened multiple times" in {
+ val issue = newIssue()
+ // FIXME
+ }
+ }
+}
diff --git a/src/test/scala/test_implicits/package.scala b/src/test/scala/test_implicits/package.scala
new file mode 100644
index 0000000..368c3cd
--- /dev/null
+++ b/src/test/scala/test_implicits/package.scala
@@ -0,0 +1,22 @@
+import java.time.{Instant, Duration, Clock}
+import java.time.temporal.ChronoUnit
+import com.jcabi.github.Issue
+import com.getbootstrap.no_carrier.github.FancyIssue
+
+package object test_implicits {
+ object RicherIssue {
+ private val label = "waiting-for-OP"
+ private val timeout = Duration.ofDays(2)
+ }
+ implicit class RicherIssue(issue: Issue) {
+ def fancy(implicit clock: Clock): FancyIssue = new FancyIssue(issue = issue, label = RicherIssue.label, timeout = RicherIssue.timeout)
+ }
+
+ implicit class RicherInstant(instant: Instant) {
+ def truncatedToSecs: Instant = instant.truncatedTo(ChronoUnit.SECONDS)
+ }
+
+ implicit class RicherOptionInstant(optInstant: Option[Instant]) {
+ def truncatedToSecs: Option[Instant] = optInstant.map{ _.truncatedToSecs }
+ }
+}