@@ -4,14 +4,21 @@ import type { MarketplaceItem } from "@roo-code/types"
44
55import { MarketplaceManager } from "../MarketplaceManager"
66
7- // Mock axios
8- vi . mock ( "axios" )
9-
10- // Mock the cloud config
7+ // Mock CloudService
118vi . mock ( "@roo-code/cloud" , ( ) => ( {
129 getRooCodeApiUrl : ( ) => "https://test.api.com" ,
10+ CloudService : {
11+ hasInstance : vi . fn ( ) ,
12+ instance : {
13+ isAuthenticated : vi . fn ( ) ,
14+ getOrganizationSettings : vi . fn ( ) ,
15+ } ,
16+ } ,
1317} ) )
1418
19+ // Mock axios
20+ vi . mock ( "axios" )
21+
1522// Mock TelemetryService
1623vi . mock ( "../../../../packages/telemetry/src/TelemetryService" , ( ) => ( {
1724 TelemetryService : {
@@ -165,8 +172,9 @@ describe("MarketplaceManager", () => {
165172
166173 const result = await manager . getMarketplaceItems ( )
167174
168- expect ( result . items ) . toHaveLength ( 1 )
169- expect ( result . items [ 0 ] . name ) . toBe ( "Test Mode" )
175+ expect ( result . marketplaceItems ) . toHaveLength ( 1 )
176+ expect ( result . marketplaceItems [ 0 ] . name ) . toBe ( "Test Mode" )
177+ expect ( result . organizationMcps ) . toHaveLength ( 0 )
170178 } )
171179
172180 it ( "should handle API errors gracefully" , async ( ) => {
@@ -175,9 +183,124 @@ describe("MarketplaceManager", () => {
175183
176184 const result = await manager . getMarketplaceItems ( )
177185
178- expect ( result . items ) . toHaveLength ( 0 )
186+ expect ( result . marketplaceItems ) . toHaveLength ( 0 )
187+ expect ( result . organizationMcps ) . toHaveLength ( 0 )
179188 expect ( result . errors ) . toEqual ( [ "API request failed" ] )
180189 } )
190+
191+ it ( "should return organization MCPs when available" , async ( ) => {
192+ const { CloudService } = await import ( "@roo-code/cloud" )
193+
194+ // Mock CloudService to return organization settings
195+ vi . mocked ( CloudService . hasInstance ) . mockReturnValue ( true )
196+ vi . mocked ( CloudService . instance . isAuthenticated ) . mockReturnValue ( true )
197+ vi . mocked ( CloudService . instance . getOrganizationSettings ) . mockReturnValue ( {
198+ version : 1 ,
199+ mcps : [
200+ {
201+ id : "org-mcp-1" ,
202+ name : "Organization MCP" ,
203+ description : "An organization MCP" ,
204+ url : "https://example.com/org-mcp" ,
205+ content : '{"command": "node", "args": ["org-server.js"]}' ,
206+ } ,
207+ ] ,
208+ hiddenMcps : [ ] ,
209+ allowList : { allowAll : true , providers : { } } ,
210+ defaultSettings : { } ,
211+ } )
212+
213+ // Mock the config loader to return test data
214+ const mockItems : MarketplaceItem [ ] = [
215+ {
216+ id : "test-mcp" ,
217+ name : "Test MCP" ,
218+ description : "A test MCP" ,
219+ type : "mcp" ,
220+ url : "https://example.com/test-mcp" ,
221+ content : '{"command": "node", "args": ["server.js"]}' ,
222+ } ,
223+ ]
224+
225+ vi . spyOn ( manager [ "configLoader" ] , "loadAllItems" ) . mockResolvedValue ( mockItems )
226+
227+ const result = await manager . getMarketplaceItems ( )
228+
229+ expect ( result . organizationMcps ) . toHaveLength ( 1 )
230+ expect ( result . organizationMcps [ 0 ] . name ) . toBe ( "Organization MCP" )
231+ expect ( result . marketplaceItems ) . toHaveLength ( 1 )
232+ expect ( result . marketplaceItems [ 0 ] . name ) . toBe ( "Test MCP" )
233+ } )
234+
235+ it ( "should filter out hidden MCPs from marketplace results" , async ( ) => {
236+ const { CloudService } = await import ( "@roo-code/cloud" )
237+
238+ // Mock CloudService to return organization settings with hidden MCPs
239+ vi . mocked ( CloudService . hasInstance ) . mockReturnValue ( true )
240+ vi . mocked ( CloudService . instance . isAuthenticated ) . mockReturnValue ( true )
241+ vi . mocked ( CloudService . instance . getOrganizationSettings ) . mockReturnValue ( {
242+ version : 1 ,
243+ mcps : [ ] ,
244+ hiddenMcps : [ "hidden-mcp" ] ,
245+ allowList : { allowAll : true , providers : { } } ,
246+ defaultSettings : { } ,
247+ } )
248+
249+ // Mock the config loader to return test data including a hidden MCP
250+ const mockItems : MarketplaceItem [ ] = [
251+ {
252+ id : "visible-mcp" ,
253+ name : "Visible MCP" ,
254+ description : "A visible MCP" ,
255+ type : "mcp" ,
256+ url : "https://example.com/visible-mcp" ,
257+ content : '{"command": "node", "args": ["visible.js"]}' ,
258+ } ,
259+ {
260+ id : "hidden-mcp" ,
261+ name : "Hidden MCP" ,
262+ description : "A hidden MCP" ,
263+ type : "mcp" ,
264+ url : "https://example.com/hidden-mcp" ,
265+ content : '{"command": "node", "args": ["hidden.js"]}' ,
266+ } ,
267+ ]
268+
269+ vi . spyOn ( manager [ "configLoader" ] , "loadAllItems" ) . mockResolvedValue ( mockItems )
270+
271+ const result = await manager . getMarketplaceItems ( )
272+
273+ expect ( result . marketplaceItems ) . toHaveLength ( 1 )
274+ expect ( result . marketplaceItems [ 0 ] . name ) . toBe ( "Visible MCP" )
275+ expect ( result . organizationMcps ) . toHaveLength ( 0 )
276+ } )
277+
278+ it ( "should handle CloudService not being available" , async ( ) => {
279+ const { CloudService } = await import ( "@roo-code/cloud" )
280+
281+ // Mock CloudService to not be available
282+ vi . mocked ( CloudService . hasInstance ) . mockReturnValue ( false )
283+
284+ // Mock the config loader to return test data
285+ const mockItems : MarketplaceItem [ ] = [
286+ {
287+ id : "test-mcp" ,
288+ name : "Test MCP" ,
289+ description : "A test MCP" ,
290+ type : "mcp" ,
291+ url : "https://example.com/test-mcp" ,
292+ content : '{"command": "node", "args": ["server.js"]}' ,
293+ } ,
294+ ]
295+
296+ vi . spyOn ( manager [ "configLoader" ] , "loadAllItems" ) . mockResolvedValue ( mockItems )
297+
298+ const result = await manager . getMarketplaceItems ( )
299+
300+ expect ( result . organizationMcps ) . toHaveLength ( 0 )
301+ expect ( result . marketplaceItems ) . toHaveLength ( 1 )
302+ expect ( result . marketplaceItems [ 0 ] . name ) . toBe ( "Test MCP" )
303+ } )
181304 } )
182305
183306 describe ( "installMarketplaceItem" , ( ) => {
0 commit comments