@@ -15,24 +15,13 @@ import {
15
15
SharingLinkRole ,
16
16
SharingLinkScope ,
17
17
} from "@fluidframework/odsp-driver-definitions/internal" ;
18
- import { createChildLogger , MockLogger } from "@fluidframework/telemetry-utils/internal" ;
18
+ import { createChildLogger } from "@fluidframework/telemetry-utils/internal" ;
19
19
20
20
import { useCreateNewModule } from "../createFile/index.js" ;
21
- import { createOdspCreateContainerRequest } from "../createOdspCreateContainerRequest.js" ;
22
21
import { EpochTracker } from "../epochTracker.js" ;
23
22
import { LocalPersistentCache } from "../odspCache.js" ;
24
- import { OdspDocumentServiceFactory } from "../odspDocumentServiceFactory.js" ;
25
- import {
26
- OdspDriverUrlResolverForShareLink ,
27
- type ShareLinkFetcherProps ,
28
- } from "../odspDriverUrlResolverForShareLink.js" ;
29
23
import { getHashedDocumentId } from "../odspPublicUtils.js" ;
30
- import {
31
- IExistingFileInfo ,
32
- INewFileInfo ,
33
- createCacheSnapshotKey ,
34
- getOdspResolvedUrl ,
35
- } from "../odspUtils.js" ;
24
+ import { IExistingFileInfo , INewFileInfo , createCacheSnapshotKey } from "../odspUtils.js" ;
36
25
37
26
import { mockFetchOk } from "./mockFetch.js" ;
38
27
@@ -335,9 +324,7 @@ describe("Create New Utils Tests", () => {
335
324
} ) ;
336
325
337
326
// Extract the Base64 encoded value of `nav`
338
- const base64Value = odspResolvedUrl . shareLinkInfo . createLink . link . webUrl . match (
339
- / n a v = ( [ ^ & ] * ) / ,
340
- ) ?. [ 1 ] as string ;
327
+ const base64Value = mockSharingLinkData . webUrl . match ( / n a v = ( [ ^ & ] * ) / ) ?. [ 1 ] as string ;
341
328
// Decode the Base64 value to UTF-8, \r�� is being stored at the end of the string so we slice it off
342
329
const decodedValue = fromBase64ToUtf8 ( base64Value ) . slice ( 0 , - 3 ) ;
343
330
@@ -484,74 +471,69 @@ describe("Create New Utils Tests", () => {
484
471
assert ( ! odspResolvedUrl2 . isClpCompliantApp , "isClpCompliantApp should be falsy" ) ;
485
472
await epochTracker . removeEntries ( ) . catch ( ( ) => { } ) ;
486
473
} ) ;
487
-
488
- it ( "Should set the appropriate nav param info when a request is made" , async ( ) => {
489
- const odspDocumentServiceFactory = new OdspDocumentServiceFactory (
490
- async ( _options ) => "token" ,
491
- async ( _options ) => "token" ,
492
- new LocalPersistentCache ( 2000 ) ,
493
- { snapshotOptions : { timeout : 2000 } , enableSingleRequestForShareLinkWithCreate : true } ,
494
- ) ;
495
-
496
- const expectedResponse = {
497
- context : "http://sp.devinstall/_api/v2.1/$metadata#" ,
498
- sequenceNumber : 1 ,
499
- sha : "shaxxshaxx" ,
500
- itemUrl : `http://fake.microsoft.com/_api/v2.1/drives/${ driveId } /items/${ itemId } ` ,
501
- driveId,
502
- itemId,
503
- id : "Summary Handle" ,
504
- sharing : mockSharingData ,
505
- dataStorePath : "/path" ,
506
- } ;
507
-
508
- const fileName = "fileName" ;
509
- const request = createOdspCreateContainerRequest ( siteUrl , driveId , filePath , fileName ) ;
510
- const logger = new MockLogger ( ) ;
511
-
512
- const sharingLinkFetcherProps : ShareLinkFetcherProps = {
513
- tokenFetcher : async ( ) => "token" ,
514
- identityType : "Enterprise" ,
515
- } ;
516
-
517
- const getContext = async (
518
- url : IOdspResolvedUrl ,
519
- dataStorePath : string ,
520
- ) : Promise < string > => {
521
- if ( dataStorePath === "" ) {
522
- return "context" ;
523
- }
524
- return url . dataStorePath ?? "context" ;
474
+ it ( "Should set the appropriate nav param info when a resolved url is sent" , async ( ) => {
475
+ const mockOdspResolvedUrl : IOdspResolvedUrl = {
476
+ ...resolvedUrl ,
477
+ odspResolvedUrl : true ,
478
+ summarizer : true ,
479
+ dataStorePath : "/dataStorePath" ,
480
+ codeHint : {
481
+ containerPackageName : "mockContainerPackageName" ,
482
+ } ,
483
+ fileVersion : "mockFileVersion" ,
484
+ context : "mockContext" ,
485
+ appName : "mockAppName" ,
525
486
} ;
526
- const shareLinkResolver = new OdspDriverUrlResolverForShareLink (
527
- sharingLinkFetcherProps ,
528
- logger ,
529
- "appName" ,
530
- getContext ,
531
- { name : "containerPackageName" } ,
532
- ) ;
533
-
534
- const resolved = await shareLinkResolver . resolve ( request ) ;
535
- const summary = createSummary ( ) ;
536
- const docService = await mockFetchOk (
537
- async ( ) => odspDocumentServiceFactory . createContainer ( summary , resolved , logger ) ,
538
- expectedResponse ,
539
- { "x-fluid-epoch" : "epoch1" } ,
487
+ const odspResolvedUrl = await useCreateNewModule ( createChildLogger ( ) , async ( module ) =>
488
+ mockFetchOk (
489
+ async ( ) =>
490
+ module . createNewFluidFile (
491
+ async ( _options ) => "token" ,
492
+ newFileParams ,
493
+ createChildLogger ( ) ,
494
+ createSummary ( ) ,
495
+ epochTracker ,
496
+ fileEntry ,
497
+ false /* createNewCaching */ ,
498
+ false /* forceAccessTokenViaAuthorizationHeader */ ,
499
+ undefined /* isClpCompliantApp */ ,
500
+ true /* enableSingleRequestForShareLinkWithCreate */ ,
501
+ mockOdspResolvedUrl ,
502
+ ) ,
503
+ {
504
+ itemId : "mockItemId" ,
505
+ id : "mockId" ,
506
+ sharing : mockSharingData ,
507
+ sharingLinkErrorReason : undefined ,
508
+ } ,
509
+ { "x-fluid-epoch" : "epoch1" } ,
510
+ ) ,
540
511
) ;
541
512
542
- const finalResolverUrl = getOdspResolvedUrl ( docService . resolvedUrl ) ;
513
+ // 's=%2FsiteUrl&d=driveId&f=mockItemId&c=%2F&fluid=1&a=mockAppName&p=mockContainerPackageName&x=mockContext'
514
+ // Update the webUrl to the version that has the nav parameter that was supposed to be added
515
+ mockSharingLinkData . webUrl =
516
+ "https://mock.url/?nav=cz0lMkZzaXRlVXJsJmQ9ZHJpdmVJZCZmPW1vY2tJdGVtSWQmYz0lMkYmZmx1aWQ9MSZhPW1vY2tBcHBOYW1lJnA9bW9ja0NvbnRhaW5lclBhY2thZ2VOYW1lJng9bW9ja0NvbnRleHQ%3D" ;
543
517
518
+ assert . deepStrictEqual ( odspResolvedUrl . shareLinkInfo ?. createLink , {
519
+ shareId : mockSharingData . shareId ,
520
+ link : {
521
+ role : mockSharingData . sharingLink . type ,
522
+ ...mockSharingData . sharingLink ,
523
+ } ,
524
+ error : undefined ,
525
+ } ) ;
544
526
// Extract the Base64 encoded value of `nav`
545
- const base64Value = finalResolverUrl . shareLinkInfo ?. createLink ?. link ?. webUrl . match (
546
- / n a v = ( [ ^ & ] * ) / ,
547
- ) ?. [ 1 ] as string ;
548
- // Decode the Base64 value to UTF-8, \r�� is being stored at the end of the string so we slice it off
549
- const decodedValue = fromBase64ToUtf8 ( base64Value ) . slice ( 0 , - 3 ) ;
527
+ const base64Value = mockSharingLinkData . webUrl . match ( / n a v = ( [ ^ & ] * ) / ) ?. [ 1 ] as string ;
528
+ // Decode the Base64 value to UTF-8, need to slice off last unnecessary character
529
+ const decodedValue = fromBase64ToUtf8 ( base64Value ) . slice ( 0 , - 1 ) ;
550
530
551
531
// Compare the values to make sure that the nav parameter was added correctly
552
532
assert . equal (
553
533
decodedValue ,
554
- "s=%2FsiteUrl&d=driveId&f=itemId &c=%2F&fluid=1&a=appName &p=containerPackageName &x=context " ,
534
+ "s=%2FsiteUrl&d=driveId&f=mockItemId &c=%2F&fluid=1&a=mockAppName &p=mockContainerPackageName &x=mockContext " ,
555
535
) ;
536
+ // Reset the webUrl to the original value
537
+ mockSharingLinkData . webUrl = "https://mock.url" ;
556
538
} ) ;
557
539
} ) ;
0 commit comments