apf-node-common 1.0.109 → 1.0.110

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.
Files changed (37) hide show
  1. package/ApplicationContextService.js +103 -103
  2. package/CoreUtils.js +59 -59
  3. package/Logger/index.js +93 -93
  4. package/Logger/loggerTransports.js +137 -137
  5. package/SSMConfig.js +44 -44
  6. package/ScheduleCalculationService.js +0 -0
  7. package/auditlog/AuditLogger.js +58 -58
  8. package/auditlog/AuditLoggerRepository.js +38 -38
  9. package/auditlog/AuditLoggerService.js +37 -37
  10. package/config/SSMParameters.js +16 -16
  11. package/constants/CommonMessages.js +14 -14
  12. package/constants/Frequency.js +8 -8
  13. package/constants/TimeZone.js +11 -11
  14. package/constants/UserType.js +9 -9
  15. package/exception/CustomException.js +36 -36
  16. package/exception/SendResponse.js +139 -139
  17. package/index.js +187 -187
  18. package/package.json +29 -29
  19. package/test/AWSUtilityIntegrationTest.js +94 -94
  20. package/test/FrequencyValidatorTest.js +0 -0
  21. package/test/LambdaCommunicationServiceTest.js +83 -83
  22. package/test/ScheduleCalculationServiceTest.js +0 -0
  23. package/utils/HashIds.js +139 -139
  24. package/utils/NumberFormatter.js +253 -253
  25. package/utils/aws/AESEncryptionUsingKMS.js +106 -106
  26. package/utils/aws/AWSAPIKeyGenerator.js +307 -307
  27. package/utils/aws/AWSS3Utils.js +128 -128
  28. package/utils/aws/AWSSMSUtils.js +63 -63
  29. package/utils/aws/AWSSNSBasedEmailDispatcher.js +37 -37
  30. package/utils/aws/AWSSNSBasedSMSDispatcher.js +37 -37
  31. package/utils/aws/AWSSNSUtils.js +38 -38
  32. package/utils/aws/LambdaCommunicationService.js +232 -232
  33. package/utils/enumHelper.js +7 -7
  34. package/utils/thirdparty/URLShorteningService.js +25 -25
  35. package/validation/CoreValidations.js +45 -45
  36. package/validation/FrequencyValidator.js +0 -0
  37. package/validation/SchemaValidation.js +106 -106
