diff --git a/addons/addon-base-raas/packages/base-raas-services/lib/data-egress/__test__/data-egress-service.test.js b/addons/addon-base-raas/packages/base-raas-services/lib/data-egress/__test__/data-egress-service.test.js index 10725873c0..aab64d6bae 100644 --- a/addons/addon-base-raas/packages/base-raas-services/lib/data-egress/__test__/data-egress-service.test.js +++ b/addons/addon-base-raas/packages/base-raas-services/lib/data-egress/__test__/data-egress-service.test.js @@ -404,7 +404,7 @@ describe('DataEgressService', () => { }, }; - dbService.table.scan.mockImplementationOnce(() => { + dbService.table.get.mockImplementationOnce(() => { throw new Error(); }); const requestContext = {}; @@ -439,7 +439,7 @@ describe('DataEgressService', () => { }, }; - dbService.table.scan.mockResolvedValue([]); + dbService.table.get.mockResolvedValue(); const requestContext = {}; const envId = 'test-id'; @@ -466,15 +466,14 @@ describe('DataEgressService', () => { }, }; - dbService.table.scan.mockResolvedValueOnce([ - { + dbService.table.get.mockResolvedValueOnce({ status: 'PROCESSING', workspaceId: 'test-workspace-id', s3BucketName: 'test-s3BucketName', s3BucketPath: 'test-s3BucketPath', id: 'test-egress-store-id', }, - ]); + ); const requestContext = {}; const envId = 'test-workspace-id'; @@ -509,15 +508,14 @@ describe('DataEgressService', () => { }; const egressStoreId = 'test-egress-store-id'; - dbService.table.scan.mockResolvedValueOnce([ - { + dbService.table.get.mockResolvedValueOnce({ status: 'PROCESSED', workspaceId: 'test-workspace-id', s3BucketName: 'test-s3BucketName', s3BucketPath: 'test-s3BucketPath', id: egressStoreId, }, - ]); + ); const requestContext = {}; const envId = 'test-workspace-id'; @@ -615,8 +613,7 @@ describe('DataEgressService', () => { }; const egressStoreId = 'test-egress-store-id'; - dbService.table.scan.mockResolvedValueOnce([ - { + dbService.table.get.mockResolvedValueOnce({ status: 'CREATED', workspaceId: 'test-workspace-id', s3BucketName: 'test-s3BucketName', @@ -624,7 +621,7 @@ describe('DataEgressService', () => { id: egressStoreId, isAbleToSubmitEgressRequest, }, - ]); + ); const requestContext = {}; const envId = 'test-workspace-id'; @@ -669,11 +666,7 @@ describe('DataEgressService', () => { describe('Get Egress Store info', () => { it('should get egress store info', async () => { - dbService.table.scan.mockResolvedValue([ - { - workspaceId: 'test-egress-store-id', - }, - ]); + dbService.table.get.mockResolvedValue({ workspaceId: 'test-egress-store-id',}); const result = await dataEgressService.getEgressStoreInfo('test-egress-store-id'); expect(result).toStrictEqual({ @@ -682,7 +675,7 @@ describe('DataEgressService', () => { }); it('should error out egress store info', async () => { - dbService.table.scan.mockImplementationOnce(() => { + dbService.table.get.mockImplementationOnce(() => { throw new Error(); }); @@ -697,7 +690,7 @@ describe('DataEgressService', () => { }); it('should error out without finding egress store info', async () => { - dbService.table.scan.mockResolvedValue([]); + dbService.table.get.mockResolvedValue(); const result = await dataEgressService.getEgressStoreInfo('test-egress-store-id'); expect(result).toStrictEqual(null); @@ -872,7 +865,7 @@ describe('DataEgressService', () => { ver: 'ver', isAbleToSubmitEgressRequest: false, }; - dbService.table.scan.mockResolvedValue([mockEgressStoreInfo]); + dbService.table.get.mockResolvedValue(mockEgressStoreInfo); await expect(dataEgressService.notifySNS(requestContext, 'workspaceId')).rejects.toThrow( // It is better to check using boom.code instead of just the actual string, unless @@ -915,7 +908,7 @@ describe('DataEgressService', () => { ver: 'ver', isAbleToSubmitEgressRequest: true, }; - dbService.table.scan.mockResolvedValue([mockEgressStoreInfo]); + dbService.table.get.mockResolvedValue(mockEgressStoreInfo); const mockRequestContext = { principalIdentifier: { uid: 'test-createdBy' } }; await expect(dataEgressService.notifySNS(mockRequestContext, 'workspaceId')).rejects.toThrow( // It is better to check using boom.code instead of just the actual string, unless @@ -984,7 +977,7 @@ describe('DataEgressService', () => { callback(null, {}); }); - dbService.table.scan.mockResolvedValue([mockEgressStoreInfo]); + dbService.table.get.mockResolvedValue(mockEgressStoreInfo); const mockRequestContext = { principalIdentifier: { uid: 'createdBy' } }; dataEgressService.lockAndUpdate = jest.fn(); dataEgressService.publishMessage = jest.fn(); diff --git a/addons/addon-base-raas/packages/base-raas-services/lib/data-egress/data-egress-service.js b/addons/addon-base-raas/packages/base-raas-services/lib/data-egress/data-egress-service.js index 8eff8577f5..0308d58073 100644 --- a/addons/addon-base-raas/packages/base-raas-services/lib/data-egress/data-egress-service.js +++ b/addons/addon-base-raas/packages/base-raas-services/lib/data-egress/data-egress-service.js @@ -63,29 +63,20 @@ class DataEgressService extends Service { async getEgressStoreInfo(environmentId) { const workspaceId = environmentId; - let egressStoreScanResult = []; + let egressStoreResult; try { - egressStoreScanResult = await this._scanner() - .limit(1000) - .scan() - .then(egressStores => { - return egressStores.filter(store => store.workspaceId === workspaceId); - }); + egressStoreResult = await this._getter() + .key({ id: workspaceId }) + .get(); } catch (error) { throw this.boom.notFound(`Error in fetch egress store info: ${JSON.stringify(error)}`, true); } - if (egressStoreScanResult.length === 0) { + if (!egressStoreResult) { return null; } - if (egressStoreScanResult.length !== 1) { - throw this.boom.internalError( - `Error in getting egress store info: multiple results fetched from egrss store table`, - true, - ); - } - return egressStoreScanResult[0]; + return egressStoreResult; } async createEgressStore(requestContext, environment) {