@@ -234,5 +234,80 @@ describe(commands.CALENDARGROUP_GET, () => {
234234 await command . action ( logger , { options : commandOptionsSchema . parse ( { id : calendarGroupId , userId : otherUserId } ) } ) ;
235235 assert ( loggerLogSpy . calledOnceWith ( calendarGroupResponse ) ) ;
236236 } ) ;
237+
238+ it ( 'retrieves calendar group for a user specified by name using delegated permissions with shared scope' , async ( ) => {
239+ sinonUtil . restore ( accessToken . getScopesFromAccessToken ) ;
240+ sinon . stub ( accessToken , 'getScopesFromAccessToken' ) . returns ( [ 'Calendars.Read.Shared' ] ) ;
241+
242+ const expectedFilterUrl = `https://graph.microsoft.com/v1.0/users('${ otherUserId } ')/calendarGroups?$select=id,name&$filter=name eq 'Personal%20Events'` ;
243+ sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
244+ if ( opts . url === expectedFilterUrl ) {
245+ return calendarGroupsResponseForFilter ;
246+ }
247+
248+ if ( opts . url === `https://graph.microsoft.com/v1.0/users('${ otherUserId } ')/calendarGroups/${ resolvedCalendarGroupId } ` ) {
249+ return calendarGroupResponse ;
250+ }
251+
252+ throw 'Invalid request' ;
253+ } ) ;
254+
255+ await command . action ( logger , { options : commandOptionsSchema . parse ( { name : calendarGroupName , userId : otherUserId } ) } ) ;
256+ assert ( loggerLogSpy . calledOnceWith ( calendarGroupResponse ) ) ;
257+ } ) ;
258+
259+ it ( 'retrieves calendar group for the signed-in user with verbose output' , async ( ) => {
260+ const logToStderrSpy = sinon . spy ( logger , 'logToStderr' ) ;
261+
262+ sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
263+ if ( opts . url === `https://graph.microsoft.com/v1.0/me/calendarGroups/${ calendarGroupId } ` ) {
264+ return calendarGroupResponse ;
265+ }
266+
267+ throw 'Invalid request' ;
268+ } ) ;
269+
270+ await command . action ( logger , { options : commandOptionsSchema . parse ( { id : calendarGroupId , verbose : true } ) } ) ;
271+
272+ assert ( loggerLogSpy . calledOnceWith ( calendarGroupResponse ) ) ;
273+ assert ( logToStderrSpy . calledOnce ) ;
274+ } ) ;
275+
276+ it ( 'throws an error when calendar group name does not match any results' , async ( ) => {
277+ const expectedFilterUrl = `https://graph.microsoft.com/v1.0/me/calendarGroups?$select=id,name&$filter=name eq 'Personal%20Events'` ;
278+ sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
279+ if ( opts . url === expectedFilterUrl ) {
280+ return { value : [ ] } ;
281+ }
282+
283+ throw 'Invalid request' ;
284+ } ) ;
285+
286+ await assert . rejects (
287+ command . action ( logger , { options : commandOptionsSchema . parse ( { name : calendarGroupName } ) } ) ,
288+ new CommandError ( `The specified calendar group '${ calendarGroupName } ' does not exist.` )
289+ ) ;
290+ } ) ;
291+
292+ it ( 'retrieves calendar group for a user specified by userName using delegated permissions with shared scope (ReadWrite.Shared)' , async ( ) => {
293+ sinonUtil . restore ( accessToken . getScopesFromAccessToken ) ;
294+ sinon . stub ( accessToken , 'getScopesFromAccessToken' ) . returns ( [ 'Calendars.ReadWrite.Shared' ] ) ;
295+
296+ const expectedFilterUrl = `https://graph.microsoft.com/v1.0/users('${ userName } ')/calendarGroups?$select=id,name&$filter=name eq 'Personal%20Events'` ;
297+ sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
298+ if ( opts . url === expectedFilterUrl ) {
299+ return calendarGroupsResponseForFilter ;
300+ }
301+
302+ if ( opts . url === `https://graph.microsoft.com/v1.0/users('${ userName } ')/calendarGroups/${ resolvedCalendarGroupId } ` ) {
303+ return calendarGroupResponse ;
304+ }
305+
306+ throw 'Invalid request' ;
307+ } ) ;
308+
309+ await command . action ( logger , { options : commandOptionsSchema . parse ( { name : calendarGroupName , userName } ) } ) ;
310+ assert ( loggerLogSpy . calledOnceWith ( calendarGroupResponse ) ) ;
311+ } ) ;
237312} ) ;
238313
0 commit comments