Skip to content

Commit

Permalink
fix: fix north items and add tests coverage after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerni10 committed Jan 3, 2025
1 parent c11002b commit 039bb25
Show file tree
Hide file tree
Showing 26 changed files with 2,003 additions and 110 deletions.
11 changes: 10 additions & 1 deletion backend/src/engine/data-stream-engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ describe('DataStreamEngine', () => {
expect(mockedNorth1.retryAllErrorValues).toHaveBeenCalledWith();
});

it('should manage item change', async () => {
it('should manage south item change', async () => {
await engine.start([], [mockedSouth1]);

await engine.reloadSouthItems('bad id');
Expand All @@ -361,6 +361,15 @@ describe('DataStreamEngine', () => {
expect(mockedSouth1.onItemChange).toHaveBeenCalled();
});

it('should manage north item change', async () => {
await engine.start([mockedNorth1], []);

await engine.reloadNorthItems('bad id');
expect(mockedNorth1.onItemChange).not.toHaveBeenCalled();
await engine.reloadNorthItems(testData.north.list[0].id);
expect(mockedNorth1.onItemChange).toHaveBeenCalled();
});

it('should update north subscriptions', async () => {
await engine.start([mockedNorth1, mockedNorth2], [mockedSouth1]);

Expand Down
4 changes: 4 additions & 0 deletions backend/src/engine/data-stream-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ export default class DataStreamEngine {
await this.southConnectors.get(southId)?.onItemChange();
}

async reloadNorthItems(northId: string): Promise<void> {
await this.northConnectors.get(northId)?.onItemChange();
}

async reloadSouth(southConnector: SouthConnectorEntity<SouthSettings, SouthItemSettings>) {
await this.stopSouth(southConnector.id);
const south = this.southConnectors.get(southConnector.id);
Expand Down
2 changes: 2 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const LOG_DB_NAME = 'logs.db';
repositoryService.southConnectorRepository,
repositoryService.northMetricsRepository,
repositoryService.scanModeRepository,
repositoryService.transformerRepository,
repositoryService.logRepository,
repositoryService.certificateRepository,
repositoryService.oianalyticsRegistrationRepository,
Expand All @@ -142,6 +143,7 @@ const LOG_DB_NAME = 'logs.db';
repositoryService.southMetricsRepository,
repositoryService.southCacheRepository,
repositoryService.scanModeRepository,
repositoryService.transformerRepository,
repositoryService.oianalyticsRegistrationRepository,
repositoryService.certificateRepository,
oIAnalyticsMessageService,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/model/oianalytics-command.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ScanModeCommandDTO } from '../../shared/model/scan-mode.model';
import { SouthConnectorCommandDTO } from '../../shared/model/south-connector.model';
import { SouthItemSettings, SouthSettings } from '../../shared/model/south-settings.model';
import { NorthConnectorCommandDTO } from '../../shared/model/north-connector.model';
import { NorthSettings } from '../../shared/model/north-settings.model';
import { NorthItemSettings, NorthSettings } from '../../shared/model/north-settings.model';

export interface BaseOIBusCommand extends BaseEntity {
type: OIBusCommandType;
Expand Down Expand Up @@ -85,13 +85,13 @@ export interface OIBusDeleteSouthConnectorCommand extends BaseOIBusCommand {
export interface OIBusCreateNorthConnectorCommand extends BaseOIBusCommand {
type: 'create-north';
northConnectorId: string | null; // used to retrieve passwords in case of duplicate
commandContent: NorthConnectorCommandDTO<NorthSettings>;
commandContent: NorthConnectorCommandDTO<NorthSettings, NorthItemSettings>;
}

export interface OIBusUpdateNorthConnectorCommand extends BaseOIBusCommand {
type: 'update-north';
northConnectorId: string;
commandContent: NorthConnectorCommandDTO<NorthSettings>;
commandContent: NorthConnectorCommandDTO<NorthSettings, NorthItemSettings>;
}

export interface OIBusDeleteNorthConnectorCommand extends BaseOIBusCommand {
Expand Down
5 changes: 5 additions & 0 deletions backend/src/north/north-connector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,4 +691,9 @@ describe('NorthConnector test', () => {
it('should check if North caches are empty', async () => {
expect(await north.isCacheEmpty()).toBeFalsy();
});

it('should manage item changes', async () => {
await north.onItemChange();
expect(northConnectorRepository.findAllItemsForNorth).toHaveBeenCalled();
});
});
7 changes: 7 additions & 0 deletions backend/src/north/north-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,13 @@ export default abstract class NorthConnector<T extends NorthSettings, I extends
await this.valueCacheService.retryAllErrorValues();
}

/**
* Reset on item changes
*/
async onItemChange(): Promise<void> {
this.connector.items = this.northConnectorRepository.findAllItemsForNorth(this.connector.id);
}

async updateScanMode(scanMode: ScanMode): Promise<void> {
if (this.cronByScanModeIds.get(scanMode.id)) {
this.createCronJob(scanMode);
Expand Down
Loading

0 comments on commit 039bb25

Please sign in to comment.