From 12da88817e1145ccce8acf3015321f88f31639a1 Mon Sep 17 00:00:00 2001 From: maartenvandenbrande Date: Thu, 8 Feb 2024 16:09:42 +0100 Subject: [PATCH] fix merging issues --- lib/pod/IPod.ts | 4 +-- lib/pod/PodCss.ts | 4 +-- .../ServiceRegistryHardcodedTestOnly-test.ts | 26 ++++++++++++++++--- lib/service/ServiceAggregation.ts | 8 +++--- lib/service/ServiceEmpty.ts | 13 +++++----- package-lock.json | 1 + 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/lib/pod/IPod.ts b/lib/pod/IPod.ts index b7d2254..6a600dd 100644 --- a/lib/pod/IPod.ts +++ b/lib/pod/IPod.ts @@ -1,7 +1,7 @@ -import type { ServiceDescription } from '../service/IService'; +import type { IServiceDescription } from '../service/IService'; export interface IPod { - newServiceLocation: (description: ServiceDescription) => Promise; + newServiceLocation: (description: IServiceDescription) => Promise; } export type PodServiceLocation = string; diff --git a/lib/pod/PodCss.ts b/lib/pod/PodCss.ts index 7f8037b..85ce4d2 100644 --- a/lib/pod/PodCss.ts +++ b/lib/pod/PodCss.ts @@ -3,7 +3,7 @@ import * as fs from 'fs-extra'; import { AppRunner } from '@solid/community-server'; import { v4 } from 'uuid'; import { AsyncConstructor } from '../core/AsyncConstructor'; -import type { ServiceDescription } from '../service/IService'; +import type { IServiceDescription } from '../service/IService'; import type { IPod, PodServiceLocation } from './IPod'; export class PodCss extends AsyncConstructor implements IPod { @@ -39,7 +39,7 @@ export class PodCss extends AsyncConstructor implements IPod { // TODO [2024-03-01]: Edit profile card } - public async newServiceLocation(description: ServiceDescription): Promise { + public async newServiceLocation(description: IServiceDescription): Promise { if (!this.initialized) { await new Promise((resolve): void => { this.subscribeInitialized((): void => { diff --git a/lib/service-registry/test/ServiceRegistryHardcodedTestOnly-test.ts b/lib/service-registry/test/ServiceRegistryHardcodedTestOnly-test.ts index 0007f8a..ca82fd8 100644 --- a/lib/service-registry/test/ServiceRegistryHardcodedTestOnly-test.ts +++ b/lib/service-registry/test/ServiceRegistryHardcodedTestOnly-test.ts @@ -9,8 +9,28 @@ describe('ServiceRegistryHardcodedTestOnly', (): void => { beforeEach((): void => { mockAggregatorServices = [ - ({ initialize: jest.fn(), test: jest.fn(), description: 'Service1' } as any) as IService, - ({ initialize: jest.fn(), test: jest.fn(), description: 'Service2' } as any) as IService, + ({ + subscribeInitialized: jest.fn( + (resolve): void => { + resolve(); + }, + ), + test: jest.fn(), + description: { + toString: (): string => 'Service1', + }, + } as any) as IService, + ({ + subscribeInitialized: jest.fn( + (resolve): void => { + resolve(); + }, + ), + test: jest.fn(), + description: { + toString: (): string => 'Service2', + }, + } as any) as IService, ]; mockCostQueueFactory = { @@ -24,7 +44,7 @@ describe('ServiceRegistryHardcodedTestOnly', (): void => { it('should initialize all services.', async(): Promise => { await serviceRegistry.initializeServices(); for (const service of mockAggregatorServices) { - expect(service.initialize).toHaveBeenCalledWith(); + expect(service.subscribeInitialized).toHaveBeenCalledWith(expect.any(Function)); } }); }); diff --git a/lib/service/ServiceAggregation.ts b/lib/service/ServiceAggregation.ts index ae48ad6..5431cae 100644 --- a/lib/service/ServiceAggregation.ts +++ b/lib/service/ServiceAggregation.ts @@ -3,7 +3,7 @@ import { v4 } from 'uuid'; import type { IFetch } from '../fetch/IFetch'; import type { IPod } from '../pod/IPod'; import { AsyncConstructor } from '../core/AsyncConstructor'; -import type { IService, Operation, OperationResult, OperationTestResult, ServiceDescription } from './IService'; +import type { IOperation, IOperationResult, IOperationTestResult, IService, IServiceDescription } from './IService'; export class ServiceAggregation extends AsyncConstructor implements IService { public fetch: IFetch; @@ -20,7 +20,7 @@ export class ServiceAggregation extends AsyncConstructor implements IService { this.podLocation = await args.pod.newServiceLocation(this.description); } - public async test(operation: Operation): Promise { + public async test(operation: IOperation): Promise { if (operation.operation !== 'Aggregation') { throw new Error('Not an aggregation operation'); } @@ -31,7 +31,7 @@ export class ServiceAggregation extends AsyncConstructor implements IService { }; } - public async run(operation: Operation): Promise { + public async run(operation: IOperation): Promise { const resultLocation = `${this.podLocation}/${v4()}.ttl`; const streamWriter = new StreamWriter(); @@ -57,7 +57,7 @@ export class ServiceAggregation extends AsyncConstructor implements IService { }; } - public get description(): ServiceDescription { + public get description(): IServiceDescription { return { toString: (): string => 'Aggregation', }; diff --git a/lib/service/ServiceEmpty.ts b/lib/service/ServiceEmpty.ts index 82e2baf..a068b8d 100644 --- a/lib/service/ServiceEmpty.ts +++ b/lib/service/ServiceEmpty.ts @@ -1,25 +1,24 @@ import { AsyncConstructor } from '../core/AsyncConstructor'; import type { IPod } from '../pod/IPod'; import type { IFetch } from '../fetch/IFetch'; -import type { IService, Operation, OperationResult, OperationTestResult, ServiceDescription } from './IService'; -import type { ServiceAggregationArgs } from './ServiceAggregation'; +import type { IOperation, IOperationResult, IOperationTestResult, IService, IServiceDescription } from './IService'; export class ServiceEmpty extends AsyncConstructor implements IService { private podLocation: string | undefined; public fetch: IFetch; public pod: IPod; - public constructor(args: ServiceAggregationArgs) { + public constructor(args: ServiceEmptyArgs) { super(args); this.fetch = args.fetch; this.pod = args.pod; } - protected async initialize(args: ServiceAggregationArgs): Promise { + protected async initialize(args: ServiceEmptyArgs): Promise { this.podLocation = await args.pod.newServiceLocation(this.description); } - public async test(operation: Operation): Promise { + public async test(operation: IOperation): Promise { if (operation.operation !== 'Empty') { throw new Error('Not a Empty operation'); } @@ -30,7 +29,7 @@ export class ServiceEmpty extends AsyncConstructor implements IService { }; } - public async run(operation: Operation): Promise { + public async run(operation: IOperation): Promise { return { aggregatorService: this, operation, @@ -38,7 +37,7 @@ export class ServiceEmpty extends AsyncConstructor implements IService { }; } - public get description(): ServiceDescription { + public get description(): IServiceDescription { return { toString: (): string => 'Empty', }; diff --git a/package-lock.json b/package-lock.json index 9a7b31d..46b2733 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@solid/community-server": "^7.0.3", "componentsjs": "^5.4.2", + "fs-extra": "^11.2.0", "n3": "^1.17.2", "readable-stream": "^4.5.2", "tinyqueue": "^2.0.3",