|
| 1 | +package history.filter.transform |
| 2 | + |
| 3 | +import assertk.assertThat |
| 4 | +import assertk.assertions.isEqualTo |
| 5 | +import kotlin.test.Test |
| 6 | +import kotlinx.datetime.LocalDate |
| 7 | +import kotlinx.datetime.LocalDateTime |
| 8 | +import stubs.Stubs |
| 9 | + |
| 10 | +class RepositoryCreatedAtTransformTest { |
| 11 | + |
| 12 | + // region Code Review components |
| 13 | + private val earlyCodeReviewComment = Stubs.generic.codeReviewComment.copy( |
| 14 | + createdAt = LocalDateTime(2023, 2, 28, 10, 40, 20), |
| 15 | + ) |
| 16 | + private val validCodeReviewComment = Stubs.generic.codeReviewComment.copy( |
| 17 | + createdAt = LocalDateTime(2023, 3, 1, 10, 40, 20), |
| 18 | + ) |
| 19 | + private val lateCodeReviewComment = Stubs.generic.codeReviewComment.copy( |
| 20 | + createdAt = LocalDateTime(2023, 3, 2, 10, 40, 20), |
| 21 | + ) |
| 22 | + private val codeReviewComments = listOf(earlyCodeReviewComment, validCodeReviewComment, lateCodeReviewComment) |
| 23 | + |
| 24 | + private val earlyCodeReviewFeedback = Stubs.generic.codeReviewFeedback.copy( |
| 25 | + submittedAt = LocalDateTime(2023, 2, 28, 10, 40, 20), |
| 26 | + ) |
| 27 | + private val validCodeReviewFeedback = Stubs.generic.codeReviewFeedback.copy( |
| 28 | + submittedAt = LocalDateTime(2023, 3, 1, 10, 40, 20), |
| 29 | + ) |
| 30 | + private val lateCodeReviewFeedback = Stubs.generic.codeReviewFeedback.copy( |
| 31 | + submittedAt = LocalDateTime(2023, 3, 2, 10, 40, 20), |
| 32 | + ) |
| 33 | + private val codeReviewFeedbacks = listOf(earlyCodeReviewFeedback, validCodeReviewFeedback, lateCodeReviewFeedback) |
| 34 | + // endregion Code Review components |
| 35 | + |
| 36 | + // region Discussion components |
| 37 | + private val earlyDiscussionComment = Stubs.generic.discussionComment.copy( |
| 38 | + createdAt = LocalDateTime(2023, 2, 28, 10, 40, 20), |
| 39 | + ) |
| 40 | + private val validDiscussionComment = Stubs.generic.discussionComment.copy( |
| 41 | + createdAt = LocalDateTime(2023, 3, 1, 10, 40, 20), |
| 42 | + ) |
| 43 | + private val lateDiscussionComment = Stubs.generic.discussionComment.copy( |
| 44 | + createdAt = LocalDateTime(2023, 3, 2, 10, 40, 20), |
| 45 | + ) |
| 46 | + private val discussionComments = listOf(earlyDiscussionComment, validDiscussionComment, lateDiscussionComment) |
| 47 | + // endregion Discussion components |
| 48 | + |
| 49 | + // region Repository components |
| 50 | + private val earlyCodeReview = Stubs.generic.codeReview.copy( |
| 51 | + createdAt = LocalDateTime(2023, 2, 28, 10, 40, 20), |
| 52 | + mergedAt = LocalDateTime(2023, 2, 28, 10, 45, 20), |
| 53 | + closedAt = LocalDateTime(2023, 2, 28, 10, 50, 20), |
| 54 | + comments = codeReviewComments, |
| 55 | + feedbacks = codeReviewFeedbacks, |
| 56 | + ) |
| 57 | + private val validCodeReview = Stubs.generic.codeReview.copy( |
| 58 | + createdAt = LocalDateTime(2023, 3, 1, 10, 40, 20), |
| 59 | + mergedAt = LocalDateTime(2023, 3, 1, 10, 45, 20), |
| 60 | + closedAt = LocalDateTime(2023, 3, 1, 10, 50, 20), |
| 61 | + comments = codeReviewComments, |
| 62 | + feedbacks = codeReviewFeedbacks, |
| 63 | + ) |
| 64 | + private val lateCodeReview = Stubs.generic.codeReview.copy( |
| 65 | + createdAt = LocalDateTime(2023, 3, 2, 10, 40, 20), |
| 66 | + mergedAt = LocalDateTime(2023, 3, 2, 10, 45, 20), |
| 67 | + closedAt = LocalDateTime(2023, 3, 2, 10, 50, 20), |
| 68 | + comments = codeReviewComments, |
| 69 | + feedbacks = codeReviewFeedbacks, |
| 70 | + ) |
| 71 | + val codeReviews = listOf(earlyCodeReview, validCodeReview, lateCodeReview) |
| 72 | + |
| 73 | + private val earlyDiscussion = Stubs.generic.discussion.copy( |
| 74 | + createdAt = LocalDateTime(2023, 2, 28, 10, 40, 20), |
| 75 | + closedAt = LocalDateTime(2023, 2, 28, 10, 45, 20), |
| 76 | + comments = discussionComments, |
| 77 | + ) |
| 78 | + private val validDiscussion = Stubs.generic.discussion.copy( |
| 79 | + createdAt = LocalDateTime(2023, 3, 1, 10, 40, 20), |
| 80 | + closedAt = LocalDateTime(2023, 3, 1, 10, 45, 20), |
| 81 | + comments = discussionComments, |
| 82 | + ) |
| 83 | + private val lateDiscussion = Stubs.generic.discussion.copy( |
| 84 | + createdAt = LocalDateTime(2023, 3, 2, 10, 40, 20), |
| 85 | + closedAt = LocalDateTime(2023, 3, 2, 10, 45, 20), |
| 86 | + comments = discussionComments, |
| 87 | + ) |
| 88 | + private val discussions = listOf(earlyDiscussion, validDiscussion, lateDiscussion) |
| 89 | + // endregion Repository components |
| 90 | + |
| 91 | + val repository = Stubs.generic.repository.copy( |
| 92 | + codeReviews = codeReviews, |
| 93 | + discussions = discussions, |
| 94 | + ) |
| 95 | + |
| 96 | + @Test fun `transform is applied correctly - apply to all`() { |
| 97 | + val expectedCodeReviewComments = listOf(validCodeReviewComment) |
| 98 | + val expectedCodeReviewFeedbacks = listOf(validCodeReviewFeedback) |
| 99 | + val expectedCodeReviews = listOf( |
| 100 | + validCodeReview.copy( |
| 101 | + comments = expectedCodeReviewComments, |
| 102 | + feedbacks = expectedCodeReviewFeedbacks, |
| 103 | + ), |
| 104 | + ) |
| 105 | + |
| 106 | + val expectedDiscussionComments = listOf(validDiscussionComment) |
| 107 | + val expectedDiscussions = listOf( |
| 108 | + validDiscussion.copy( |
| 109 | + comments = expectedDiscussionComments, |
| 110 | + ), |
| 111 | + ) |
| 112 | + |
| 113 | + val expectedRepository = Stubs.generic.repository.copy( |
| 114 | + codeReviews = expectedCodeReviews, |
| 115 | + discussions = expectedDiscussions, |
| 116 | + ) |
| 117 | + |
| 118 | + val transform = RepositoryCreatedAtTransform( |
| 119 | + createdAt = LocalDate(2023, 3, 1), |
| 120 | + applyToCommentsAndFeedbacks = true, |
| 121 | + applyToCodeReviewsAndDiscussions = true, |
| 122 | + ) |
| 123 | + |
| 124 | + assertThat(transform(repository)).isEqualTo(expectedRepository) |
| 125 | + } |
| 126 | + |
| 127 | + @Test fun `transform is applied correctly - apply to code reviews and discussions only`() { |
| 128 | + val expectedCodeReviewComments = codeReviewComments |
| 129 | + val expectedCodeReviewFeedbacks = codeReviewFeedbacks |
| 130 | + val expectedCodeReviews = listOf( |
| 131 | + validCodeReview.copy( |
| 132 | + comments = expectedCodeReviewComments, |
| 133 | + feedbacks = expectedCodeReviewFeedbacks, |
| 134 | + ), |
| 135 | + ) |
| 136 | + |
| 137 | + val expectedDiscussionComments = discussionComments |
| 138 | + val expectedDiscussions = listOf( |
| 139 | + validDiscussion.copy( |
| 140 | + comments = expectedDiscussionComments, |
| 141 | + ), |
| 142 | + ) |
| 143 | + |
| 144 | + val expectedRepository = Stubs.generic.repository.copy( |
| 145 | + codeReviews = expectedCodeReviews, |
| 146 | + discussions = expectedDiscussions, |
| 147 | + ) |
| 148 | + |
| 149 | + val transform = RepositoryCreatedAtTransform( |
| 150 | + createdAt = LocalDate(2023, 3, 1), |
| 151 | + applyToCommentsAndFeedbacks = false, |
| 152 | + applyToCodeReviewsAndDiscussions = true, |
| 153 | + ) |
| 154 | + |
| 155 | + assertThat(transform(repository)).isEqualTo(expectedRepository) |
| 156 | + } |
| 157 | + |
| 158 | + @Test fun `transform is applied correctly - apply to comments and feedbacks only`() { |
| 159 | + val expectedCodeReviewComments = listOf(validCodeReviewComment) |
| 160 | + val expectedCodeReviewFeedbacks = listOf(validCodeReviewFeedback) |
| 161 | + val expectedCodeReviews = codeReviews.map { |
| 162 | + it.copy( |
| 163 | + comments = expectedCodeReviewComments, |
| 164 | + feedbacks = expectedCodeReviewFeedbacks, |
| 165 | + ) |
| 166 | + } |
| 167 | + |
| 168 | + val expectedDiscussionComments = listOf(validDiscussionComment) |
| 169 | + val expectedDiscussions = discussions.map { |
| 170 | + it.copy( |
| 171 | + comments = expectedDiscussionComments, |
| 172 | + ) |
| 173 | + } |
| 174 | + |
| 175 | + val expectedRepository = Stubs.generic.repository.copy( |
| 176 | + codeReviews = expectedCodeReviews, |
| 177 | + discussions = expectedDiscussions, |
| 178 | + ) |
| 179 | + |
| 180 | + val transform = RepositoryCreatedAtTransform( |
| 181 | + createdAt = LocalDate(2023, 3, 1), |
| 182 | + applyToCommentsAndFeedbacks = true, |
| 183 | + applyToCodeReviewsAndDiscussions = false, |
| 184 | + ) |
| 185 | + |
| 186 | + assertThat(transform(repository)).isEqualTo(expectedRepository) |
| 187 | + } |
| 188 | + |
| 189 | + @Test fun `transform is applied correctly - apply to none`() { |
| 190 | + val transform = RepositoryCreatedAtTransform( |
| 191 | + createdAt = LocalDate(2023, 3, 1), |
| 192 | + applyToCommentsAndFeedbacks = false, |
| 193 | + applyToCodeReviewsAndDiscussions = false, |
| 194 | + ) |
| 195 | + |
| 196 | + assertThat(transform(repository)).isEqualTo(repository) |
| 197 | + } |
| 198 | + |
| 199 | +} |
0 commit comments