package/index.js CHANGED
@@ -1,188 +1,188 @@
1
- 'use strict'
2
-
3
- // This module is one way of exposing subdependencies to dependent modules
4
- // Modules are still `require`d on demand
5
- const fs = require('fs');
6
- const path = require('path');
7
- //const Logger = require('./Logger/index');
8
- const Logger = require('./Logger').getLogger();
9
- const validation = require('./validation/CoreValidations');
10
- const sendResponse = require('./exception/SendResponse');
11
- const CustomException = require('./exception/CustomException');
12
- const SSMConfig = require('./SSMConfig');
13
- const ApplicationContextService = require('./ApplicationContextService');
14
- const schemaValidation = require('./validation/SchemaValidation');
15
- const AWSS3Utils = require('./utils/aws/AWSS3Utils');
16
- const CoreUtils = require('./CoreUtils');
17
- const FrequencyValidator = require('./validation/FrequencyValidator');
18
- const ScheduleCalculationService = require('./ScheduleCalculationService');
19
- const AWSSNSBasedEmailDispatcher = require('./utils/aws/AWSSNSBasedEmailDispatcher');
20
- const AWSSNSBasedSMSDispatcher = require('./utils/aws/AWSSNSBasedSMSDispatcher')
21
- const LambdaCommunicationService = require('./utils/aws/LambdaCommunicationService');
22
- const AWSSNSUtils = require('./utils/aws/AWSSNSUtils');
23
- const AWSAPIKeyGenerator = require('./utils/aws/AWSAPIKeyGenerator');
24
- const AESEncryptionUsingKMS = require('./utils/aws/AESEncryptionUsingKMS');
25
- const AccessInterceptor = require('./utils/AccessInterceptor');
26
- const AWSSMSUtils = require('./utils/aws/AWSSMSUtils');
27
- const HashIds = require('./utils/HashIds');
28
- const modulePath = path.resolve(__dirname, 'node_modules');
29
- const TimeZoneConverter = require('./utils/TimeZoneConverter');
30
- const Internationalization = require('./utils/Internationalization');
31
- const NumberFormatter = require('./utils/NumberFormatter');
32
- const URLShorteningService = require('./utils/thirdparty/URLShorteningService');
33
-
34
-
35
-
36
- try {
37
- console.log('common library initialized*******');
38
- fs.readdirSync(modulePath)
39
- .map(subDir => path.resolve(modulePath, subDir))
40
- .filter(file => fs.statSync(file).isDirectory() && fs.existsSync(path.resolve(file, 'package.json')))
41
- .forEach(moduleDir => {
42
- const moduleName = path.basename(moduleDir)
43
- Object.defineProperty(
44
- module.exports,
45
- moduleName, {
46
- get: () => require(moduleName)
47
- })
48
- })
49
- } catch (error) {
50
- console.error('************index called modulePath error ***********' + error);
51
- }
52
-
53
- module.exports.Logger = Logger
54
- module.exports.CustomException = CustomException;
55
- module.exports.SSMConfig = {
56
- ssmConfig: SSMConfig.ssmConfig
57
- };
58
- module.exports.ApplicationContextService = {
59
- setContextAttributes: ApplicationContextService.setContextAttributes
60
- };
61
-
62
- module.exports.SendResponse = {
63
-
64
- generateErrorResponse: sendResponse.sendErrorMessage,
65
- databaseConnectionError: sendResponse.databaseConnectionError,
66
- dataNotFound: sendResponse.dataNotFound,
67
- errorMessage: sendResponse.errorMessage,
68
- sendData: sendResponse.sendData,
69
- successMessageForPost: sendResponse.successMessageForPost,
70
- successMessage: sendResponse.successMessage,
71
- getAllSuccessMessage: sendResponse.getAllSuccessMessage,
72
- unAuthorizedAccess: sendResponse.unAuthorizedAccess,
73
- validationException: sendResponse.validationException,
74
- merchantInActive: sendResponse.merchantInActive,
75
- invalidMerchant: sendResponse.invalidMerchant,
76
- successOnlyMessage: sendResponse.successOnlyMessage,
77
- internalServerError: sendResponse.internalServerError
78
-
79
- };
80
-
81
- module.exports.Validations = {
82
- generateErrorResponse: validation.generateErrorResponse,
83
- validateRequest: validation.validateRequest
84
- };
85
- module.exports.SchemaValidation = {
86
- validateRequest: schemaValidation.validateRequest
87
- };
88
-
89
-
90
- module.exports.FrequencyValidator = {
91
- isValidFrequency: FrequencyValidator.isValidFrequency
92
- };
93
-
94
- module.exports.ScheduleCalculationService = {
95
- getNextDate: ScheduleCalculationService.getNextDate,
96
- getLastDayOfMonth: ScheduleCalculationService.getLastDayOfMonth
97
-
98
- };
99
-
100
- module.exports.CoreUtils = {
101
- convertUCfirst: CoreUtils.convertUCfirst,
102
- prefixPad: CoreUtils.prefixPad,
103
- getUTCDate: CoreUtils.getUTCDate,
104
- getUTC: CoreUtils.getUTC,
105
- isInputDateTime: CoreUtils.isInputDateTime,
106
- formatSearchToDate: CoreUtils.formatSearchToDate,
107
- isInputDate: CoreUtils.isInputDate
108
- };
109
-
110
-
111
- module.exports.AWSS3Utils = {
112
- getS3File: AWSS3Utils.getS3File,
113
- putS3File: AWSS3Utils.putS3File,
114
- getS3FileStream: AWSS3Utils.getS3FileStream,
115
- deleteS3File: AWSS3Utils.deleteS3File
116
-
117
- };
118
- module.exports.AWSSNSBasedEmailDispatcher = {
119
- dispatchNotification: AWSSNSBasedEmailDispatcher.dispatchNotification
120
- }
121
-
122
- module.exports.AWSSNSBasedSMSDispatcher = {
123
- dispatchNotification: AWSSNSBasedSMSDispatcher.dispatchNotification
124
- }
125
-
126
- module.exports.LambdaCommunicationService = {
127
- invokeAPI: LambdaCommunicationService.invokeAPI,
128
- invokeLambdaAPI: LambdaCommunicationService.invokeLambdaAPI,
129
- generateJWTToken: LambdaCommunicationService.generateJWTToken
130
- }
131
-
132
- module.exports.AWSSNSUtils = {
133
- publish: AWSSNSUtils.publish,
134
- }
135
-
136
- module.exports.AWSAPIKeyGenerator = {
137
- addApiKey: AWSAPIKeyGenerator.addApiKey,
138
- createUsagePlan: AWSAPIKeyGenerator.createUsagePlan,
139
- getApiKey: AWSAPIKeyGenerator.getApiKey,
140
- deleteApiKey: AWSAPIKeyGenerator.deleteApiKey,
141
- createApiKey: AWSAPIKeyGenerator.createApiKey
142
- }
143
-
144
- module.exports.AESEncryptionUsingKMS = {
145
- encrypt: AESEncryptionUsingKMS.encrypt,
146
- decrypt: AESEncryptionUsingKMS.decrypt,
147
-
148
- }
149
-
150
- module.exports.AWSUsagePlanAndApiKey = {
151
- encrypt: AESEncryptionUsingKMS.encrypt,
152
- decrypt: AESEncryptionUsingKMS.decrypt,
153
-
154
- }
155
-
156
- module.exports.AccessInterceptor = {
157
- authorize: AccessInterceptor.authorize
158
- }
159
-
160
- module.exports.HashIds = {
161
- hashResponse: HashIds.hashResponse,
162
- unHashRequest: HashIds.unHashRequest
163
- }
164
-
165
-
166
- module.exports.TimeZoneConverter = {
167
- timeZoneConvert: TimeZoneConverter.timeZoneConvert
168
- }
169
- module.exports.NumberFormatter = {
170
- format: NumberFormatter.format
171
- }
172
-
173
-
174
- module.exports.AWSSMSUtils = {
175
- sendSMS: AWSSMSUtils.sendSMS
176
- }
177
-
178
-
179
- module.exports.Internationalization = {
180
- FormatCurrency: Internationalization.FormatCurrency,
181
- FormatDate: Internationalization.FormatDate,
182
- FormatDateTime: Internationalization.FormatDateTime
183
-
184
- }
185
-
186
- module.exports.URLShorteningService = {
187
- shortenURL: URLShorteningService.shortenURL
1
+ 'use strict'
2
+
3
+ // This module is one way of exposing subdependencies to dependent modules
4
+ // Modules are still `require`d on demand
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ //const Logger = require('./Logger/index');
8
+ const Logger = require('./Logger').getLogger();
9
+ const validation = require('./validation/CoreValidations');
10
+ const sendResponse = require('./exception/SendResponse');
11
+ const CustomException = require('./exception/CustomException');
12
+ const SSMConfig = require('./SSMConfig');
13
+ const ApplicationContextService = require('./ApplicationContextService');
14
+ const schemaValidation = require('./validation/SchemaValidation');
15
+ const AWSS3Utils = require('./utils/aws/AWSS3Utils');
16
+ const CoreUtils = require('./CoreUtils');
17
+ const FrequencyValidator = require('./validation/FrequencyValidator');
18
+ const ScheduleCalculationService = require('./ScheduleCalculationService');
19
+ const AWSSNSBasedEmailDispatcher = require('./utils/aws/AWSSNSBasedEmailDispatcher');
20
+ const AWSSNSBasedSMSDispatcher = require('./utils/aws/AWSSNSBasedSMSDispatcher')
21
+ const LambdaCommunicationService = require('./utils/aws/LambdaCommunicationService');
22
+ const AWSSNSUtils = require('./utils/aws/AWSSNSUtils');
23
+ const AWSAPIKeyGenerator = require('./utils/aws/AWSAPIKeyGenerator');
24
+ const AESEncryptionUsingKMS = require('./utils/aws/AESEncryptionUsingKMS');
25
+ const AccessInterceptor = require('./utils/AccessInterceptor');
26
+ const AWSSMSUtils = require('./utils/aws/AWSSMSUtils');
27
+ const HashIds = require('./utils/HashIds');
28
+ const modulePath = path.resolve(__dirname, 'node_modules');
29
+ const TimeZoneConverter = require('./utils/TimeZoneConverter');
30
+ const Internationalization = require('./utils/Internationalization');
31
+ const NumberFormatter = require('./utils/NumberFormatter');
32
+ const URLShorteningService = require('./utils/thirdparty/URLShorteningService');
33
+
34
+
35
+
36
+ try {
37
+ console.log('common library initialized*******');
38
+ fs.readdirSync(modulePath)
39
+ .map(subDir => path.resolve(modulePath, subDir))
40
+ .filter(file => fs.statSync(file).isDirectory() && fs.existsSync(path.resolve(file, 'package.json')))
41
+ .forEach(moduleDir => {
42
+ const moduleName = path.basename(moduleDir)
43
+ Object.defineProperty(
44
+ module.exports,
45
+ moduleName, {
46
+ get: () => require(moduleName)
47
+ })
48
+ })
49
+ } catch (error) {
50
+ console.error('************index called modulePath error ***********' + error);
51
+ }
52
+
53
+ module.exports.Logger = Logger
54
+ module.exports.CustomException = CustomException;
55
+ module.exports.SSMConfig = {
56
+ ssmConfig: SSMConfig.ssmConfig
57
+ };
58
+ module.exports.ApplicationContextService = {
59
+ setContextAttributes: ApplicationContextService.setContextAttributes
60
+ };
61
+
62
+ module.exports.SendResponse = {
63
+
64
+ generateErrorResponse: sendResponse.sendErrorMessage,
65
+ databaseConnectionError: sendResponse.databaseConnectionError,
66
+ dataNotFound: sendResponse.dataNotFound,
67
+ errorMessage: sendResponse.errorMessage,
68
+ sendData: sendResponse.sendData,
69
+ successMessageForPost: sendResponse.successMessageForPost,
70
+ successMessage: sendResponse.successMessage,
71
+ getAllSuccessMessage: sendResponse.getAllSuccessMessage,
72
+ unAuthorizedAccess: sendResponse.unAuthorizedAccess,
73
+ validationException: sendResponse.validationException,
74
+ merchantInActive: sendResponse.merchantInActive,
75
+ invalidMerchant: sendResponse.invalidMerchant,
76
+ successOnlyMessage: sendResponse.successOnlyMessage,
77
+ internalServerError: sendResponse.internalServerError
78
+
79
+ };
80
+
81
+ module.exports.Validations = {
82
+ generateErrorResponse: validation.generateErrorResponse,
83
+ validateRequest: validation.validateRequest
84
+ };
85
+ module.exports.SchemaValidation = {
86
+ validateRequest: schemaValidation.validateRequest
87
+ };
88
+
89
+
90
+ module.exports.FrequencyValidator = {
91
+ isValidFrequency: FrequencyValidator.isValidFrequency
92
+ };
93
+
94
+ module.exports.ScheduleCalculationService = {
95
+ getNextDate: ScheduleCalculationService.getNextDate,
96
+ getLastDayOfMonth: ScheduleCalculationService.getLastDayOfMonth
97
+
98
+ };
99
+
100
+ module.exports.CoreUtils = {
101
+ convertUCfirst: CoreUtils.convertUCfirst,
102
+ prefixPad: CoreUtils.prefixPad,
103
+ getUTCDate: CoreUtils.getUTCDate,
104
+ getUTC: CoreUtils.getUTC,
105
+ isInputDateTime: CoreUtils.isInputDateTime,
106
+ formatSearchToDate: CoreUtils.formatSearchToDate,
107
+ isInputDate: CoreUtils.isInputDate
108
+ };
109
+
110
+
111
+ module.exports.AWSS3Utils = {
112
+ getS3File: AWSS3Utils.getS3File,
113
+ putS3File: AWSS3Utils.putS3File,
114
+ getS3FileStream: AWSS3Utils.getS3FileStream,
115
+ deleteS3File: AWSS3Utils.deleteS3File
116
+
117
+ };
118
+ module.exports.AWSSNSBasedEmailDispatcher = {
119
+ dispatchNotification: AWSSNSBasedEmailDispatcher.dispatchNotification
120
+ }
121
+
122
+ module.exports.AWSSNSBasedSMSDispatcher = {
123
+ dispatchNotification: AWSSNSBasedSMSDispatcher.dispatchNotification
124
+ }
125
+
126
+ module.exports.LambdaCommunicationService = {
127
+ invokeAPI: LambdaCommunicationService.invokeAPI,
128
+ invokeLambdaAPI: LambdaCommunicationService.invokeLambdaAPI,
129
+ generateJWTToken: LambdaCommunicationService.generateJWTToken
130
+ }
131
+
132
+ module.exports.AWSSNSUtils = {
133
+ publish: AWSSNSUtils.publish,
134
+ }
135
+
136
+ module.exports.AWSAPIKeyGenerator = {
137
+ addApiKey: AWSAPIKeyGenerator.addApiKey,
138
+ createUsagePlan: AWSAPIKeyGenerator.createUsagePlan,
139
+ getApiKey: AWSAPIKeyGenerator.getApiKey,
140
+ deleteApiKey: AWSAPIKeyGenerator.deleteApiKey,
141
+ createApiKey: AWSAPIKeyGenerator.createApiKey
142
+ }
143
+
144
+ module.exports.AESEncryptionUsingKMS = {
145
+ encrypt: AESEncryptionUsingKMS.encrypt,
146
+ decrypt: AESEncryptionUsingKMS.decrypt,
147
+
148
+ }
149
+
150
+ module.exports.AWSUsagePlanAndApiKey = {
151
+ encrypt: AESEncryptionUsingKMS.encrypt,
152
+ decrypt: AESEncryptionUsingKMS.decrypt,
153
+
154
+ }
155
+
156
+ module.exports.AccessInterceptor = {
157
+ authorize: AccessInterceptor.authorize
158
+ }
159
+
160
+ module.exports.HashIds = {
161
+ hashResponse: HashIds.hashResponse,
162
+ unHashRequest: HashIds.unHashRequest
163
+ }
164
+
165
+
166
+ module.exports.TimeZoneConverter = {
167
+ timeZoneConvert: TimeZoneConverter.timeZoneConvert
168
+ }
169
+ module.exports.NumberFormatter = {
170
+ format: NumberFormatter.format
171
+ }
172
+
173
+
174
+ module.exports.AWSSMSUtils = {
175
+ sendSMS: AWSSMSUtils.sendSMS
176
+ }
177
+
178
+
179
+ module.exports.Internationalization = {
180
+ FormatCurrency: Internationalization.FormatCurrency,
181
+ FormatDate: Internationalization.FormatDate,
182
+ FormatDateTime: Internationalization.FormatDateTime
183
+
184
+ }
185
+
186
+ module.exports.URLShorteningService = {
187
+ shortenURL: URLShorteningService.shortenURL
188
188
  };
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "apf-node-common",
3
- "version": "1.0.109",
4
- "description": "",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "author": "",
10
- "license": "ISC",
11
- "dependencies": {
12
- "ajv": "^6.10.2",
13
- "ajv-errors": "^1.0.1",
14
- "ajv-keywords": "^3.4.1",
15
- "axios": "^0.21.1",
16
- "basic": "^2.0.3",
17
- "camelcase-keys": "^6.1.1",
18
- "express-http-context": "^1.2.3",
19
- "fastest-validator": "^0.6.17",
20
- "jsonwebtoken": "^8.5.1",
21
- "moment": "^2.24.0",
22
- "moment-timezone": "^0.5.27",
23
- "path-to-regexp": "^6.1.0",
24
- "swagger-jsdoc": "^3.4.0",
25
- "winston": "^3.2.1",
26
- "winston-aws-cloudwatch": "^3.0.0",
27
- "winston-daily-rotate-file": "^4.5.0"
28
- }
29
- }
1
+ {
2
+ "name": "apf-node-common",
3
+ "version": "1.0.110",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "ajv": "^6.10.2",
13
+ "ajv-errors": "^1.0.1",
14
+ "ajv-keywords": "^3.4.1",
15
+ "axios": "^0.21.1",
16
+ "basic": "^2.0.3",
17
+ "camelcase-keys": "^6.1.1",
18
+ "express-http-context": "^1.2.3",
19
+ "fastest-validator": "^0.6.17",
20
+ "jsonwebtoken": "^8.5.1",
21
+ "moment": "^2.24.0",
22
+ "moment-timezone": "^0.5.27",
23
+ "path-to-regexp": "^6.1.0",
24
+ "swagger-jsdoc": "^3.4.0",
25
+ "winston": "^3.2.1",
26
+ "winston-aws-cloudwatch": "^3.0.0",
27
+ "winston-daily-rotate-file": "^4.5.0"
28
+ }
29
+ }
@@ -1,94 +1,94 @@
1
- var expect = require('chai').expect;
2
-
3
- const AWSUtility = require('../utils/AWSS3Utils');
4
-
5
- describe("AWSUtility Testing", function () {
6
-
7
-
8
- it('should get s3 file content', async function () {
9
-
10
- // use await to wait until the promise is fulfilled
11
- return AWSUtility.getS3File('hpgimages', 'hello.html')
12
- .then((file)=>{
13
- expect(file).to.be.a('string');
14
- })
15
-
16
- // .that.matches(/^[a-z]$/)
17
- // .and.equal('Hello world');
18
- }),
19
- it('should get error in case of undefined bucket name', async function () {
20
- var file = await AWSUtility.getS3File(undefined, 'hello.html')
21
- .then((file)=>{
22
- console.log('test')
23
- })
24
- .catch(function (error) {
25
- expect(function () { throw error }).to.throw(Error, 'bucket name is invalid');
26
- });
27
- }),
28
- it('should get error in case of undefined bucket name', async function () {
29
- AWSUtility.getS3File('hpgimages', undefined)
30
- .catch(function (error) {
31
- expect(function () { throw error })
32
- .to.throw(Error, 'file name is invalid');
33
- });
34
- }),
35
- it('should get error in case of invalid bucket name', async function () {
36
- AWSUtility.getS3File('hpgimageds', 'hhgh')
37
- .catch(function (error) {
38
- expect(function () { throw error })
39
- .to.throw(Error, 'The specified bucket does not exist');
40
- });
41
- }),
42
- it('should get error in case of invalid file name', async function () {
43
- await AWSUtility.getS3File('hpgimages', 'hhgh')
44
- .catch(function (error) {
45
- expect(function () { throw error })
46
- .to.throw(Error, 'The specified key does not exist');
47
- });
48
- }),
49
- it('should upload content to s3 - put', async function () {
50
- var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
51
- AWSUtility.putS3File('hpgimages', 'testput.html',file)
52
- .then((response)=>{
53
- console.log('response - '+ response)
54
- expect(response).to.be.a('string')
55
- })
56
-
57
- }),
58
- it('should get error in case of undefined bucket name - put', async function () {
59
- var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
60
- await AWSUtility.putS3File(undefined,'hpgimages',file)
61
- .catch(function (error) {
62
- expect(function () { throw error })
63
- .to.throw(Error, 'bucket name is invalid');
64
- });
65
- }),
66
- it('should get error in case of undefined file name - put', async function () {
67
- var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
68
- await AWSUtility.putS3File('hpgimages', undefined,file)
69
-
70
- .catch(function (error) {
71
- expect(function () { throw error })
72
- .to.throw(Error, 'file name is invalid');
73
- });
74
- }),
75
- it('should get error in case of invalid file name - put', async function () {
76
- var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
77
- AWSUtility.putS3File('hpgimages', 'ooo', undefined)
78
- .catch(function (error) {
79
- expect(function () { throw error })
80
- .to.throw(Error, 'content is invalid');
81
- });
82
- }),
83
- it('should get error in case of invalid bucket name - put', async function () {
84
- var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
85
- await AWSUtility.putS3File('xyz', 'hello.html', file)
86
- .catch(function (error) {
87
- expect(function () { throw error })
88
- .to.throw(Error, 'The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.');
89
- })
90
-
91
- })
92
- })
93
-
94
-
1
+ var expect = require('chai').expect;
2
+
3
+ const AWSUtility = require('../utils/AWSS3Utils');
4
+
5
+ describe("AWSUtility Testing", function () {
6
+
7
+
8
+ it('should get s3 file content', async function () {
9
+
10
+ // use await to wait until the promise is fulfilled
11
+ return AWSUtility.getS3File('hpgimages', 'hello.html')
12
+ .then((file)=>{
13
+ expect(file).to.be.a('string');
14
+ })
15
+
16
+ // .that.matches(/^[a-z]$/)
17
+ // .and.equal('Hello world');
18
+ }),
19
+ it('should get error in case of undefined bucket name', async function () {
20
+ var file = await AWSUtility.getS3File(undefined, 'hello.html')
21
+ .then((file)=>{
22
+ console.log('test')
23
+ })
24
+ .catch(function (error) {
25
+ expect(function () { throw error }).to.throw(Error, 'bucket name is invalid');
26
+ });
27
+ }),
28
+ it('should get error in case of undefined bucket name', async function () {
29
+ AWSUtility.getS3File('hpgimages', undefined)
30
+ .catch(function (error) {
31
+ expect(function () { throw error })
32
+ .to.throw(Error, 'file name is invalid');
33
+ });
34
+ }),
35
+ it('should get error in case of invalid bucket name', async function () {
36
+ AWSUtility.getS3File('hpgimageds', 'hhgh')
37
+ .catch(function (error) {
38
+ expect(function () { throw error })
39
+ .to.throw(Error, 'The specified bucket does not exist');
40
+ });
41
+ }),
42
+ it('should get error in case of invalid file name', async function () {
43
+ await AWSUtility.getS3File('hpgimages', 'hhgh')
44
+ .catch(function (error) {
45
+ expect(function () { throw error })
46
+ .to.throw(Error, 'The specified key does not exist');
47
+ });
48
+ }),
49
+ it('should upload content to s3 - put', async function () {
50
+ var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
51
+ AWSUtility.putS3File('hpgimages', 'testput.html',file)
52
+ .then((response)=>{
53
+ console.log('response - '+ response)
54
+ expect(response).to.be.a('string')
55
+ })
56
+
57
+ }),
58
+ it('should get error in case of undefined bucket name - put', async function () {
59
+ var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
60
+ await AWSUtility.putS3File(undefined,'hpgimages',file)
61
+ .catch(function (error) {
62
+ expect(function () { throw error })
63
+ .to.throw(Error, 'bucket name is invalid');
64
+ });
65
+ }),
66
+ it('should get error in case of undefined file name - put', async function () {
67
+ var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
68
+ await AWSUtility.putS3File('hpgimages', undefined,file)
69
+
70
+ .catch(function (error) {
71
+ expect(function () { throw error })
72
+ .to.throw(Error, 'file name is invalid');
73
+ });
74
+ }),
75
+ it('should get error in case of invalid file name - put', async function () {
76
+ var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
77
+ AWSUtility.putS3File('hpgimages', 'ooo', undefined)
78
+ .catch(function (error) {
79
+ expect(function () { throw error })
80
+ .to.throw(Error, 'content is invalid');
81
+ });
82
+ }),
83
+ it('should get error in case of invalid bucket name - put', async function () {
84
+ var file = await AWSUtility.getS3File('hpgimages', 'hello.html');
85
+ await AWSUtility.putS3File('xyz', 'hello.html', file)
86
+ .catch(function (error) {
87
+ expect(function () { throw error })
88
+ .to.throw(Error, 'The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.');
89
+ })
90
+
91
+ })
92
+ })
93
+
94
+
File without changes