Allow overriding WebSocket implementation and add flaky version for testing

This commit is contained in:
Andras Schmelczer 2025-04-07 23:13:45 +01:00
parent 74a8060246
commit 3ec6bd4d5b
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
8 changed files with 162 additions and 73 deletions

View file

@ -21,13 +21,13 @@ export class SyncService {
private static readonly NETWORK_RETRY_INTERVAL_MS = 1000;
private client: Client<paths>;
private pingClient: Client<paths>;
private _fetchImplementation: typeof globalThis.fetch = globalThis.fetch;
public constructor(
private readonly deviceId: string,
private readonly connectionStatus: ConnectionStatus,
private readonly settings: Settings,
private readonly logger: Logger
private readonly logger: Logger,
private readonly fetchImplementation: typeof globalThis.fetch = globalThis.fetch
) {
[this.client, this.pingClient] = this.createClient(
this.settings.getSettings().remoteUri
@ -44,13 +44,6 @@ export class SyncService {
});
}
public set fetchImplementation(fetch: typeof globalThis.fetch) {
this._fetchImplementation = fetch;
[this.client, this.pingClient] = this.createClient(
this.settings.getSettings().remoteUri
);
}
private static formatError(
error: components["schemas"]["SerializedError"]
): string {
@ -329,7 +322,7 @@ export class SyncService {
baseUrl: remoteUri,
fetch: this.connectionStatus.getFetchImplementation(
this.logger,
this._fetchImplementation
this.fetchImplementation
),
headers: {
authorization: `Bearer ${this.settings.getSettings().token}`
@ -337,7 +330,7 @@ export class SyncService {
}),
createClient<paths>({
baseUrl: remoteUri,
fetch: this._fetchImplementation,
fetch: this.fetchImplementation,
headers: {
authorization: `Bearer ${this.settings.getSettings().token}`
}