1
1
package cc.unitmesh.devti.language.compiler.exec
2
2
3
- import cc.unitmesh.devti.command.dataprovider.BuiltinCommand
4
- import com.intellij.openapi.project.Project
5
3
import com.intellij.testFramework.fixtures.BasePlatformTestCase
6
4
import kotlinx.coroutines.runBlocking
7
- import org.mockito.Mockito
8
5
9
6
class LibraryVersionFetchInsCommandTest : BasePlatformTestCase () {
10
-
11
- fun testCommandName () {
12
- val project = Mockito .mock(Project ::class .java)
13
- val command = LibraryVersionFetchInsCommand (project, " npm:react" , " " )
14
- assertEquals(BuiltinCommand .LIBRARY_VERSION_FETCH , command.commandName)
15
- }
16
-
17
- fun testJsonFormat () = runBlocking {
18
- val project = Mockito .mock(Project ::class .java)
19
-
20
- // Test JSON format
21
- val jsonContent = """ {"name": "react", "type": "npm"}"""
22
- val command = LibraryVersionFetchInsCommand (project, " " , jsonContent)
23
- val result = command.execute()
24
- assertNotNull(result)
25
- // Note: This will fail in test environment without network, but validates parsing
26
- }
27
-
28
- fun testLegacyFormat () = runBlocking {
29
- val project = Mockito .mock(Project ::class .java)
30
-
31
- // Test legacy format with explicit type
32
- val command1 = LibraryVersionFetchInsCommand (project, " npm:react" , " " )
33
- val result1 = command1.execute()
34
- assertNotNull(result1)
35
-
36
- // Test legacy format with auto-detect
37
- val command2 = LibraryVersionFetchInsCommand (project, " react" , " " )
38
- val result2 = command2.execute()
39
- assertNotNull(result2)
40
- }
41
-
42
- fun testInvalidInput () = runBlocking {
43
- val project = Mockito .mock(Project ::class .java)
44
-
45
- // Empty input
46
- val command1 = LibraryVersionFetchInsCommand (project, " " )
47
- val result1 = command1.execute()
48
- assertNotNull(result1)
49
- assertTrue(" Should show usage" , result1!! .contains(" Usage" ))
50
-
51
- // Unsupported type
52
- val command2 = LibraryVersionFetchInsCommand (project, " unknown:package" )
53
- val result2 = command2.execute()
54
- assertNotNull(result2)
55
- assertTrue(" Should show unsupported error" , result2!! .contains(" Unsupported" ))
56
- }
57
-
58
7
fun testAutoDetection () = runBlocking {
59
8
val project = myFixture.project
60
-
61
- // Test auto detection - this will try multiple registries
62
- val command = LibraryVersionFetchInsCommand (project, " react" )
63
- val result = command.execute()
64
- assertNotNull(result)
65
- // Should either find versions or show no versions found
66
- assertTrue(" Should either show versions or not found error" ,
67
- result!! .contains(" Library versions" ) || result.contains(" No versions found" ))
68
- }
69
9
70
- fun testNetworkErrorHandling () = runBlocking {
71
- val project = Mockito .mock(Project ::class .java)
72
-
73
- // Test with invalid package name that should cause network error
74
- val command = LibraryVersionFetchInsCommand (project, " npm:this-package-definitely-does-not-exist-12345" )
10
+ val command = LibraryVersionFetchInsCommand (
11
+ project, " npm" , codeContent = """ {
12
+ "name": "react",
13
+ "type": "npm"
14
+ }"""
15
+ )
75
16
val result = command.execute()
76
17
assertNotNull(result)
77
- // Should gracefully handle network errors
78
- assertTrue(" Should handle network errors gracefully" ,
79
- result!! .contains(" not found" ) || result.contains(" failed" ))
18
+ // Should either find versions or show no versions found
19
+ assertTrue(result!! .contains(" ." ))
80
20
}
81
21
}
0 commit comments