From d94bd42b344f53e3efa2254c8012566e00835ca2 Mon Sep 17 00:00:00 2001 From: MarioJGMsoft Date: Wed, 20 Nov 2024 16:46:48 -0800 Subject: [PATCH] Testing getDeltas fetchReason addition (#23057) ## Description Create new test to make sure that the added code is functioning as intended and see what is going to be sent from now to AFR ## Reviewer Guidance Let me know if there's a better way to create the test Fixes: [AB#21454](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/21454) --- .../src/test/documentService.spec.ts | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/packages/drivers/routerlicious-driver/src/test/documentService.spec.ts b/packages/drivers/routerlicious-driver/src/test/documentService.spec.ts index 5f9d27d3156..5570d3f91b2 100644 --- a/packages/drivers/routerlicious-driver/src/test/documentService.spec.ts +++ b/packages/drivers/routerlicious-driver/src/test/documentService.spec.ts @@ -7,12 +7,38 @@ import { strict as assert } from "assert"; import { IClient } from "@fluidframework/driver-definitions"; import { IResolvedUrl } from "@fluidframework/driver-definitions/internal"; +import { MockLogger } from "@fluidframework/telemetry-utils/internal"; import { stub } from "sinon"; import { DefaultTokenProvider } from "../defaultTokenProvider.js"; +import { DeltaStorageService } from "../deltaStorageService.js"; import { R11sDocumentDeltaConnection } from "../documentDeltaConnection.js"; import { DocumentService } from "../documentService.js"; import { RouterliciousDocumentServiceFactory } from "../documentServiceFactory.js"; +import type { IR11sResponse } from "../restWrapper.js"; +import { RestWrapper } from "../restWrapperBase.js"; + +class MockRestWrapper extends RestWrapper { + protected async request(): Promise> { + throw new Error("Method not implemented."); + } + public async get(url: string, headers?: Record): Promise { + const headerElements = headers + ? Object.entries(headers) + .map(([key, value]) => `${key}=${value}`) + .join("&") + : ""; + const modifiedUrl = `${url}/${headerElements}`; + /* Usually the response would be the ops from the server but here we are sending + the modified url to check what information is being sent with the link. */ + const response = { + content: modifiedUrl, + propsToLog: {}, + requestUrl: `${modifiedUrl}${"/requestUrl"}`, + }; + return response; + } +} describe("DocumentService", () => { let documentService: DocumentService; @@ -142,4 +168,27 @@ describe("DocumentService", () => { assert.equal(documentService.policies?.summarizeProtocolTree, true); stubbedDeltaConnectionCreate.restore(); }); + + it("DocumentDeltaStorageService sends fetchReason along with fetchMessages", async () => { + // Create fake restWrapperBase + const restWrapperBase = new MockRestWrapper(); + const testLogger = new MockLogger(); + const documentDeltaStorageService = new DeltaStorageService( + "https://mock.url/deltaStorageUrl", + restWrapperBase, + testLogger.toTelemetryLogger(), + ); + const message = await documentDeltaStorageService.get( + "tenantId", + "id", + 1, + 10, + "testReason", + ); + assert.equal( + message.messages, + // Expected to be from 0 because in the get method we are subtracting 1 from the from value + "https://mock.url/deltaStorageUrl/from=0&to=10&fetchReason=testReason", + ); + }); });