diff --git a/backend/src/north/north-sftp/manifest.ts b/backend/src/north/north-sftp/manifest.ts index 317f43f89..3e4ac0ed7 100644 --- a/backend/src/north/north-sftp/manifest.ts +++ b/backend/src/north/north-sftp/manifest.ts @@ -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: [ { diff --git a/backend/src/web-server/controllers/history-query.controller.spec.ts b/backend/src/web-server/controllers/history-query.controller.spec.ts index 8dc4981f8..bc8c176a9 100644 --- a/backend/src/web-server/controllers/history-query.controller.spec.ts +++ b/backend/src/web-server/controllers/history-query.controller.spec.ts @@ -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); @@ -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' }; @@ -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); @@ -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'; @@ -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(); }); diff --git a/backend/src/web-server/controllers/south-connector.controller.spec.ts b/backend/src/web-server/controllers/south-connector.controller.spec.ts index 56dde9568..3a3571750 100644 --- a/backend/src/web-server/controllers/south-connector.controller.spec.ts +++ b/backend/src/web-server/controllers/south-connector.controller.spec.ts @@ -1037,43 +1037,46 @@ describe('South connector controller', () => { } }; - ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([{ - id: 'south-test', - category: 'debug', - name: 'Test', - description: '', - modes: { - subscription: true, - lastPoint: true, - lastFile: true, - history: true, - forceMaxInstantPerItem: true - }, - settings: [{ type: 'OibTimezone' }], - items: { - scanMode: { - acceptSubscription: true, - subscriptionOnly: true + ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([ + { + id: 'south-test', + category: 'debug', + name: 'Test', + description: '', + modes: { + subscription: true, + lastPoint: true, + lastFile: true, + history: true, + forceMaxInstantPerItem: true }, - settings: [{ type: 'OibTimezone' }] - } - }]); + settings: [{ type: 'OibTimezone' }], + items: { + scanMode: { + acceptSubscription: true, + subscriptionOnly: true + }, + settings: [{ type: 'OibTimezone' }] + } + } + ]); - (validator.validateSettings as jest.Mock) - .mockReturnValue(() => { - return true; - }); + (validator.validateSettings as jest.Mock).mockReturnValue(() => { + return true; + }); ctx.app.repositoryService.southConnectorRepository.getSouthConnector = jest.fn().mockReturnValue(southConnector); - ctx.app.repositoryService.scanModeRepository.getScanModes = jest.fn().mockReturnValue([{ - id: '1', - name: 'scan mode', - description: 'description', - cron: '* * * * *' - }]); + ctx.app.repositoryService.scanModeRepository.getScanModes = jest.fn().mockReturnValue([ + { + id: '1', + name: 'scan mode', + description: 'description', + cron: '* * * * *' + } + ]); - ctx.app.encryptionService.encryptConnectorSecrets = jest.fn().mockReturnValue({databasePath: 'folder/file'}); + ctx.app.encryptionService.encryptConnectorSecrets = jest.fn().mockReturnValue({ databasePath: 'folder/file' }); const createdSouth = { testItem: jest.fn() @@ -1104,44 +1107,47 @@ describe('South connector controller', () => { } }; - ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([{ - id: 'south-test', - category: 'debug', - name: 'Test', - description: '', - modes: { - subscription: true, - lastPoint: true, - lastFile: true, - history: true, - forceMaxInstantPerItem: true - }, - settings: [{ type: 'OibTimezone' }], - items: { - scanMode: { - acceptSubscription: true, - subscriptionOnly: true + ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValueOnce([ + { + id: 'south-test', + category: 'debug', + name: 'Test', + description: '', + modes: { + subscription: true, + lastPoint: true, + lastFile: true, + history: true, + forceMaxInstantPerItem: true }, - settings: [{ type: 'OibTimezone' }] - } - }]); + settings: [{ type: 'OibTimezone' }], + items: { + scanMode: { + acceptSubscription: true, + subscriptionOnly: true + }, + settings: [{ type: 'OibTimezone' }] + } + } + ]); ctx.params.id = 'create'; ctx.query.duplicateId = null; - (validator.validateSettings as jest.Mock) - .mockReturnValue(() => { - return true; - }); + (validator.validateSettings as jest.Mock).mockReturnValue(() => { + return true; + }); - ctx.app.repositoryService.scanModeRepository.getScanModes = jest.fn().mockReturnValue([{ - id: '1', - name: 'scan mode', - description: 'description', - cron: '* * * * *' - }]); + ctx.app.repositoryService.scanModeRepository.getScanModes = jest.fn().mockReturnValue([ + { + id: '1', + name: 'scan mode', + description: 'description', + cron: '* * * * *' + } + ]); - ctx.app.encryptionService.encryptConnectorSecrets = jest.fn().mockReturnValue({databasePath: 'folder/file'}); + ctx.app.encryptionService.encryptConnectorSecrets = jest.fn().mockReturnValue({ databasePath: 'folder/file' }); const createdSouth = { testItem: jest.fn() @@ -1158,11 +1164,6 @@ describe('South connector controller', () => { expect(ctx.badRequest).not.toHaveBeenCalled(); }); - it('testSouthItem() should throw error of manifest not found', async () => { - await southConnectorController.testSouthItem(ctx); - expect(ctx.notFound).toHaveBeenCalledWith('South manifest not found'); - }); - it('testSouthItem() should throw error of south not found', async () => { ctx.request.body = { south: southConnectorCommand, @@ -1178,27 +1179,29 @@ describe('South connector controller', () => { ctx.params.id = 'id'; - ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([{ - id: 'south-test', - category: 'debug', - name: 'Test', - description: '', - modes: { - subscription: true, - lastPoint: true, - lastFile: true, - history: true, - forceMaxInstantPerItem: true - }, - settings: [{ type: 'OibTimezone' }], - items: { - scanMode: { - acceptSubscription: true, - subscriptionOnly: true + ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([ + { + id: 'south-test', + category: 'debug', + name: 'Test', + description: '', + modes: { + subscription: true, + lastPoint: true, + lastFile: true, + history: true, + forceMaxInstantPerItem: true }, - settings: [{ type: 'OibTimezone' }] - } - }]); + settings: [{ type: 'OibTimezone' }], + items: { + scanMode: { + acceptSubscription: true, + subscriptionOnly: true + }, + settings: [{ type: 'OibTimezone' }] + } + } + ]); ctx.app.repositoryService.southConnectorRepository.getSouthConnector = jest.fn().mockReturnValue(null); @@ -1225,27 +1228,29 @@ describe('South connector controller', () => { ctx.query.duplicateId = 'id'; ctx.params.id = 'create'; - ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([{ - id: 'south-test', - category: 'debug', - name: 'Test', - description: '', - modes: { - subscription: true, - lastPoint: true, - lastFile: true, - history: true, - forceMaxInstantPerItem: true - }, - settings: [{ type: 'OibTimezone' }], - items: { - scanMode: { - acceptSubscription: true, - subscriptionOnly: true + ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([ + { + id: 'south-test', + category: 'debug', + name: 'Test', + description: '', + modes: { + subscription: true, + lastPoint: true, + lastFile: true, + history: true, + forceMaxInstantPerItem: true }, - settings: [{ type: 'OibTimezone' }] - } - }]); + settings: [{ type: 'OibTimezone' }], + items: { + scanMode: { + acceptSubscription: true, + subscriptionOnly: true + }, + settings: [{ type: 'OibTimezone' }] + } + } + ]); ctx.app.repositoryService.southConnectorRepository.getSouthConnector = jest.fn().mockReturnValue(null); @@ -1268,32 +1273,33 @@ describe('South connector controller', () => { } }; - ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([{ - id: 'south-test', - category: 'debug', - name: 'Test', - description: '', - modes: { - subscription: true, - lastPoint: true, - lastFile: true, - history: true, - forceMaxInstantPerItem: true - }, - settings: [{ type: 'OibTimezone' }], - items: { - scanMode: { - acceptSubscription: true, - subscriptionOnly: true + ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([ + { + id: 'south-test', + category: 'debug', + name: 'Test', + description: '', + modes: { + subscription: true, + lastPoint: true, + lastFile: true, + history: true, + forceMaxInstantPerItem: true }, - settings: [{ type: 'OibTimezone' }] - } - }]); + settings: [{ type: 'OibTimezone' }], + items: { + scanMode: { + acceptSubscription: true, + subscriptionOnly: true + }, + settings: [{ type: 'OibTimezone' }] + } + } + ]); - (validator.validateSettings as jest.Mock) - .mockReturnValue(() => { - return true; - }); + (validator.validateSettings as jest.Mock).mockReturnValue(() => { + return true; + }); ctx.app.repositoryService.southConnectorRepository.getSouthConnector = jest.fn().mockReturnValue(southConnector); @@ -1318,41 +1324,44 @@ describe('South connector controller', () => { } }; - ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([{ - id: 'south-test', - category: 'debug', - name: 'Test', - description: '', - modes: { - subscription: true, - lastPoint: true, - lastFile: true, - history: true, - forceMaxInstantPerItem: true - }, - settings: [{ type: 'OibTimezone' }], - items: { - scanMode: { - acceptSubscription: true, - subscriptionOnly: true + ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([ + { + id: 'south-test', + category: 'debug', + name: 'Test', + description: '', + modes: { + subscription: true, + lastPoint: true, + lastFile: true, + history: true, + forceMaxInstantPerItem: true }, - settings: [{ type: 'OibTimezone' }] - } - }]); + settings: [{ type: 'OibTimezone' }], + items: { + scanMode: { + acceptSubscription: true, + subscriptionOnly: true + }, + settings: [{ type: 'OibTimezone' }] + } + } + ]); - (validator.validateSettings as jest.Mock) - .mockReturnValue(() => { - return true; - }); + (validator.validateSettings as jest.Mock).mockReturnValue(() => { + return true; + }); ctx.app.repositoryService.southConnectorRepository.getSouthConnector = jest.fn().mockReturnValue(southConnector); - ctx.app.repositoryService.scanModeRepository.getScanModes = jest.fn().mockReturnValue([{ - id: '1', - name: 'bad scan mode', - description: 'description', - cron: '* * * * *' - }]); + ctx.app.repositoryService.scanModeRepository.getScanModes = jest.fn().mockReturnValue([ + { + id: '1', + name: 'bad scan mode', + description: 'description', + cron: '* * * * *' + } + ]); await southConnectorController.testSouthItem(ctx); @@ -1376,27 +1385,29 @@ describe('South connector controller', () => { } }; - ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([{ - id: 'south-test', - category: 'debug', - name: 'Test', - description: '', - modes: { - subscription: true, - lastPoint: true, - lastFile: true, - history: true, - forceMaxInstantPerItem: true - }, - settings: [{ type: 'OibTimezone' }], - items: { - scanMode: { - acceptSubscription: true, - subscriptionOnly: true + ctx.app.southService.getInstalledSouthManifests = jest.fn().mockReturnValue([ + { + id: 'south-test', + category: 'debug', + name: 'Test', + description: '', + modes: { + subscription: true, + lastPoint: true, + lastFile: true, + history: true, + forceMaxInstantPerItem: true }, - settings: [{ type: 'OibTimezone' }] - } - }]); + settings: [{ type: 'OibTimezone' }], + items: { + scanMode: { + acceptSubscription: true, + subscriptionOnly: true + }, + settings: [{ type: 'OibTimezone' }] + } + } + ]); (validator.validateSettings as jest.Mock).mockRejectedValueOnce('Bad request'); @@ -2170,7 +2181,7 @@ describe('South connector controller', () => { ...southConnectorCommand }; ctx.params.id = 'create'; - ctx.app.repositoryService.southConnectorRepository.getSouthConnector.mockReturnValue(null); + ctx.app.repositoryService.southConnectorRepository.getSouthConnector.mockReturnValue(southConnector); ctx.app.encryptionService.encryptConnectorSecrets.mockReturnValue(southConnectorCommand.settings); await southConnectorController.testSouthConnection(ctx); @@ -2178,7 +2189,7 @@ describe('South connector controller', () => { expect(validator.validateSettings).toHaveBeenCalledTimes(1); expect(ctx.app.encryptionService.encryptConnectorSecrets).toHaveBeenCalledWith( southConnectorCommand.settings, - undefined, + southConnector.settings, southTestManifest.settings ); expect(ctx.notFound).not.toHaveBeenCalled();