@@ -14,6 +14,7 @@ import { session } from '../../../../utils/session.js';
1414import { sinonUtil } from '../../../../utils/sinonUtil.js' ;
1515import commands from '../../commands.js' ;
1616import command from './page-list.js' ;
17+ import { accessToken } from '../../../../utils/accessToken.js' ;
1718import { settingsNames } from '../../../../settingsNames.js' ;
1819
1920describe ( commands . PAGE_LIST , ( ) => {
@@ -76,6 +77,7 @@ describe(commands.PAGE_LIST, () => {
7677 let logger : Logger ;
7778 let loggerLogSpy : sinon . SinonSpy ;
7879 let commandInfo : CommandInfo ;
80+ let accessTokenStub : sinon . SinonStub ;
7981
8082 before ( ( ) => {
8183 sinon . stub ( auth , 'restoreAuth' ) . resolves ( ) ;
@@ -84,13 +86,7 @@ describe(commands.PAGE_LIST, () => {
8486 sinon . stub ( session , 'getId' ) . returns ( '' ) ;
8587 auth . connection . active = true ;
8688 commandInfo = cli . getCommandInfo ( command ) ;
87- sinon . stub ( cli , 'getSettingWithDefaultValue' ) . callsFake ( ( settingName : string , defaultValue : any ) => {
88- if ( settingName === 'prompt' ) {
89- return false ;
90- }
91-
92- return defaultValue ;
93- } ) ;
89+ sinon . stub ( cli , 'getSettingWithDefaultValue' ) . callsFake ( ( settingName : string , defaultValue : any ) => settingName === settingsNames . prompt ? false : defaultValue ) ;
9490 } ) ;
9591
9692 beforeEach ( ( ) => {
@@ -107,14 +103,14 @@ describe(commands.PAGE_LIST, () => {
107103 }
108104 } ;
109105 loggerLogSpy = sinon . spy ( logger , 'log' ) ;
110- ( command as any ) . items = [ ] ;
106+ accessTokenStub = sinon . stub ( accessToken , 'assertAccessTokenType' ) . resolves ( ) ;
111107 } ) ;
112108
113109 afterEach ( ( ) => {
114110 sinonUtil . restore ( [
115111 request . get ,
116112 odata . getAllItems ,
117- cli . getSettingWithDefaultValue
113+ accessToken . assertAccessTokenType
118114 ] ) ;
119115 } ) ;
120116
@@ -165,6 +161,13 @@ describe(commands.PAGE_LIST, () => {
165161 assert . strictEqual ( actual , true ) ;
166162 } ) ;
167163
164+ it ( 'enforces the user to use delegated permissions' , async ( ) => {
165+ sinon . stub ( odata , 'getAllItems' ) . resolves ( [ ] ) ;
166+
167+ await command . action ( logger , { options : { } } ) ;
168+ assert ( accessTokenStub . calledOnceWithExactly ( 'delegated' ) ) ;
169+ } ) ;
170+
168171 it ( 'lists Microsoft OneNote pages for the currently logged in user' , async ( ) => {
169172 sinon . stub ( odata , 'getAllItems' ) . callsFake ( async ( url : string ) => {
170173 if ( url === `https://graph.microsoft.com/v1.0/me/onenote/pages` ) {
@@ -191,7 +194,7 @@ describe(commands.PAGE_LIST, () => {
191194
192195 it ( 'lists Microsoft OneNote pages for user by name' , async ( ) => {
193196 sinon . stub ( odata , 'getAllItems' ) . callsFake ( async ( url : string ) => {
194- if ( url === `https://graph.microsoft.com/v1.0/users/${ userName } /onenote/pages` ) {
197+ if ( url === `https://graph.microsoft.com/v1.0/users/${ formatting . encodeQueryParameter ( userName ) } /onenote/pages` ) {
195198 return pageResponse . value ;
196199 }
197200 throw 'Invalid request' ;
@@ -215,7 +218,7 @@ describe(commands.PAGE_LIST, () => {
215218
216219 it ( 'lists Microsoft OneNote pages in group by name' , async ( ) => {
217220 sinon . stub ( odata , 'getAllItems' ) . callsFake ( async ( url : string ) => {
218- if ( url === `https://graph.microsoft.com/v1.0/groups?$filter=displayName eq '${ formatting . encodeQueryParameter ( groupName ) } '` ) {
221+ if ( url === `https://graph.microsoft.com/v1.0/groups?$filter=displayName eq '${ formatting . encodeQueryParameter ( groupName ) } '&$select=id ` ) {
219222 return [ {
220223 "id" : groupId ,
221224 "description" : groupName ,
@@ -277,7 +280,7 @@ describe(commands.PAGE_LIST, () => {
277280
278281 it ( 'throws error if group by displayName returns no results' , async ( ) => {
279282 sinon . stub ( odata , 'getAllItems' ) . callsFake ( async ( url : string ) => {
280- if ( url === `https://graph.microsoft.com/v1.0/groups?$filter=displayName eq '${ formatting . encodeQueryParameter ( groupName ) } '` ) {
283+ if ( url === `https://graph.microsoft.com/v1.0/groups?$filter=displayName eq '${ formatting . encodeQueryParameter ( groupName ) } '&$select=id ` ) {
281284 return [ ] ;
282285 }
283286 throw 'Invalid request' ;
@@ -287,17 +290,9 @@ describe(commands.PAGE_LIST, () => {
287290 } ) ;
288291
289292 it ( 'throws an error if group by displayName returns multiple results' , async ( ) => {
290- sinon . stub ( cli , 'getSettingWithDefaultValue' ) . callsFake ( ( settingName , defaultValue ) => {
291- if ( settingName === settingsNames . prompt ) {
292- return false ;
293- }
294-
295- return defaultValue ;
296- } ) ;
297-
298293 const duplicateGroupId = '9f3c2c36-1682-4922-9ae1-f57d2caf0de1' ;
299294 sinon . stub ( odata , 'getAllItems' ) . callsFake ( async ( url : string ) => {
300- if ( url === `https://graph.microsoft.com/v1.0/groups?$filter=displayName eq '${ formatting . encodeQueryParameter ( groupName ) } '` ) {
295+ if ( url === `https://graph.microsoft.com/v1.0/groups?$filter=displayName eq '${ formatting . encodeQueryParameter ( groupName ) } '&$select=id ` ) {
301296 return [ {
302297 "id" : groupId ,
303298 "description" : groupName ,
@@ -311,6 +306,7 @@ describe(commands.PAGE_LIST, () => {
311306 throw 'Invalid request' ;
312307 } ) ;
313308
314- await assert . rejects ( command . action ( logger , { options : { groupName : groupName } } as any ) , new CommandError ( "Multiple groups with name 'Dummy Group A' found. Found: bba4c915-0ac8-47a1-bd05-087a44c92d3b, 9f3c2c36-1682-4922-9ae1-f57d2caf0de1." ) ) ;
309+ await assert . rejects ( command . action ( logger , { options : { groupName : groupName } } ) ,
310+ new CommandError ( "Multiple groups with name 'Dummy Group A' found. Found: bba4c915-0ac8-47a1-bd05-087a44c92d3b, 9f3c2c36-1682-4922-9ae1-f57d2caf0de1." ) ) ;
315311 } ) ;
316312} ) ;
0 commit comments