Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADDED] Application formatter test generated by AI #241

Merged
merged 2 commits into from
Jan 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions src/test/kotlin/StatsGeneratorApplicationTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

import dev.hossain.githubstats.AuthorPrStats
import dev.hossain.githubstats.AuthorStats
import dev.hossain.githubstats.PrAuthorStatsService
import dev.hossain.githubstats.PrReviewerStatsService
import dev.hossain.githubstats.ReviewerReviewStats
import dev.hossain.githubstats.formatter.StatsFormatter
import dev.hossain.githubstats.util.AppConfig
import dev.hossain.i18n.Resources
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import kotlin.time.Duration

/**
* Unit test for [StatsGeneratorApplication].
*/
class StatsGeneratorApplicationTest {

private val prReviewerStatsService: PrReviewerStatsService = mockk(relaxed = true)
private val prAuthorStatsService: PrAuthorStatsService = mockk(relaxed = true)
private val resources: Resources = mockk(relaxed = true)
private val appConfig: AppConfig = mockk(relaxed = true)
private val formatters: List<StatsFormatter> = listOf(mockk(relaxed = true))

private lateinit var statsGeneratorApplication: StatsGeneratorApplication

@BeforeEach
fun setUp() {
statsGeneratorApplication = StatsGeneratorApplication(
prReviewerStatsService,
prAuthorStatsService,
resources,
appConfig,
formatters
)
}

@Test
fun `generateAuthorStats should call authorStats and formatAuthorStats for each user`() = runBlocking {
val userIds = listOf("user1", "user2")
val authorStats = AuthorStats(
AuthorPrStats(
authorUserId = "user1",
totalPrsCreated = 0,
totalIssueComments = 0,
totalPrSubmissionComments = 0,
totalCodeReviewComments = 0
),
emptyList()
)

coEvery { appConfig.get().userIds } returns userIds
coEvery { prAuthorStatsService.authorStats(any()) } returns authorStats

statsGeneratorApplication.generateAuthorStats()

userIds.forEach { userId ->
coVerify { prAuthorStatsService.authorStats(userId) }
formatters.forEach { formatter ->
verify { formatter.formatAuthorStats(authorStats) }
}
}
}

@Test
fun `generateReviewerStats should call reviewerStats and formatReviewerStats for each user`() = runBlocking {
val userIds = listOf("user1", "user2")
val reviewerStats = ReviewerReviewStats(
repoId = "repo_id",
reviewerId = "user1",
average = Duration.ZERO,
totalReviews = 1,
reviewedPrStats = emptyList(),
reviewedForPrStats = emptyMap()
)

coEvery { appConfig.get().userIds } returns userIds
coEvery { prReviewerStatsService.reviewerStats(any()) } returns reviewerStats

statsGeneratorApplication.generateReviewerStats()

userIds.forEach { userId ->
coVerify { prReviewerStatsService.reviewerStats(userId) }
formatters.forEach { formatter ->
verify { formatter.formatReviewerStats(reviewerStats) }
}
}
}
}