From 9f1f4beae4f41a341c0578c7ec0b047e5e478a1a Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 23 Nov 2025 11:29:42 +0000 Subject: [PATCH] Renamce --- .../src/services/fetch-controller.test.ts | 28 +++++++++---------- .../sync-client/src/services/sync-service.ts | 8 +++--- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/frontend/sync-client/src/services/fetch-controller.test.ts b/frontend/sync-client/src/services/fetch-controller.test.ts index e5562dcd..b349ced2 100644 --- a/frontend/sync-client/src/services/fetch-controller.test.ts +++ b/frontend/sync-client/src/services/fetch-controller.test.ts @@ -9,7 +9,7 @@ describe("FetchController", () => { const createMockFetch = (shouldSleep: boolean) => mock.fn(async () => { if (shouldSleep) { - await sleep(50); + await sleep(30); } return Promise.resolve(new Response("OK", { status: 200 })); }); @@ -25,13 +25,12 @@ describe("FetchController", () => { it("should allow fetch when canFetch is true", async () => { const logger = new Logger(); const controller = new FetchController(true, logger); - const mockFetch = createMockFetch(true); + const mockFetch = createMockFetch(false); const controlledFetch = controller.getControlledFetchImplementation( logger, mockFetch ); - mock.timers.tick(50); const response = await controlledFetch("http://example.com"); assert.strictEqual(await response.text(), "OK"); @@ -48,12 +47,12 @@ describe("FetchController", () => { ); const fetchPromise = controlledFetch("http://example.com"); - mock.timers.tick(10); assert.strictEqual(mockFetch.mock.calls.length, 0); controller.canFetch = true; + await Promise.resolve(); + mock.timers.tick(30); - mock.timers.tick(50); const response = await fetchPromise; assert.strictEqual(await response.text(), "OK"); assert.strictEqual(mockFetch.mock.calls.length, 1); @@ -69,11 +68,11 @@ describe("FetchController", () => { ); const firstRequest = controlledFetch("http://example.com"); - assert.strictEqual(mockFetch.mock.calls.length, 1); // because firstRequest started before reset - controller.startReset(); - const secondRequest = controlledFetch("http://example.com"); + assert.strictEqual(mockFetch.mock.calls.length, 1); - mock.timers.tick(50); + controller.startReset(); + + const secondRequest = controlledFetch("http://example.com"); await assert.rejects( firstRequest, @@ -83,13 +82,13 @@ describe("FetchController", () => { secondRequest, (error: unknown) => error instanceof SyncResetError ); - assert.strictEqual(mockFetch.mock.calls.length, 1); // because firstRequest started before reset + assert.strictEqual(mockFetch.mock.calls.length, 1); }); it("should allow fetch after reset finishes", async () => { const logger = new Logger(); const controller = new FetchController(true, logger); - const mockFetch = createMockFetch(true); + const mockFetch = createMockFetch(false); const controlledFetch = controller.getControlledFetchImplementation( logger, mockFetch @@ -98,7 +97,6 @@ describe("FetchController", () => { controller.startReset(); controller.finishReset(); - mock.timers.tick(50); const response = await controlledFetch("http://example.com"); assert.strictEqual(await response.text(), "OK"); }); @@ -134,8 +132,10 @@ describe("FetchController", () => { controller.finishReset(); - mock.timers.tick(50); - const response = await controlledFetch("http://example.com"); + const fetchPromise = controlledFetch("http://example.com"); + mock.timers.tick(30); + + const response = await fetchPromise; assert.strictEqual(await response.text(), "OK"); }); diff --git a/frontend/sync-client/src/services/sync-service.ts b/frontend/sync-client/src/services/sync-service.ts index ce5e8cb3..91d6f8df 100644 --- a/frontend/sync-client/src/services/sync-service.ts +++ b/frontend/sync-client/src/services/sync-service.ts @@ -25,7 +25,7 @@ export class SyncService { public constructor( private readonly deviceId: string, - private readonly connectionStatus: FetchController, + private readonly fetchController: FetchController, private readonly settings: Settings, private readonly logger: Logger, fetchImplementation: typeof globalThis.fetch = globalThis.fetch @@ -34,7 +34,7 @@ export class SyncService { const unboundFetch: typeof globalThis.fetch = async (...args) => fetchImplementation(...args); - this.client = this.connectionStatus.getControlledFetchImplementation( + this.client = this.fetchController.getControlledFetchImplementation( this.logger, unboundFetch ); @@ -341,8 +341,8 @@ export class SyncService { private getUrl(path: string): string { const { vaultName, remoteUri } = this.settings.getSettings(); - const safeRemoteUri = remoteUri.replace(/\/+$/g, ""); - return `${safeRemoteUri}/vaults/${vaultName}${path}`; + const remoteUriWithoutTrailingSlash = remoteUri.replace(/\/+$/, ""); + return `${remoteUriWithoutTrailingSlash}/vaults/${vaultName}${path}`; } private getDefaultHeaders(