import assert from "assert" ; import { IFluidHandle } from "@fluidframework/core-interfaces" ; import { SharedMap } from "@fluidframework/map" ; import { requestFluidObject } from "@fluidframework/runtime-utils" ; import { TestFluidObject , ITestObjectProvider , } from "@fluidframework/test-utils" ; import { describeFullCompat , ITestDataObject , TestDataObjectType , } from "@fluidframework/test-version-utils" ; describeFullCompat ( "FluidObjectHandle" , ( getTestObjectProvider ) => { let provider ; beforeEach ( ( ) => { provider = getTestObjectProvider ( ) ; } ) ; let firstContainerObject1 ; let firstContainerObject2 ; let secondContainerObject1 ; beforeEach ( async ( ) => { const firstContainer = await provider . makeTestContainer ( ) ; firstContainerObject1 = await requestFluidObject < ITestDataObject > ( firstContainer , "default" ) ; const containerRuntime1 = firstContainerObject1 . _context . containerRuntime ; const dataStore = await containerRuntime1 . createDataStore ( TestDataObjectType ) ; firstContainerObject2 = await requestFluidObject < ITestDataObject > ( dataStore , "" ) ; const secondContainer = await provider . loadTestContainer ( ) ; secondContainerObject1 = await requestFluidObject < ITestDataObject > ( secondContainer , "default" ) ; await provider . ensureSynchronized ( ) ; } ) ; it ( "should generate the absolute path for ContainerRuntime correctly" , ( ) => { const absolutePath = "" ; const containerRuntime1 = firstContainerObject1 . _context . containerRuntime . IFluidHandleContext ; assert . equal ( containerRuntime1 . absolutePath , absolutePath , "The ContainerRuntime's path is incorrect" ) ; const containerRuntime2 = secondContainerObject1 . _context . containerRuntime . IFluidHandleContext ; assert . equal ( containerRuntime2 . absolutePath , absolutePath , "The remote ContainerRuntime's path is incorrect" ) ; } ) ; it ( "should generate the absolute path for FluidDataObjectRuntime correctly" , function ( ) { const absolutePath = `/${ firstContainerObject1 . _runtime . id }` ; const fluidHandleContext11 = firstContainerObject1 . _runtime . rootRoutingContext ; assert . equal ( fluidHandleContext11 . absolutePath , absolutePath , "The FluidDataObjectRuntime's path is incorrect" ) ; const fluidHandleContext12 = secondContainerObject1 . _runtime . rootRoutingContext ; assert . equal ( fluidHandleContext12 . absolutePath , absolutePath , "The remote FluidDataObjectRuntime's path is incorrect" ) ; } ) ; it ( "can store and retrieve a DDS from handle within same data store runtime" , async ( ) => { const sharedMap = SharedMap . create ( firstContainerObject1 . _runtime ) ; sharedMap . set ( "key1" , "value1" ) ; const sharedMapHandle = sharedMap . handle ; const absolutePath = `/default/${ sharedMap . id }` ; assert . equal ( sharedMapHandle . absolutePath , absolutePath , "The handle's path is incorrect" ) ; firstContainerObject1 . _root . set ( "sharedMap" , sharedMapHandle ) ; await provider . ensureSynchronized ( ) ; const remoteSharedMapHandle = secondContainerObject1 . _root . get < IFluidHandle < SharedMap > > ( "sharedMap" ) ; assert ( remoteSharedMapHandle ) ; assert . equal ( remoteSharedMapHandle . absolutePath , absolutePath , "The remote handle's path is incorrect" ) ; const remoteSharedMap = await remoteSharedMapHandle . get ( ) ; assert . equal ( remoteSharedMap . get ( "key1" ) , "value1" , "The map does not have the value that was set" ) ; } ) ; it ( "can store and retrieve a DDS from handle in different data store runtime" , async ( ) => { const sharedMap = SharedMap . create ( firstContainerObject2 . _runtime ) ; sharedMap . set ( "key1" , "value1" ) ; const sharedMapHandle = sharedMap . handle ; const absolutePath = `/${ firstContainerObject2 . _runtime . id }/${ sharedMap . id }` ; assert . equal ( sharedMapHandle . absolutePath , absolutePath , "The handle's path is incorrect" ) ; firstContainerObject1 . _root . set ( "sharedMap" , sharedMap . handle ) ; await provider . ensureSynchronized ( ) ; const remoteSharedMapHandle = secondContainerObject1 . _root . get < IFluidHandle < SharedMap > > ( "sharedMap" ) ; assert ( remoteSharedMapHandle ) ; assert . equal ( remoteSharedMapHandle . absolutePath , absolutePath , "The remote handle's path is incorrect" ) ; const remoteSharedMap = await remoteSharedMapHandle . get ( ) ; assert . equal ( remoteSharedMap . get ( "key1" ) , "value1" , "The map does not have the value that was set" ) ; } ) ; it ( "can store and retrieve a PureDataObject from handle in different data store runtime" , async ( ) => { const absolutePath = `/${ firstContainerObject2 . _runtime . id }` ; const dataObjectHandle = firstContainerObject2 . handle ; assert . equal ( dataObjectHandle . absolutePath , absolutePath , "The handle's absolutepath is not correct" ) ; firstContainerObject1 . _root . set ( "dataObject2" , firstContainerObject2 . handle ) ; await provider . ensureSynchronized ( ) ; const remoteDataObjectHandle = secondContainerObject1 . _root . get < IFluidHandle < TestFluidObject > > ( "dataObject2" ) ; assert ( remoteDataObjectHandle ) ; assert . equal ( remoteDataObjectHandle . absolutePath , absolutePath , "The remote handle's path is incorrect" ) ; const container2DataObject2 = await remoteDataObjectHandle . get ( ) ; assert . equal ( container2DataObject2 . handle . absolutePath , firstContainerObject2 . handle . absolutePath , "The urls do not match" ) ; } ) ; } ) ;