@@ -8,7 +8,9 @@ import { createDATools, createEDSTools } from '../src/tools/tools';
88function makeEdsClient ( overrides : Partial < EDSAdminClient > = { } ) : EDSAdminClient {
99 return {
1010 preview : vi . fn ( ) . mockResolvedValue ( { status : 200 , path : '/docs/index' , url : 'https://main--repo--org.hlx.page/docs/index' } ) ,
11+ unpreview : vi . fn ( ) . mockResolvedValue ( { status : 200 , path : '/docs/index' } ) ,
1112 publishLive : vi . fn ( ) . mockResolvedValue ( { status : 200 , path : '/docs/index' , url : 'https://main--repo--org.hlx.live/docs/index' } ) ,
13+ unpublishLive : vi . fn ( ) . mockResolvedValue ( { status : 200 , path : '/docs/index' } ) ,
1214 ...overrides ,
1315 } as unknown as EDSAdminClient ;
1416}
@@ -85,6 +87,60 @@ describe('eds_publish tool', () => {
8587 } ) ;
8688} ) ;
8789
90+ describe ( 'content_unpreview tool' , ( ) => {
91+ it ( 'is registered when edsClient is provided' , ( ) => {
92+ const tools = createEDSTools ( makeEdsClient ( ) ) ;
93+ expect ( tools ) . toHaveProperty ( 'content_unpreview' ) ;
94+ } ) ;
95+
96+ it ( 'calls edsClient.unpreview() and returns result' , async ( ) => {
97+ const edsClient = makeEdsClient ( ) ;
98+ const tools = createEDSTools ( edsClient ) ;
99+
100+ const result = await tools . content_unpreview . execute ( { org : 'o' , repo : 'r' , path : '/docs/index' } , { } as any ) ;
101+
102+ expect ( edsClient . unpreview ) . toHaveBeenCalledWith ( 'o' , 'r' , '/docs/index' ) ;
103+ expect ( result ) . toMatchObject ( { status : 200 , path : '/docs/index' } ) ;
104+ } ) ;
105+
106+ it ( 'returns { error, status } when unpreview throws' , async ( ) => {
107+ const edsClient = makeEdsClient ( {
108+ unpreview : vi . fn ( ) . mockRejectedValue ( { status : 404 , message : 'Not Found' } ) ,
109+ } ) ;
110+ const tools = createEDSTools ( edsClient ) ;
111+
112+ const result = await tools . content_unpreview . execute ( { org : 'o' , repo : 'r' , path : '/p' } , { } as any ) ;
113+ expect ( result ) . toMatchObject ( { error : 'Not Found' , status : 404 } ) ;
114+ } ) ;
115+ } ) ;
116+
117+ describe ( 'content_unpublish tool' , ( ) => {
118+ it ( 'is registered when edsClient is provided' , ( ) => {
119+ const tools = createEDSTools ( makeEdsClient ( ) ) ;
120+ expect ( tools ) . toHaveProperty ( 'content_unpublish' ) ;
121+ } ) ;
122+
123+ it ( 'calls edsClient.unpublishLive() and returns result' , async ( ) => {
124+ const edsClient = makeEdsClient ( ) ;
125+ const tools = createEDSTools ( edsClient ) ;
126+
127+ const result = await tools . content_unpublish . execute ( { org : 'o' , repo : 'r' , path : '/docs/index' } , { } as any ) ;
128+
129+ expect ( edsClient . unpublishLive ) . toHaveBeenCalledWith ( 'o' , 'r' , '/docs/index' ) ;
130+ expect ( result ) . toMatchObject ( { status : 200 , path : '/docs/index' } ) ;
131+ } ) ;
132+
133+ it ( 'returns { error, status } when unpublishLive throws' , async ( ) => {
134+ const edsClient = makeEdsClient ( {
135+ unpublishLive : vi . fn ( ) . mockRejectedValue ( { status : 502 , message : 'Live error' } ) ,
136+ } ) ;
137+ const tools = createEDSTools ( edsClient ) ;
138+
139+ const result = await tools . content_unpublish . execute ( { org : 'o' , repo : 'r' , path : '/p' } , { } as any ) ;
140+ expect ( result ) . toMatchObject ( { error : 'Live error' , status : 502 } ) ;
141+ } ) ;
142+ } ) ;
143+
88144describe ( 'DA tools still registered when client provided' , ( ) => {
89145 it ( 'da_list_sources present when daClient is provided' , ( ) => {
90146 // Minimal mock for DAAdminClient
0 commit comments