@@ -8,6 +8,7 @@ import { cli } from '../../../../cli/cli.js';
88import request from '../../../../request.js' ;
99import { telemetry } from '../../../../telemetry.js' ;
1010import { accessToken } from '../../../../utils/accessToken.js' ;
11+ import { calendarGroup } from '../../../../utils/calendarGroup.js' ;
1112import { pid } from '../../../../utils/pid.js' ;
1213import { session } from '../../../../utils/session.js' ;
1314import { sinonUtil } from '../../../../utils/sinonUtil.js' ;
@@ -20,17 +21,6 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
2021 const userId = 'b743445a-112c-4fda-9afd-05943f9c7b36' ;
2122 const userName = 'john.doe@contoso.com' ;
2223
23- const calendarGroupsResponse = {
24- value : [
25- {
26- id : calendarGroupId ,
27- name : calendarGroupName ,
28- changeKey : 'nfZyf7VcrEKLNoU37KWlkQAAA0x0+w==' ,
29- classId : '0006f0b7-0000-0000-c000-000000000046'
30- }
31- ]
32- } ;
33-
3424 let log : string [ ] ;
3525 let logger : Logger ;
3626 let commandInfo : CommandInfo ;
@@ -77,6 +67,7 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
7767 afterEach ( ( ) => {
7868 sinonUtil . restore ( [
7969 accessToken . isAppOnlyAccessToken ,
70+ calendarGroup . getUserCalendarGroupByName ,
8071 request . get ,
8172 request . delete ,
8273 cli . promptForConfirmation
@@ -186,13 +177,7 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
186177 } ) ;
187178
188179 it ( 'removes the calendar group specified by name for the signed-in user' , async ( ) => {
189- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
190- if ( opts . url === `https://graph.microsoft.com/v1.0/me/calendarGroups?$filter=name eq '${ calendarGroupName } '` ) {
191- return calendarGroupsResponse ;
192- }
193-
194- throw 'Invalid request' ;
195- } ) ;
180+ sinon . stub ( calendarGroup , 'getUserCalendarGroupByName' ) . resolves ( { id : calendarGroupId , name : calendarGroupName } ) ;
196181
197182 const deleteRequestStub = sinon . stub ( request , 'delete' ) . callsFake ( async ( opts ) => {
198183 if ( opts . url === `https://graph.microsoft.com/v1.0/me/calendarGroups/${ calendarGroupId } ` ) {
@@ -210,13 +195,7 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
210195 } ) ;
211196
212197 it ( 'removes the calendar group specified by name for the signed-in user (verbose)' , async ( ) => {
213- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
214- if ( opts . url === `https://graph.microsoft.com/v1.0/me/calendarGroups?$filter=name eq '${ calendarGroupName } '` ) {
215- return calendarGroupsResponse ;
216- }
217-
218- throw 'Invalid request' ;
219- } ) ;
198+ sinon . stub ( calendarGroup , 'getUserCalendarGroupByName' ) . resolves ( { id : calendarGroupId , name : calendarGroupName } ) ;
220199
221200 const deleteRequestStub = sinon . stub ( request , 'delete' ) . callsFake ( async ( opts ) => {
222201 if ( opts . url === `https://graph.microsoft.com/v1.0/me/calendarGroups/${ calendarGroupId } ` ) {
@@ -245,7 +224,7 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
245224
246225 it ( 'removes the calendar group specified by id for a user specified by userName' , async ( ) => {
247226 const deleteRequestStub = sinon . stub ( request , 'delete' ) . callsFake ( async ( opts ) => {
248- if ( opts . url === `https://graph.microsoft.com/v1.0/users('${ userName } ')/calendarGroups/${ calendarGroupId } ` ) {
227+ if ( opts . url === `https://graph.microsoft.com/v1.0/users('john.doe%40contoso.com ')/calendarGroups/${ calendarGroupId } ` ) {
249228 return ;
250229 }
251230
@@ -257,13 +236,7 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
257236 } ) ;
258237
259238 it ( 'removes the calendar group specified by name for a user specified by userId' , async ( ) => {
260- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
261- if ( opts . url === `https://graph.microsoft.com/v1.0/users('${ userId } ')/calendarGroups?$filter=name eq '${ calendarGroupName } '` ) {
262- return calendarGroupsResponse ;
263- }
264-
265- throw 'Invalid request' ;
266- } ) ;
239+ sinon . stub ( calendarGroup , 'getUserCalendarGroupByName' ) . resolves ( { id : calendarGroupId , name : calendarGroupName } ) ;
267240
268241 const deleteRequestStub = sinon . stub ( request , 'delete' ) . callsFake ( async ( opts ) => {
269242 if ( opts . url === `https://graph.microsoft.com/v1.0/users('${ userId } ')/calendarGroups/${ calendarGroupId } ` ) {
@@ -278,16 +251,10 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
278251 } ) ;
279252
280253 it ( 'removes the calendar group specified by name for a user specified by userName' , async ( ) => {
281- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
282- if ( opts . url === `https://graph.microsoft.com/v1.0/users('${ userName } ')/calendarGroups?$filter=name eq '${ calendarGroupName } '` ) {
283- return calendarGroupsResponse ;
284- }
285-
286- throw 'Invalid request' ;
287- } ) ;
254+ sinon . stub ( calendarGroup , 'getUserCalendarGroupByName' ) . resolves ( { id : calendarGroupId , name : calendarGroupName } ) ;
288255
289256 const deleteRequestStub = sinon . stub ( request , 'delete' ) . callsFake ( async ( opts ) => {
290- if ( opts . url === `https://graph.microsoft.com/v1.0/users('${ userName } ')/calendarGroups/${ calendarGroupId } ` ) {
257+ if ( opts . url === `https://graph.microsoft.com/v1.0/users('john.doe%40contoso.com ')/calendarGroups/${ calendarGroupId } ` ) {
291258 return ;
292259 }
293260
@@ -325,17 +292,11 @@ describe(commands.CALENDARGROUP_REMOVE, () => {
325292 } ) ;
326293
327294 it ( 'throws error when calendar group specified by name is not found' , async ( ) => {
328- sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
329- if ( opts . url === `https://graph.microsoft.com/v1.0/me/calendarGroups?$filter=name eq '${ calendarGroupName } '` ) {
330- return { value : [ ] } ;
331- }
332-
333- throw 'Invalid request' ;
334- } ) ;
295+ sinon . stub ( calendarGroup , 'getUserCalendarGroupByName' ) . rejects ( new Error ( `The specified calendar group '${ calendarGroupName } ' does not exist.` ) ) ;
335296
336297 await assert . rejects (
337298 command . action ( logger , { options : commandOptionsSchema . parse ( { name : calendarGroupName , force : true } ) } ) ,
338- new CommandError ( `Calendar group with name '${ calendarGroupName } ' not found .` )
299+ new CommandError ( `The specified calendar group '${ calendarGroupName } ' does not exist .` )
339300 ) ;
340301 } ) ;
341302
0 commit comments