Skip to content

Commit

Permalink
fix:improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Feb 6, 2024
1 parent 198fcd7 commit ba0aca8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class WorkflowDataContextService(project: Project) {
settingsService.state.apiToken
}

val requestExecutor = GithubApiRequestExecutor.Factory.Companion.getInstance().create(token)
val requestExecutor = GithubApiRequestExecutor.Factory.Companion.getInstance().create(token=token)
val singleRunDataLoader = SingleRunDataLoader(requestExecutor)
requestExecutor.addListener(singleRunDataLoader) {
singleRunDataLoader.invalidateAllData()
Expand Down
16 changes: 11 additions & 5 deletions src/test/kotlin/com/dsoftware/ghmanager/TestWindowTabController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.verify
import junit.framework.TestCase
import org.jetbrains.plugins.github.api.GithubApiRequest
import org.jetbrains.plugins.github.api.GithubApiRequestExecutor
Expand All @@ -28,6 +29,11 @@ class TestWindowTabController : GitHubActionsManagerBaseTest() {
mockGhActionsService(setOf("http://github.com/owner/repo"), setOf("account1"))
mockkStatic(GHCompatibilityUtil::class)
every { GHCompatibilityUtil.getOrRequestToken(any(), any()) } returns "token"
executorMock = mockk<GithubApiRequestExecutor>(relaxed = true) {}
mockkObject(GithubApiRequestExecutor.Factory)
every { GithubApiRequestExecutor.Factory.getInstance() } returns mockk<GithubApiRequestExecutor.Factory> {
every { create(token = any()) } returns executorMock
}
workflowDataContextService = project.service<WorkflowDataContextService>()
factory.init(toolWindow)
executeSomeCoroutineTasksAndDispatchAllInvocationEvents(project)
Expand All @@ -48,6 +54,9 @@ class TestWindowTabController : GitHubActionsManagerBaseTest() {
val workflowRunSelectionContext: WorkflowRunSelectionContext =
workflowDataContextService.repositories.values.first().value.get()
TestCase.assertEquals(0, workflowRunSelectionContext.runsListModel.size)
verify {
executorMock.execute(any(), ofType(GithubApiRequest::class))
}
}

private fun mockGithubApiRequestExecutor(
Expand All @@ -69,7 +78,7 @@ class TestWindowTabController : GitHubActionsManagerBaseTest() {
branch
})
val workflowTypesResponse = WorkflowTypes(workflowTypes.size, workflowTypes.toList())
executorMock = mockk<GithubApiRequestExecutor>(relaxed = true) {
executorMock.apply {
every {
execute(any(), any<GithubApiRequest<WorkflowRuns>>())
} returns WorkflowRuns(workflowRunsList.size, workflowRunsList.toList())
Expand All @@ -83,9 +92,6 @@ class TestWindowTabController : GitHubActionsManagerBaseTest() {
execute(any(), any<GithubApiRequest<WorkflowTypes>>())
} returns workflowTypesResponse
}
mockkObject(GithubApiRequestExecutor.Factory)
every { GithubApiRequestExecutor.Factory.getInstance() } returns mockk<GithubApiRequestExecutor.Factory> {
every { create(token = any()) } returns executorMock
}

}
}

0 comments on commit ba0aca8

Please sign in to comment.