Skip to content

Commit

Permalink
fix: tests after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerni10 committed Oct 3, 2024
1 parent e177a46 commit 11c719f
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 262 deletions.
3 changes: 1 addition & 2 deletions backend/src/north/north-sftp/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const manifest: NorthConnectorManifest = {
description: 'Write files and values into a SFTP server',
modes: {
files: true,
points: true,
items: false
points: true
},
settings: [
{
Expand Down
93 changes: 16 additions & 77 deletions backend/src/web-server/controllers/history-query.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,66 +428,6 @@ describe('History query controller', () => {
ctx.query.duplicateId = null;
});

it('createHistoryQuery() should create History query with existing connectors', async () => {
ctx.request.body = { ...JSON.parse(JSON.stringify(historyQueryCreateCommand)), fromNorthId: 'id1', fromSouthId: 'id2' };
ctx.request.body.items = [
{
name: 'name',
enabled: true,
connectorId: 'connectorId',
settings: {}
}
];
ctx.app.repositoryService.southConnectorRepository.getSouthConnector.mockReturnValue(southConnector);
ctx.app.repositoryService.southItemRepository.getSouthItems.mockReturnValue([]);
ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue(northConnector);

ctx.app.encryptionService.encryptConnectorSecrets
.mockReturnValueOnce(southConnector.settings)
.mockReturnValueOnce(northConnector.settings);
ctx.app.reloadService.onCreateHistoryQuery.mockReturnValue(historyQuery);

await historyQueryController.createHistoryQuery(ctx);

const southManifest = southTestManifest;
const northManifest = northTestManifest;
expect(ctx.app.repositoryService.scanModeRepository.getScanModes).not.toHaveBeenCalled();
expect(validator.validateSettings).toHaveBeenCalledWith(southManifest.settings, historyQuery.southSettings);
expect(validator.validateSettings).toHaveBeenCalledWith(northManifest.settings, historyQuery.northSettings);
expect(ctx.app.encryptionService.encryptConnectorSecrets).toHaveBeenCalledWith(
historyQuery.southSettings,
southConnector.settings,
southManifest.settings
);
expect(ctx.app.encryptionService.encryptConnectorSecrets).toHaveBeenCalledWith(
historyQuery.northSettings,
northConnector.settings,
northManifest.settings
);
expect(ctx.app.reloadService.onCreateHistoryQuery).toHaveBeenCalledWith(
{
name: 'name',
description: 'description',
history: {
maxInstantPerItem: true,
maxReadInterval: 3600,
readDelay: 0,
overlap: 0
},
startTime: '2020-02-01T02:02:59.999Z',
endTime: '2020-02-02T02:02:59.999Z',
southType: 'south-test',
northType: 'north-test',
southSettings: southConnector.settings,
southSharedConnection: false,
northSettings: northConnector.settings,
caching: northCacheSettings
},
ctx.request.body.items
);
expect(ctx.created).toHaveBeenCalledWith(historyQuery);
});

it('createHistoryQuery() should not create History query without body', async () => {
ctx.request.body = null;
await historyQueryController.createHistoryQuery(ctx);
Expand Down Expand Up @@ -516,6 +456,21 @@ describe('History query controller', () => {
expect(ctx.notFound).toHaveBeenCalled();
});

it('startHistoryQuery() should restart when the history is in finished or errored state', async () => {
ctx.params.enable = true;
ctx.params.id = 'id';

ctx.app.repositoryService.historyQueryRepository.getHistoryQuery.mockReturnValueOnce({ ...historyQuery, status: 'FINISHED' });
await historyQueryController.startHistoryQuery(ctx);

ctx.app.repositoryService.historyQueryRepository.getHistoryQuery.mockReturnValueOnce({ ...historyQuery, status: 'ERRORED' });
await historyQueryController.startHistoryQuery(ctx);

expect(ctx.app.reloadService.historyEngine.stopHistoryQuery).toHaveBeenCalledTimes(2);
expect(ctx.app.reloadService.historyEngine.resetCache).toHaveBeenCalledTimes(2);
expect(ctx.badRequest).not.toHaveBeenCalled();
});

it('createHistoryQuery() should return 404 when South connector not found', async () => {
ctx.request.body = { ...JSON.parse(JSON.stringify(historyQueryCreateCommand)), fromSouthId: 'id1' };

Expand Down Expand Up @@ -595,7 +550,7 @@ describe('History query controller', () => {

it('startHistoryQuery() should return not found if history not found', async () => {
ctx.params.id = 'id';
ctx.app.repositoryService.historyQueryRepository.getHistoryQuery.mockReturnValue(null);
ctx.app.repositoryService.historyQueryRepository.getHistoryQuery.mockReturnValueOnce(null);

await historyQueryController.startHistoryQuery(ctx);

Expand All @@ -604,21 +559,6 @@ describe('History query controller', () => {
expect(ctx.notFound).toHaveBeenCalled();
});

it('startHistoryQuery() should restart when the history is in finished or errored state', async () => {
ctx.params.enable = true;
ctx.params.id = 'id';

ctx.app.repositoryService.historyQueryRepository.getHistoryQuery.mockReturnValue({ ...historyQuery, status: 'FINISHED' });
await historyQueryController.startHistoryQuery(ctx);

ctx.app.repositoryService.historyQueryRepository.getHistoryQuery.mockReturnValue({ ...historyQuery, status: 'ERRORED' });
await historyQueryController.startHistoryQuery(ctx);

expect(ctx.app.reloadService.historyEngine.stopHistoryQuery).toHaveBeenCalledTimes(2);
expect(ctx.app.reloadService.historyEngine.resetCache).toHaveBeenCalledTimes(2);
expect(ctx.badRequest).not.toHaveBeenCalled();
});

it('pauseHistoryQuery() should pause History query', async () => {
ctx.params.enable = true;
ctx.params.id = 'id';
Expand Down Expand Up @@ -688,7 +628,6 @@ describe('History query controller', () => {
);
expect(ctx.app.reloadService.onDeleteHistoryItem).toHaveBeenCalledWith('id', 'id1');

expect(ctx.app.reloadService.onUpdateHistoryQuerySettings).toHaveBeenCalledWith('id', historyQueryCommand);
expect(ctx.noContent).toHaveBeenCalled();
});

Expand Down
Loading

0 comments on commit 11c719f

Please sign in to comment.