-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The plugin is now implemented as a Service and it now loads any activ…
…e entry on load-up.
- Loading branch information
1 parent
4b059ff
commit e9b0aae
Showing
11 changed files
with
179 additions
and
36 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
10 changes: 0 additions & 10 deletions
10
src/main/kotlin/io/github/ricardormdev/clockifyplugin/PluginFactory.kt
This file was deleted.
Oops, something went wrong.
5 changes: 4 additions & 1 deletion
5
src/main/kotlin/io/github/ricardormdev/clockifyplugin/PluginLoader.kt
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
90 changes: 82 additions & 8 deletions
90
src/test/kotlin/io/github/ricardormdev/clockifyplugin/RepositoryTest.kt
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 |
---|---|---|
@@ -1,24 +1,98 @@ | ||
package io.github.ricardormdev.clockifyplugin | ||
|
||
import io.github.ricardormdev.clockifyplugin.api.API | ||
import io.github.ricardormdev.clockifyplugin.api.models.Project | ||
import io.github.ricardormdev.clockifyplugin.api.models.Tag | ||
import io.github.ricardormdev.clockifyplugin.api.models.UserInterface | ||
import io.github.ricardormdev.clockifyplugin.api.models.Workspace | ||
import io.github.ricardormdev.clockifyplugin.api.websocket.authentication.AuthenticateTokens | ||
import io.github.ricardormdev.clockifyplugin.api.websocket.authentication.UserLogin | ||
import io.github.ricardormdev.clockifyplugin.settings.ApplicationSettingsState | ||
import io.github.ricardormdev.clockifyplugin.settings.settingsState | ||
import io.mockk.* | ||
import org.junit.Before | ||
import org.junit.Test | ||
import kotlin.test.assertTrue | ||
|
||
class RepositoryTest { | ||
|
||
@Test | ||
fun testLogin() { | ||
fun testWorking() { | ||
val plugin = buildPlugin() | ||
|
||
assertTrue(plugin.getStatusMessage().contains("You are not working."), "The message should mention is not working") | ||
plugin.startWorking("workspaceA", "a", true, "Random Description") | ||
assertTrue(plugin.logged, "The user should be logged.") | ||
assertTrue(plugin.working, "The status should be working.") | ||
val timer : PluginTimer = getField("timer", plugin) | ||
assertTrue(plugin.getStatusMessage().contains("You've worked for:"), "The message should mention is working") | ||
Thread.sleep(1000) | ||
assertTrue(timer.getTiming() > 0, "The timer should be started.") | ||
} | ||
|
||
fun buildPlugin() : Plugin { | ||
val plugin = Plugin() | ||
val auther = mockAuthenticator() | ||
val controller = mockController() | ||
val api = mockAPI() | ||
|
||
assignVarToObj("user", controller, api.getUser("user")) | ||
assignVarToObj("dataController", plugin, controller) | ||
assignVarToObj("api", plugin, api) | ||
assignVarToObj("timer", plugin, PluginTimer(plugin)) | ||
assignVarToObj("authenticator", plugin, auther) | ||
plugin.logged = true | ||
|
||
return plugin | ||
} | ||
|
||
@Test | ||
fun testWorking() { | ||
val plugin = Plugin() | ||
val timer = PluginTimer(plugin) | ||
fun assignVarToObj(name: String, target: Any, value: Any) { | ||
val field = target::class.java.getDeclaredField(name) | ||
field.isAccessible = true | ||
field.set(target, value) | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T> getField(fieldName: String, target: Any) : T { | ||
val field = target::class.java.getDeclaredField(fieldName) | ||
field.isAccessible = true | ||
return field.get(target) as T | ||
} | ||
|
||
fun mockController() : PluginDataController { | ||
return PluginDataController(mockAPI()) | ||
} | ||
|
||
fun mockAuthenticator(): AuthenticateTokens { | ||
return mockkClass(AuthenticateTokens::class) { | ||
every { retrieveFullUser() } returns UserLogin("user", "email@domain.com", "UserName", "token", "refreshToken", arrayOf()) | ||
} | ||
} | ||
|
||
fun mockAPI(): API { | ||
return mockkClass(API::class) { | ||
every { getWorkspaces() } returns arrayOf( | ||
Workspace("workspaceA", "workspaceA"), | ||
Workspace("workspaceB", "workspaceB") | ||
) | ||
|
||
every { getProjects("workspaceA") } returns | ||
arrayOf(Project("a", "Project A"), Project("b", "Project B"), Project("b", "Project B")) | ||
|
||
every { getProjects("workspaceB") } returns arrayOf( | ||
Project("a", "Project A"), | ||
Project("b", "Project B"), | ||
Project("b", "Project B")) | ||
|
||
every { getUser("user") } returns | ||
UserInterface("user", "UserName", "workspaceA") | ||
|
||
every { getTags(any()) } returns | ||
arrayOf(Tag("TagA", "TagNameA"), Tag("TagB", "TagNameB")) | ||
|
||
|
||
timer.startTimer() | ||
println(timer.getTiming()) | ||
assert(timer.getTiming() > 0) | ||
every { startWorking(any(), any(), any(), any()) } returns Unit | ||
} | ||
} | ||
|
||
} |