lesgo 1.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/bin/lesgo-scripts.sh +4 -4
- package/dist/config/app.d.ts +7 -0
- package/dist/config/app.js +9 -0
- package/dist/config/aws.d.ts +5 -0
- package/dist/config/aws.js +4 -0
- package/dist/config/basicAuth.d.ts +7 -0
- package/dist/config/basicAuth.js +8 -0
- package/dist/config/crypto.d.ts +10 -0
- package/dist/config/crypto.js +9 -0
- package/dist/config/dynamodb.d.ts +8 -0
- package/dist/config/dynamodb.js +14 -0
- package/dist/config/elasticache.d.ts +7 -0
- package/dist/config/elasticache.js +6 -0
- package/dist/config/index.d.ts +11 -0
- package/dist/config/index.js +11 -0
- package/dist/config/jwt.d.ts +12 -0
- package/dist/config/jwt.js +16 -0
- package/dist/config/rds.d.ts +12 -0
- package/dist/config/rds.js +13 -0
- package/dist/config/s3.d.ts +5 -0
- package/dist/config/s3.js +5 -0
- package/dist/config/secretsManager.d.ts +4 -0
- package/dist/config/secretsManager.js +4 -0
- package/dist/config/sqs.d.ts +9 -0
- package/dist/config/sqs.js +18 -0
- package/dist/exceptions/LesgoException.d.ts +6 -0
- package/{src → dist}/exceptions/LesgoException.js +5 -4
- package/dist/exceptions/index.d.ts +1 -0
- package/dist/exceptions/index.js +1 -0
- package/dist/middlewares/disconnectMiddleware.d.ts +8 -0
- package/dist/middlewares/disconnectMiddleware.js +78 -0
- package/dist/middlewares/httpMiddleware.d.ts +12 -0
- package/dist/middlewares/httpMiddleware.js +74 -0
- package/dist/middlewares/httpResponseMiddleware.d.ts +7 -0
- package/dist/middlewares/httpResponseMiddleware.js +128 -0
- package/dist/middlewares/index.d.ts +7 -0
- package/dist/middlewares/index.js +7 -0
- package/dist/middlewares/invokeCommandMiddleware.d.ts +12 -0
- package/dist/middlewares/invokeCommandMiddleware.js +70 -0
- package/dist/middlewares/sqsMiddleware.d.ts +10 -0
- package/dist/middlewares/sqsMiddleware.js +70 -0
- package/dist/middlewares/verifyBasicAuthMiddleware.d.ts +8 -0
- package/dist/middlewares/verifyBasicAuthMiddleware.js +59 -0
- package/dist/middlewares/verifyJwtMiddleware.d.ts +6 -0
- package/dist/middlewares/verifyJwtMiddleware.js +37 -0
- package/dist/services/DynamoDbService/deleteRecord.d.ts +8 -0
- package/dist/services/DynamoDbService/deleteRecord.js +69 -0
- package/dist/services/DynamoDbService/getClient.d.ts +7 -0
- package/dist/services/DynamoDbService/getClient.js +30 -0
- package/dist/services/DynamoDbService/getTableName.d.ts +2 -0
- package/dist/services/DynamoDbService/getTableName.js +15 -0
- package/dist/services/DynamoDbService/index.d.ts +6 -0
- package/dist/services/DynamoDbService/index.js +6 -0
- package/dist/services/DynamoDbService/putRecord.d.ts +8 -0
- package/dist/services/DynamoDbService/putRecord.js +64 -0
- package/dist/services/DynamoDbService/query.d.ts +7 -0
- package/dist/services/DynamoDbService/query.js +78 -0
- package/dist/services/DynamoDbService/scan.d.ts +7 -0
- package/dist/services/DynamoDbService/scan.js +60 -0
- package/dist/services/DynamoDbService/updateRecord.d.ts +9 -0
- package/dist/services/DynamoDbService/updateRecord.js +89 -0
- package/dist/services/ElastiCacheRedisService/deleteRedisCache.d.ts +3 -0
- package/dist/services/ElastiCacheRedisService/deleteRedisCache.js +62 -0
- package/dist/services/ElastiCacheRedisService/disconnectElastiCacheRedisClient.d.ts +11 -0
- package/dist/services/ElastiCacheRedisService/disconnectElastiCacheRedisClient.js +69 -0
- package/dist/services/ElastiCacheRedisService/getElastiCacheRedisClient.d.ts +12 -0
- package/dist/services/ElastiCacheRedisService/getElastiCacheRedisClient.js +114 -0
- package/dist/services/ElastiCacheRedisService/getRedisCache.d.ts +3 -0
- package/dist/services/ElastiCacheRedisService/getRedisCache.js +70 -0
- package/dist/services/ElastiCacheRedisService/index.d.ts +5 -0
- package/dist/services/ElastiCacheRedisService/index.js +5 -0
- package/dist/services/ElastiCacheRedisService/setRedisCache.d.ts +6 -0
- package/dist/services/ElastiCacheRedisService/setRedisCache.js +77 -0
- package/dist/services/JWTService/decodeJwt.d.ts +7 -0
- package/dist/services/JWTService/decodeJwt.js +9 -0
- package/dist/services/JWTService/getJwtSecret.d.ts +13 -0
- package/dist/services/JWTService/getJwtSecret.js +54 -0
- package/dist/services/JWTService/index.d.ts +2 -0
- package/dist/services/JWTService/index.js +2 -0
- package/dist/services/JWTService/sign.d.ts +3 -0
- package/dist/services/JWTService/sign.js +31 -0
- package/dist/services/JWTService/verify.d.ts +7 -0
- package/dist/services/JWTService/verify.js +61 -0
- package/dist/services/LoggerService.d.ts +46 -0
- package/{src → dist}/services/LoggerService.js +29 -60
- package/dist/services/RDSAuroraMySQLProxyService/disconnectMySQLProxyClient.d.ts +2 -0
- package/dist/services/RDSAuroraMySQLProxyService/disconnectMySQLProxyClient.js +60 -0
- package/dist/services/RDSAuroraMySQLProxyService/getMySQLProxyClient.d.ts +8 -0
- package/dist/services/RDSAuroraMySQLProxyService/getMySQLProxyClient.js +87 -0
- package/dist/services/RDSAuroraMySQLProxyService/index.d.ts +3 -0
- package/dist/services/RDSAuroraMySQLProxyService/index.js +3 -0
- package/dist/services/RDSAuroraMySQLProxyService/query.d.ts +4 -0
- package/dist/services/RDSAuroraMySQLProxyService/query.js +63 -0
- package/dist/services/S3Service/getClient.d.ts +4 -0
- package/dist/services/S3Service/getClient.js +28 -0
- package/dist/services/S3Service/getDownloadSignedUrl.d.ts +7 -0
- package/dist/services/S3Service/getDownloadSignedUrl.js +58 -0
- package/dist/services/S3Service/getHeadObject.d.ts +13 -0
- package/dist/services/S3Service/getHeadObject.js +83 -0
- package/dist/services/S3Service/getObject.d.ts +10 -0
- package/dist/services/S3Service/getObject.js +89 -0
- package/dist/services/S3Service/getUploadSignedUrl.d.ts +7 -0
- package/dist/services/S3Service/getUploadSignedUrl.js +61 -0
- package/dist/services/S3Service/index.d.ts +6 -0
- package/dist/services/S3Service/index.js +6 -0
- package/dist/services/S3Service/putObject.d.ts +9 -0
- package/dist/services/S3Service/putObject.js +77 -0
- package/dist/services/SQSService/deleteMessage.d.ts +9 -0
- package/dist/services/SQSService/deleteMessage.js +69 -0
- package/dist/services/SQSService/dispatch.d.ts +9 -0
- package/dist/services/SQSService/dispatch.js +71 -0
- package/dist/services/SQSService/getClient.d.ts +4 -0
- package/dist/services/SQSService/getClient.js +28 -0
- package/dist/services/SQSService/getQueueUrl.d.ts +7 -0
- package/dist/services/SQSService/getQueueUrl.js +25 -0
- package/dist/services/SQSService/index.d.ts +4 -0
- package/dist/services/SQSService/index.js +4 -0
- package/dist/services/SQSService/receiveMessages.d.ts +8 -0
- package/dist/services/SQSService/receiveMessages.js +65 -0
- package/dist/services/SecretsManagerService/getClient.d.ts +7 -0
- package/dist/services/SecretsManagerService/getClient.js +28 -0
- package/dist/services/SecretsManagerService/getSecretValue.d.ts +7 -0
- package/dist/services/SecretsManagerService/getSecretValue.js +65 -0
- package/dist/services/SecretsManagerService/index.d.ts +2 -0
- package/dist/services/SecretsManagerService/index.js +2 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/types/aws.d.ts +8 -0
- package/dist/types/aws.js +1 -0
- package/dist/utils/cache/redis/deleteCache.d.ts +19 -0
- package/dist/utils/cache/redis/deleteCache.js +21 -0
- package/dist/utils/cache/redis/getCache.d.ts +22 -0
- package/dist/utils/cache/redis/getCache.js +24 -0
- package/dist/utils/cache/redis/getClient.d.ts +30 -0
- package/dist/utils/cache/redis/getClient.js +32 -0
- package/dist/utils/cache/redis/index.d.ts +4 -0
- package/dist/utils/cache/redis/index.js +4 -0
- package/dist/utils/cache/redis/setCache.d.ts +25 -0
- package/dist/utils/cache/redis/setCache.js +26 -0
- package/dist/utils/crypto/decrypt.d.ts +33 -0
- package/dist/utils/crypto/decrypt.js +59 -0
- package/dist/utils/crypto/encrypt.d.ts +31 -0
- package/dist/utils/crypto/encrypt.js +41 -0
- package/dist/utils/crypto/hash.d.ts +31 -0
- package/dist/utils/crypto/hash.js +56 -0
- package/dist/utils/crypto/index.d.ts +3 -0
- package/dist/utils/crypto/index.js +3 -0
- package/dist/utils/crypto/validateEncryptionFields.d.ts +19 -0
- package/dist/utils/crypto/validateEncryptionFields.js +71 -0
- package/dist/utils/db/mysql/proxy/disconnect.d.ts +2 -0
- package/dist/utils/db/mysql/proxy/disconnect.js +5 -0
- package/dist/utils/db/mysql/proxy/disconnectDb.d.ts +2 -0
- package/dist/utils/db/mysql/proxy/disconnectDb.js +5 -0
- package/dist/utils/db/mysql/proxy/getClient.d.ts +4 -0
- package/dist/utils/db/mysql/proxy/getClient.js +5 -0
- package/dist/utils/db/mysql/proxy/index.d.ts +3 -0
- package/dist/utils/db/mysql/proxy/index.js +3 -0
- package/dist/utils/db/mysql/proxy/query.d.ts +4 -0
- package/dist/utils/db/mysql/proxy/query.js +45 -0
- package/dist/utils/dynamodb/deleteRecord.d.ts +5 -0
- package/dist/utils/dynamodb/deleteRecord.js +39 -0
- package/dist/utils/dynamodb/getClient.d.ts +3 -0
- package/dist/utils/dynamodb/getClient.js +5 -0
- package/dist/utils/dynamodb/index.d.ts +6 -0
- package/dist/utils/dynamodb/index.js +6 -0
- package/dist/utils/dynamodb/putRecord.d.ts +4 -0
- package/dist/utils/dynamodb/putRecord.js +39 -0
- package/dist/utils/dynamodb/query.d.ts +5 -0
- package/dist/utils/dynamodb/query.js +52 -0
- package/dist/utils/dynamodb/scan.d.ts +4 -0
- package/dist/utils/dynamodb/scan.js +40 -0
- package/dist/utils/dynamodb/updateRecord.d.ts +5 -0
- package/dist/utils/dynamodb/updateRecord.js +53 -0
- package/dist/utils/formatUnixTimestamp.d.ts +8 -0
- package/dist/utils/formatUnixTimestamp.js +17 -0
- package/dist/utils/generateUid.d.ts +13 -0
- package/{src → dist}/utils/generateUid.js +9 -4
- package/dist/utils/getCurrentDatetime.d.ts +2 -0
- package/dist/utils/getCurrentDatetime.js +4 -0
- package/dist/utils/getCurrentTimestamp.d.ts +7 -0
- package/dist/utils/getCurrentTimestamp.js +9 -0
- package/dist/utils/getJwtSubFromAuthHeader.d.ts +9 -0
- package/dist/utils/getJwtSubFromAuthHeader.js +24 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/isDecimal.d.ts +8 -0
- package/dist/utils/isDecimal.js +9 -0
- package/dist/utils/isEmail.d.ts +9 -0
- package/{src → dist}/utils/isEmail.js +9 -4
- package/dist/utils/isEmpty.d.ts +8 -0
- package/dist/utils/isEmpty.js +19 -0
- package/dist/utils/jwt/index.d.ts +2 -0
- package/dist/utils/jwt/index.js +2 -0
- package/dist/utils/jwt/sign.d.ts +3 -0
- package/dist/utils/jwt/sign.js +5 -0
- package/dist/utils/jwt/verify.d.ts +3 -0
- package/dist/utils/jwt/verify.js +12 -0
- package/dist/utils/logger.d.ts +20 -0
- package/dist/utils/logger.js +38 -0
- package/dist/utils/s3/getClient.d.ts +3 -0
- package/dist/utils/s3/getClient.js +5 -0
- package/dist/utils/s3/getDownloadSignedUrl.d.ts +5 -0
- package/dist/utils/s3/getDownloadSignedUrl.js +39 -0
- package/dist/utils/s3/getHeadObject.d.ts +10 -0
- package/dist/utils/s3/getHeadObject.js +39 -0
- package/dist/utils/s3/getObject.d.ts +13 -0
- package/dist/utils/s3/getObject.js +51 -0
- package/dist/utils/s3/getUploadSignedUrl.d.ts +5 -0
- package/dist/utils/s3/getUploadSignedUrl.js +39 -0
- package/dist/utils/s3/index.d.ts +6 -0
- package/dist/utils/s3/index.js +6 -0
- package/dist/utils/s3/putObject.d.ts +5 -0
- package/dist/utils/s3/putObject.js +39 -0
- package/dist/utils/secretsmanager/getClient.d.ts +3 -0
- package/dist/utils/secretsmanager/getClient.js +5 -0
- package/dist/utils/secretsmanager/getSecretValue.d.ts +4 -0
- package/dist/utils/secretsmanager/getSecretValue.js +68 -0
- package/dist/utils/secretsmanager/index.d.ts +2 -0
- package/dist/utils/secretsmanager/index.js +2 -0
- package/dist/utils/sqs/deleteMessage.d.ts +5 -0
- package/dist/utils/sqs/deleteMessage.js +39 -0
- package/dist/utils/sqs/dispatch.d.ts +5 -0
- package/dist/utils/sqs/dispatch.js +39 -0
- package/dist/utils/sqs/getClient.d.ts +3 -0
- package/dist/utils/sqs/getClient.js +5 -0
- package/dist/utils/sqs/index.d.ts +4 -0
- package/dist/utils/sqs/index.js +4 -0
- package/dist/utils/sqs/receiveMessages.d.ts +5 -0
- package/dist/utils/sqs/receiveMessages.js +39 -0
- package/dist/utils/validateFields.d.ts +22 -0
- package/{src → dist}/utils/validateFields.js +13 -19
- package/package.json +145 -34
- package/src/exceptions/__tests__/LesgoException.spec.js +0 -24
- package/src/exceptions/index.js +0 -4
- package/src/index.js +0 -4
- package/src/middlewares/__mocks__/ValidationErrorException.js +0 -18
- package/src/middlewares/__tests__/basicAuthMiddleware.spec.js +0 -264
- package/src/middlewares/__tests__/clientAuthMiddleware.spec.js +0 -235
- package/src/middlewares/__tests__/errorHttpResponseMiddleware.spec.js +0 -203
- package/src/middlewares/__tests__/gzipHttpResponse.spec.js +0 -185
- package/src/middlewares/__tests__/httpNoOutputMiddleware.spec.js +0 -201
- package/src/middlewares/__tests__/normalizeHttpRequestMiddleware.spec.js +0 -181
- package/src/middlewares/__tests__/normalizeSQSMessageMiddleware.spec.js +0 -120
- package/src/middlewares/__tests__/successHttpResponseMiddleware.spec.js +0 -172
- package/src/middlewares/__tests__/verifyJwtMiddleware.spec.js +0 -297
- package/src/middlewares/basicAuthMiddleware.js +0 -125
- package/src/middlewares/clientAuthMiddleware.js +0 -103
- package/src/middlewares/errorHttpResponseMiddleware.js +0 -101
- package/src/middlewares/gzipHttpResponse.js +0 -98
- package/src/middlewares/httpMiddleware.js +0 -19
- package/src/middlewares/httpNoOutputMiddleware.js +0 -91
- package/src/middlewares/index.js +0 -19
- package/src/middlewares/normalizeHttpRequestMiddleware.js +0 -101
- package/src/middlewares/normalizeSQSMessageMiddleware.js +0 -67
- package/src/middlewares/successHttpResponseMiddleware.js +0 -85
- package/src/middlewares/verifyJwtMiddleware.js +0 -73
- package/src/services/AuroraDbRDSProxyService.js +0 -182
- package/src/services/AuroraDbService.js +0 -111
- package/src/services/DynamoDbService.js +0 -177
- package/src/services/ElastiCacheService.js +0 -17
- package/src/services/ElasticsearchService.js +0 -181
- package/src/services/FirebaseAdminService.js +0 -108
- package/src/services/JwtService.js +0 -52
- package/src/services/S3Service.js +0 -59
- package/src/services/SQSService.js +0 -65
- package/src/services/__tests__/AuroraDbRDSProxyService.spec.js +0 -278
- package/src/services/__tests__/AuroraDbService.spec.js +0 -211
- package/src/services/__tests__/AwsElasticsearchConnection.spec.js +0 -89
- package/src/services/__tests__/DynamoDbService.spec.js +0 -314
- package/src/services/__tests__/ElasticsearchService.spec.js +0 -201
- package/src/services/__tests__/FirebaseAdminService.spec.js +0 -356
- package/src/services/__tests__/JwtService.spec.js +0 -35
- package/src/services/__tests__/LengthAwarePaginator.spec.js +0 -223
- package/src/services/__tests__/LoggerService.spec.js +0 -267
- package/src/services/__tests__/Paginator.spec.js +0 -383
- package/src/services/__tests__/S3Service.spec.js +0 -55
- package/src/services/__tests__/SQSService.spec.js +0 -47
- package/src/services/__tests__/SignedRequest.spec.js +0 -103
- package/src/services/aws/AwsElasticsearchConnection.js +0 -59
- package/src/services/aws/SignedRequest.js +0 -158
- package/src/services/index.js +0 -19
- package/src/services/pagination/LengthAwarePaginator.js +0 -49
- package/src/services/pagination/Paginator.js +0 -260
- package/src/utils/__mocks__/db.js +0 -109
- package/src/utils/__tests__/cache.spec.js +0 -131
- package/src/utils/__tests__/crypto.spec.js +0 -122
- package/src/utils/__tests__/db.spec.js +0 -70
- package/src/utils/__tests__/dynamodb.spec.js +0 -27
- package/src/utils/__tests__/elasticsearch.spec.js +0 -43
- package/src/utils/__tests__/generateUid.spec.js +0 -36
- package/src/utils/__tests__/getJwtSubFromAuthHeader.spec.js +0 -20
- package/src/utils/__tests__/isDecimal.spec.js +0 -12
- package/src/utils/__tests__/isEmail.spec.js +0 -28
- package/src/utils/__tests__/isEmpty.spec.js +0 -31
- package/src/utils/__tests__/logger.spec.js +0 -11
- package/src/utils/__tests__/objectStore.spec.js +0 -67
- package/src/utils/__tests__/prepSQLInsertParams.spec.js +0 -46
- package/src/utils/__tests__/prepSQLUpdateParams.spec.js +0 -36
- package/src/utils/__tests__/queue.spec.js +0 -54
- package/src/utils/__tests__/validateFields.spec.js +0 -374
- package/src/utils/cache.js +0 -215
- package/src/utils/crypto.js +0 -77
- package/src/utils/db.js +0 -17
- package/src/utils/dynamodb.js +0 -6
- package/src/utils/elasticsearch.js +0 -20
- package/src/utils/getJwtSubFromAuthHeader.js +0 -18
- package/src/utils/index.js +0 -26
- package/src/utils/isDecimal.js +0 -2
- package/src/utils/isEmpty.js +0 -6
- package/src/utils/logger.js +0 -25
- package/src/utils/objectStore.js +0 -11
- package/src/utils/prepSQLInsertParams.js +0 -21
- package/src/utils/prepSQLUpdateParams.js +0 -25
- package/src/utils/queue.js +0 -11
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import dataApiClient from 'data-api-client';
|
|
2
|
-
import dbConfig from 'Config/db'; // eslint-disable-line import/no-unresolved
|
|
3
|
-
import AuroraDbService from '../AuroraDbService';
|
|
4
|
-
import LesgoException from '../../exceptions/LesgoException';
|
|
5
|
-
|
|
6
|
-
const auroraConfig = {
|
|
7
|
-
secretArn: 'fakeSecretArn',
|
|
8
|
-
resourceArn: 'fakeResourceArn',
|
|
9
|
-
database: 'fakeDbName',
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
describe('test AuroraDbService instantiate', () => {
|
|
13
|
-
it('should not throw exception when instantiating', () => {
|
|
14
|
-
const db = new AuroraDbService();
|
|
15
|
-
|
|
16
|
-
expect(dataApiClient).toHaveBeenCalledWith({});
|
|
17
|
-
expect(db.client.mocked).toMatchObject({});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should not throw exception with custom config', () => {
|
|
21
|
-
const db = new AuroraDbService(auroraConfig);
|
|
22
|
-
|
|
23
|
-
expect(dataApiClient).toHaveBeenCalledWith(auroraConfig);
|
|
24
|
-
expect(db.client.mocked).toMatchObject(auroraConfig);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should not throw exception with custom region', () => {
|
|
28
|
-
const db = new AuroraDbService({
|
|
29
|
-
...auroraConfig,
|
|
30
|
-
region: 'ap-southeast-1',
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
expect(dataApiClient).toHaveBeenCalledWith(auroraConfig);
|
|
34
|
-
expect(db.client.mocked).toMatchObject(auroraConfig);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('test AuroraDbService connect', () => {
|
|
39
|
-
it('should have updated credentials when calling connect', () => {
|
|
40
|
-
const db = new AuroraDbService(auroraConfig);
|
|
41
|
-
db.connect({
|
|
42
|
-
secretArn: dbConfig.secretCommandArn,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
expect(db.client.mocked).toMatchObject({
|
|
46
|
-
secretArn: dbConfig.secretCommandArn,
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('test AuroraDbService query', () => {
|
|
52
|
-
it('should return records object when calling query function', async () => {
|
|
53
|
-
const db = new AuroraDbService(auroraConfig);
|
|
54
|
-
return expect(db.query('SELECT_QUERY', {})).resolves.toMatchObject({
|
|
55
|
-
records: [
|
|
56
|
-
{
|
|
57
|
-
id: 1,
|
|
58
|
-
uid: 'some-uid-1',
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
id: 2,
|
|
62
|
-
uid: 'some-uid-2',
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('test AuroraDbService select', () => {
|
|
70
|
-
it('should return array records when calling select function', async () => {
|
|
71
|
-
const db = new AuroraDbService(auroraConfig);
|
|
72
|
-
return expect(db.select('SELECT_QUERY', {})).resolves.toMatchObject([
|
|
73
|
-
{
|
|
74
|
-
id: 1,
|
|
75
|
-
uid: 'some-uid-1',
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
id: 2,
|
|
79
|
-
uid: 'some-uid-2',
|
|
80
|
-
},
|
|
81
|
-
]);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should throw an exception when writing with invalid query', async () => {
|
|
85
|
-
const error = new LesgoException(
|
|
86
|
-
'Exception caught executing SQL Statement',
|
|
87
|
-
'AURORADBSERVICE_QUERY_EXCEPTION',
|
|
88
|
-
500,
|
|
89
|
-
{
|
|
90
|
-
err: {
|
|
91
|
-
code: 'BadRequestException',
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
const db = new AuroraDbService(auroraConfig);
|
|
97
|
-
return expect(db.select('INVALID_QUERY', {})).rejects.toMatchObject(error);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should throw an exception when calling select with invalid query parameters', async () => {
|
|
101
|
-
const error = new LesgoException(
|
|
102
|
-
'Exception caught executing SQL Statement',
|
|
103
|
-
'AURORADBSERVICE_QUERY_EXCEPTION',
|
|
104
|
-
500,
|
|
105
|
-
{
|
|
106
|
-
err: {
|
|
107
|
-
code: 'BadRequestException',
|
|
108
|
-
},
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const db = new AuroraDbService(auroraConfig);
|
|
113
|
-
return expect(
|
|
114
|
-
db.select('RANDOM_QUERY', 'INVALID_QUERY_PARAMETERS')
|
|
115
|
-
).rejects.toMatchObject(error);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe('test AuroraDbService selectPaginate', () => {
|
|
120
|
-
it('should return paginated records when calling selectPaginate function', async () => {
|
|
121
|
-
const db = new AuroraDbService(auroraConfig);
|
|
122
|
-
return expect(db.selectPaginate('SELECT_QUERY', {})).resolves.toMatchObject(
|
|
123
|
-
{
|
|
124
|
-
count: 2,
|
|
125
|
-
previous_page: false,
|
|
126
|
-
current_page: 1,
|
|
127
|
-
next_page: false,
|
|
128
|
-
per_page: 10,
|
|
129
|
-
items: [
|
|
130
|
-
{
|
|
131
|
-
id: 1,
|
|
132
|
-
uid: 'some-uid-1',
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
id: 2,
|
|
136
|
-
uid: 'some-uid-2',
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('should return paginated records when calling selectPaginate with defined total', async () => {
|
|
144
|
-
const db = new AuroraDbService(auroraConfig);
|
|
145
|
-
return expect(
|
|
146
|
-
db.selectPaginate('SELECT_QUERY', {}, 1, 2, 1)
|
|
147
|
-
).resolves.toMatchObject({
|
|
148
|
-
count: 1,
|
|
149
|
-
previous_page: 1,
|
|
150
|
-
current_page: 2,
|
|
151
|
-
next_page: 3,
|
|
152
|
-
per_page: 1,
|
|
153
|
-
items: [
|
|
154
|
-
{
|
|
155
|
-
id: 1,
|
|
156
|
-
uid: 'some-uid-1',
|
|
157
|
-
},
|
|
158
|
-
],
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe('test AuroraDbService selectFirst', () => {
|
|
164
|
-
it('should only return the first record when calling selectFirst', async () => {
|
|
165
|
-
const db = new AuroraDbService(auroraConfig);
|
|
166
|
-
return expect(db.selectFirst('SELECT_QUERY', {})).resolves.toMatchObject({
|
|
167
|
-
id: 1,
|
|
168
|
-
uid: 'some-uid-1',
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
describe('test AuroraDbService insert', () => {
|
|
174
|
-
it('should return recordId when inserting record', async () => {
|
|
175
|
-
const db = new AuroraDbService(auroraConfig);
|
|
176
|
-
return expect(db.insert('INSERT_QUERY', {})).resolves.toEqual(20);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('should throw exception when calling insert with invalid query', async () => {
|
|
180
|
-
const error = new LesgoException(
|
|
181
|
-
'No records inserted from INSERT query',
|
|
182
|
-
'AURORADBSERVICE_NO_RECORDS_INSERTED',
|
|
183
|
-
400
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
const db = new AuroraDbService(auroraConfig);
|
|
187
|
-
return expect(db.insert('INVALID_INSERT_QUERY', {})).rejects.toMatchObject(
|
|
188
|
-
error
|
|
189
|
-
);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe('test AuroraDbService update', () => {
|
|
194
|
-
it('should return success when making update query', async () => {
|
|
195
|
-
const db = new AuroraDbService(auroraConfig);
|
|
196
|
-
return db.update('UPDATE_QUERY', {});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('should throw exception when caliing update with invalid query', async () => {
|
|
200
|
-
const error = new LesgoException(
|
|
201
|
-
'No records updated from UPDATE query',
|
|
202
|
-
'AURORADBSERVICE_NO_RECORDS_UPDATED',
|
|
203
|
-
400
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
const db = new AuroraDbService(auroraConfig);
|
|
207
|
-
return expect(db.update('INVALID_UPDATE_QUERY', {})).rejects.toMatchObject(
|
|
208
|
-
error
|
|
209
|
-
);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import AWS from 'aws-sdk';
|
|
2
|
-
import { URL } from 'url';
|
|
3
|
-
import AwsElasticsearchConnection from '../aws/AwsElasticsearchConnection';
|
|
4
|
-
|
|
5
|
-
const commonConn = new AwsElasticsearchConnection();
|
|
6
|
-
|
|
7
|
-
describe('ServicesGroup: test AwsElasticsearchConnection Credentails', () => {
|
|
8
|
-
it('test getCredentials AwsElasticsearchConnection', async () => {
|
|
9
|
-
await expect(commonConn.getCredentials()).resolves.toMatchObject({
|
|
10
|
-
mocked: {
|
|
11
|
-
credentials: 'mockedCredentials',
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('test getCredentails and throws rejects promise', async () => {
|
|
17
|
-
const oldConfig = AWS.config;
|
|
18
|
-
|
|
19
|
-
AWS.config = {
|
|
20
|
-
...AWS.config,
|
|
21
|
-
getCredentials: jest.fn().mockImplementation(callback => {
|
|
22
|
-
return callback(
|
|
23
|
-
{
|
|
24
|
-
mocked: {
|
|
25
|
-
error: 'mockedError',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
null
|
|
29
|
-
);
|
|
30
|
-
}),
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
await expect(commonConn.getCredentials()).rejects.toMatchObject({
|
|
34
|
-
mocked: {
|
|
35
|
-
error: 'mockedError',
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// return it back the old config
|
|
40
|
-
AWS.config = oldConfig;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should throw error if credential is empty', async () => {
|
|
44
|
-
const oldConfig = AWS.config.credentials;
|
|
45
|
-
AWS.config.credentials = null;
|
|
46
|
-
|
|
47
|
-
await expect(commonConn.getCredentials()).rejects.toThrow(
|
|
48
|
-
new Error('Invalid AWS Credentials')
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
// return it back the old config
|
|
52
|
-
AWS.config.credentials = oldConfig;
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('ServicesGroup: test AwsElasticsearchConnection Request', () => {
|
|
57
|
-
it('should call the request method', async () => {
|
|
58
|
-
const conn = new AwsElasticsearchConnection({
|
|
59
|
-
awsRegion: 'us-east-1',
|
|
60
|
-
url: new URL('http://localhost'),
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
await conn.request({ method: 'POST' }, () => {}); // using no body
|
|
64
|
-
await conn.request({ method: 'POST', body: 'Yow' }, () => {}); // using string to body
|
|
65
|
-
await conn.request({ method: 'POST', body: ['Yow'] }, () => {}); // using array to body
|
|
66
|
-
|
|
67
|
-
await conn.request(
|
|
68
|
-
{
|
|
69
|
-
method: 'POST',
|
|
70
|
-
body: ['Yow'],
|
|
71
|
-
},
|
|
72
|
-
err => {
|
|
73
|
-
throw err;
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should call the request method and throw awsRegion Error', async () => {
|
|
79
|
-
const conn = new AwsElasticsearchConnection({
|
|
80
|
-
awsRegion: null,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
await conn.request({}, err => {
|
|
84
|
-
return expect(err).toMatchObject({
|
|
85
|
-
message: 'Please provide the awsRegion!',
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { DocumentClient } from 'aws-sdk/clients/dynamodb'; // eslint-disable-line import/no-extraneous-dependencies
|
|
2
|
-
import DynamoDbService from '../DynamoDbService';
|
|
3
|
-
import LesgoException from '../../exceptions/LesgoException';
|
|
4
|
-
|
|
5
|
-
describe('test DynamoDbService connect', () => {
|
|
6
|
-
it('should not throw an error when instantiating DynamoDbService', () => {
|
|
7
|
-
// eslint-disable-next-line no-unused-vars
|
|
8
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
9
|
-
|
|
10
|
-
expect(DocumentClient).toHaveBeenCalledWith({ region: 'ap-southeast-1' });
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should throw an error when instantiating DynamoDbService with missing region', () => {
|
|
14
|
-
try {
|
|
15
|
-
expect(new DynamoDbService()).toThrow();
|
|
16
|
-
} catch (err) {
|
|
17
|
-
expect(err).toMatchObject(
|
|
18
|
-
new LesgoException(
|
|
19
|
-
'Missing required parameter region',
|
|
20
|
-
'DYNAMODB_MISSING_PARAMETER'
|
|
21
|
-
)
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('test DynamoDbService query', () => {
|
|
28
|
-
it('should return a list of items when calling query', () => {
|
|
29
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
30
|
-
|
|
31
|
-
const tableName = 'sampleTable';
|
|
32
|
-
const keyConditionExpression = 'key = :keyId';
|
|
33
|
-
const expressionAttributeValues = { ':keyId': 123 };
|
|
34
|
-
const projectionExpression = ['key', 'value'];
|
|
35
|
-
|
|
36
|
-
return expect(
|
|
37
|
-
db.query(
|
|
38
|
-
tableName,
|
|
39
|
-
keyConditionExpression,
|
|
40
|
-
expressionAttributeValues,
|
|
41
|
-
projectionExpression
|
|
42
|
-
)
|
|
43
|
-
).resolves.toMatchObject([
|
|
44
|
-
{
|
|
45
|
-
key: 123,
|
|
46
|
-
value: 'abc',
|
|
47
|
-
},
|
|
48
|
-
]);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should throw exception when tableName is empty', () => {
|
|
52
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
53
|
-
|
|
54
|
-
const tableName = '';
|
|
55
|
-
const keyConditionExpression = 'key = :keyId';
|
|
56
|
-
const expressionAttributeValues = { ':keyId': 123 };
|
|
57
|
-
const projectionExpression = ['key', 'value'];
|
|
58
|
-
|
|
59
|
-
return expect(
|
|
60
|
-
db.query(
|
|
61
|
-
tableName,
|
|
62
|
-
keyConditionExpression,
|
|
63
|
-
expressionAttributeValues,
|
|
64
|
-
projectionExpression
|
|
65
|
-
)
|
|
66
|
-
).rejects.toThrow(
|
|
67
|
-
new LesgoException(
|
|
68
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB QUERY OPERATION',
|
|
69
|
-
'DYNAMODB_QUERY_EXCEPTION'
|
|
70
|
-
)
|
|
71
|
-
);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should throw exception when expressionAttributeValues is not an object', () => {
|
|
75
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
76
|
-
|
|
77
|
-
const tableName = 'sampleTable';
|
|
78
|
-
const keyConditionExpression = 'key = :keyId';
|
|
79
|
-
const expressionAttributeValues = 'someString';
|
|
80
|
-
const projectionExpression = ['key', 'value'];
|
|
81
|
-
|
|
82
|
-
return expect(
|
|
83
|
-
db.query(
|
|
84
|
-
tableName,
|
|
85
|
-
keyConditionExpression,
|
|
86
|
-
expressionAttributeValues,
|
|
87
|
-
projectionExpression
|
|
88
|
-
)
|
|
89
|
-
).rejects.toThrow(
|
|
90
|
-
new LesgoException(
|
|
91
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB QUERY OPERATION',
|
|
92
|
-
'DYNAMODB_QUERY_EXCEPTION'
|
|
93
|
-
)
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should throw exception when projectionExpression is not an array', () => {
|
|
98
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
99
|
-
|
|
100
|
-
const tableName = 'sampleTable';
|
|
101
|
-
const keyConditionExpression = 'key = :keyId';
|
|
102
|
-
const expressionAttributeValues = { ':keyId': 123 };
|
|
103
|
-
const projectionExpression = 'someString';
|
|
104
|
-
|
|
105
|
-
return expect(
|
|
106
|
-
db.query(
|
|
107
|
-
tableName,
|
|
108
|
-
keyConditionExpression,
|
|
109
|
-
expressionAttributeValues,
|
|
110
|
-
projectionExpression
|
|
111
|
-
)
|
|
112
|
-
).rejects.toThrow(
|
|
113
|
-
new LesgoException(
|
|
114
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB QUERY OPERATION',
|
|
115
|
-
'DYNAMODB_QUERY_EXCEPTION'
|
|
116
|
-
)
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('test DynamoDbService queryCount', () => {
|
|
122
|
-
it('should return count when calling query', () => {
|
|
123
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
124
|
-
|
|
125
|
-
const tableName = 'sampleTable';
|
|
126
|
-
const keyConditionExpression = 'key = :keyId';
|
|
127
|
-
const expressionAttributeValues = { ':keyId': 123 };
|
|
128
|
-
|
|
129
|
-
return expect(
|
|
130
|
-
db.queryCount(
|
|
131
|
-
tableName,
|
|
132
|
-
keyConditionExpression,
|
|
133
|
-
expressionAttributeValues
|
|
134
|
-
)
|
|
135
|
-
).resolves.toEqual(1);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should throw exception when tableName is empty', () => {
|
|
139
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
140
|
-
|
|
141
|
-
const tableName = '';
|
|
142
|
-
const keyConditionExpression = 'key = :keyId';
|
|
143
|
-
const expressionAttributeValues = { ':keyId': 123 };
|
|
144
|
-
|
|
145
|
-
return expect(
|
|
146
|
-
db.queryCount(
|
|
147
|
-
tableName,
|
|
148
|
-
keyConditionExpression,
|
|
149
|
-
expressionAttributeValues
|
|
150
|
-
)
|
|
151
|
-
).rejects.toThrow(
|
|
152
|
-
new LesgoException(
|
|
153
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB QUERY COUNT OPERATION',
|
|
154
|
-
'DYNAMODB_QUERY_EXCEPTION'
|
|
155
|
-
)
|
|
156
|
-
);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('should throw exception when expressionAttributeValues is not an object', () => {
|
|
160
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
161
|
-
|
|
162
|
-
const tableName = 'sampleTable';
|
|
163
|
-
const keyConditionExpression = 'key = :keyId';
|
|
164
|
-
const expressionAttributeValues = 'someString';
|
|
165
|
-
|
|
166
|
-
return expect(
|
|
167
|
-
db.queryCount(
|
|
168
|
-
tableName,
|
|
169
|
-
keyConditionExpression,
|
|
170
|
-
expressionAttributeValues
|
|
171
|
-
)
|
|
172
|
-
).rejects.toThrow(
|
|
173
|
-
new LesgoException(
|
|
174
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB QUERY COUNT OPERATION',
|
|
175
|
-
'DYNAMODB_QUERY_EXCEPTION'
|
|
176
|
-
)
|
|
177
|
-
);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('test DynamoDbService put', () => {
|
|
182
|
-
it('should return recordCount when calling put', () => {
|
|
183
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
184
|
-
|
|
185
|
-
const tableName = 'sampleTable';
|
|
186
|
-
const item = {
|
|
187
|
-
key: 123,
|
|
188
|
-
value: 'abc',
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
return expect(db.put(tableName, item)).resolves.toEqual({
|
|
192
|
-
recordCount: 1,
|
|
193
|
-
data: {},
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('should throw exception when tableName is empty', () => {
|
|
198
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
199
|
-
|
|
200
|
-
const tableName = '';
|
|
201
|
-
const item = {
|
|
202
|
-
key: 123,
|
|
203
|
-
value: 'abc',
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
return expect(db.put(tableName, item)).rejects.toThrow(
|
|
207
|
-
new LesgoException(
|
|
208
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB PUT OPERATION',
|
|
209
|
-
'DYNAMODB_PUT_EXCEPTION'
|
|
210
|
-
)
|
|
211
|
-
);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('should throw exception when item is not an object', () => {
|
|
215
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
216
|
-
|
|
217
|
-
const tableName = 'sampleTable';
|
|
218
|
-
const item = 'someString';
|
|
219
|
-
|
|
220
|
-
return expect(db.put(tableName, item)).rejects.toThrow(
|
|
221
|
-
new LesgoException(
|
|
222
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB PUT OPERATION',
|
|
223
|
-
'DYNAMODB_PUT_EXCEPTION'
|
|
224
|
-
)
|
|
225
|
-
);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
describe('test DynamoDbService update', () => {
|
|
230
|
-
it('should return count when calling query', () => {
|
|
231
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
232
|
-
|
|
233
|
-
const tableName = 'sampleTable';
|
|
234
|
-
const key = { key: 123 };
|
|
235
|
-
const updateExpression = 'SET value = :value';
|
|
236
|
-
const expressionAttributeValues = { ':value': 'asd' };
|
|
237
|
-
|
|
238
|
-
return expect(
|
|
239
|
-
db.update(tableName, key, updateExpression, expressionAttributeValues)
|
|
240
|
-
).resolves.toEqual({ recordCount: 1, data: {} });
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('should throw exception when tableName is empty', () => {
|
|
244
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
245
|
-
|
|
246
|
-
const tableName = '';
|
|
247
|
-
const key = { key: 123 };
|
|
248
|
-
const updateExpression = 'SET value = :value';
|
|
249
|
-
const expressionAttributeValues = { ':value': 'asd' };
|
|
250
|
-
|
|
251
|
-
return expect(
|
|
252
|
-
db.update(tableName, key, updateExpression, expressionAttributeValues)
|
|
253
|
-
).rejects.toThrow(
|
|
254
|
-
new LesgoException(
|
|
255
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB UPDATE OPERATION',
|
|
256
|
-
'DYNAMODB_UPDATE_EXCEPTION'
|
|
257
|
-
)
|
|
258
|
-
);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('should throw exception when expressionAttributeValues is not an object', () => {
|
|
262
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
263
|
-
|
|
264
|
-
const tableName = 'sampleTable';
|
|
265
|
-
const key = { key: 123 };
|
|
266
|
-
const updateExpression = 'SET value = :value';
|
|
267
|
-
const expressionAttributeValues = 'someString';
|
|
268
|
-
|
|
269
|
-
return expect(
|
|
270
|
-
db.update(tableName, key, updateExpression, expressionAttributeValues)
|
|
271
|
-
).rejects.toThrow(
|
|
272
|
-
new LesgoException(
|
|
273
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB UPDATE OPERATION',
|
|
274
|
-
'DYNAMODB_UPDATE_EXCEPTION'
|
|
275
|
-
)
|
|
276
|
-
);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('should throw exception when key is not an object', () => {
|
|
280
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
281
|
-
|
|
282
|
-
const tableName = 'sampleTable';
|
|
283
|
-
const key = 123;
|
|
284
|
-
const updateExpression = 'SET value = :value';
|
|
285
|
-
const expressionAttributeValues = { ':value': 'asd' };
|
|
286
|
-
|
|
287
|
-
return expect(
|
|
288
|
-
db.update(tableName, key, updateExpression, expressionAttributeValues)
|
|
289
|
-
).rejects.toThrow(
|
|
290
|
-
new LesgoException(
|
|
291
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB UPDATE OPERATION',
|
|
292
|
-
'DYNAMODB_UPDATE_EXCEPTION'
|
|
293
|
-
)
|
|
294
|
-
);
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
it('should throw exception when updateExpression is not a string', () => {
|
|
298
|
-
const db = new DynamoDbService({ region: 'ap-southeast-1' });
|
|
299
|
-
|
|
300
|
-
const tableName = 'sampleTable';
|
|
301
|
-
const key = { key: 123 };
|
|
302
|
-
const updateExpression = { some: 'value' };
|
|
303
|
-
const expressionAttributeValues = { ':value': 'asd' };
|
|
304
|
-
|
|
305
|
-
return expect(
|
|
306
|
-
db.update(tableName, key, updateExpression, expressionAttributeValues)
|
|
307
|
-
).rejects.toThrow(
|
|
308
|
-
new LesgoException(
|
|
309
|
-
'EXCEPTION ENCOUNTERED FOR DYNAMODB UPDATE OPERATION',
|
|
310
|
-
'DYNAMODB_UPDATE_EXCEPTION'
|
|
311
|
-
)
|
|
312
|
-
);
|
|
313
|
-
});
|
|
314
|
-
});
|