From 7343d9996b980c9dfedf430d7caba6fdc6c64050 Mon Sep 17 00:00:00 2001 From: J2EEbbesen Date: Wed, 29 Nov 2023 21:36:58 -0600 Subject: [PATCH] Better config (#62) * configurable bucket name * more tests * adding BUCKET_NAME to CircleCI config --- .circleci/config.yml | 4 +++- README.md | 6 +++-- package-lock.json | 46 ++++++++++++++++++++++++++---------- package.json | 5 ++-- scripts/package.sh | 6 ++--- src/app.ts | 4 +++- src/bucketUtils.ts | 11 +++++---- src/pollyUtils.ts | 3 ++- src/utils.ts | 8 +++++++ test/app.test.ts | 4 ++-- test/bucketUtils.test.ts | 5 ++-- test/comprehendUtils.test.ts | 4 ++-- test/pollyUtils.test.ts | 2 +- test/safeUtils.test.ts | 27 +++++++++++++++++++++ uploaded/.keep | 0 15 files changed, 101 insertions(+), 34 deletions(-) delete mode 100644 uploaded/.keep diff --git a/.circleci/config.yml b/.circleci/config.yml index ad30979..6a09415 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,5 +9,7 @@ jobs: - node/install-packages: pkg-manager: npm - run: - command: npm run test + command: | + BUCKET_NAME="eulagy" + npm run test name: Run tests diff --git a/README.md b/README.md index 3468efb..7aa5342 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ EULAgy is a utility that can be plugged into an application that will stream an And (shhhh, don't tell) EULAgy will work for _any_ text file, not just EULAs :). - * EULAgy uses Amazon Polly to create an mp3 from EULA text * EULAgy uses Amazon Comprehend to create a csv from EULA text * EULAgy is designed to work on AWS Lambda, but can also be run from the command line @@ -20,13 +19,16 @@ And (shhhh, don't tell) EULAgy will work for _any_ text file, not just EULAs :). *In particular, code changes are required to remove hard-coded `eulagy` bucket name throughout the application!* ## Using +### Environment variables +EULAgy requires a populated `BUCKET_NAME` environment variable for tests and production + ### AWS Lambda See Deploy below. Place txt files in the root S3 bucket -- output will appear in the `uploaded` folder of the S3 bucket. ## Develop 1. [Install npm](https://www.npmjs.com/get-npm) 1. `npm install` -1. `npm test` to validate setup! +1. `npm test` to validate setup! 1. `npm run liveTest` to run tests that actually hit S3 * requires configured AWS CLI setup on box running tests -- (You'll need to have AWS credentials created, e.g., https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) * will incur AWS charges (up to several cents per full suite run in the cheapest AWS region) diff --git a/package-lock.json b/package-lock.json index 8928a24..4d2172f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@aws-sdk/client-polly": ">=3.454.0", "@aws-sdk/client-s3": ">=3.456.0", "@types/aws-lambda": ">=8.10.129", + "@types/node": "^20.10.1", "debug": "4.3.4", "minimatch": ">=3.12", "ms": "2.1.2", @@ -2957,7 +2958,6 @@ "version": "20.10.1", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.1.tgz", "integrity": "sha512-T2qwhjWwGH81vUEx4EXmBKsTJRXFXNZTL4v0gi01+zyBmCwzE6TyHszqX01m+QHTEq+EZNo13NeJIdEqf+Myrg==", - "dev": true, "dependencies": { "undici-types": "~5.26.4" } @@ -3261,6 +3261,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, "engines": { "node": ">=8" } @@ -3809,7 +3810,8 @@ "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true }, "node_modules/convert-source-map": { "version": "2.0.0", @@ -4784,7 +4786,8 @@ "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true }, "node_modules/fsevents": { "version": "2.3.3", @@ -4922,6 +4925,7 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -4953,6 +4957,7 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4962,6 +4967,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, "dependencies": { "brace-expansion": "^1.1.7" }, @@ -5034,7 +5040,8 @@ "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true }, "node_modules/graphemer": { "version": "1.4.0", @@ -5186,6 +5193,7 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true, "engines": { "node": ">=0.8.19" } @@ -5194,6 +5202,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dev": true, "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -5202,7 +5211,8 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, "node_modules/internal-slot": { "version": "1.0.6", @@ -5510,7 +5520,8 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true }, "node_modules/istanbul-lib-coverage": { "version": "3.2.2", @@ -8899,6 +8910,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, "dependencies": { "wrappy": "1" } @@ -9017,6 +9029,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -9340,6 +9353,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, "dependencies": { "glob": "^7.1.3" }, @@ -9409,6 +9423,7 @@ "version": "7.5.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, "dependencies": { "lru-cache": "^6.0.0" }, @@ -9423,6 +9438,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, "dependencies": { "yallist": "^4.0.0" }, @@ -9433,7 +9449,8 @@ "node_modules/semver/node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true }, "node_modules/set-function-length": { "version": "1.1.1", @@ -9502,7 +9519,8 @@ "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "dev": true }, "node_modules/sisteransi": { "version": "1.0.5", @@ -9641,6 +9659,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -9746,7 +9765,8 @@ "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==" + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "dev": true }, "node_modules/tmpl": { "version": "1.0.5", @@ -10053,8 +10073,7 @@ "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" }, "node_modules/update-browserslist-db": { "version": "1.0.13", @@ -10136,6 +10155,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, "dependencies": { "isexe": "^2.0.0" }, @@ -10201,12 +10221,14 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true }, "node_modules/write-file-atomic": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-4.0.2.tgz", "integrity": "sha512-7KxauUdBmSdWnmpaGFg+ppNjKF8uNLry8LyzjauQDOVONfFLNKrKvQOxZ/VuTIcS/gge/YNahf5RIIQWTSarlg==", + "dev": true, "dependencies": { "imurmurhash": "^0.1.4", "signal-exit": "^3.0.7" diff --git a/package.json b/package.json index 580941a..83f68ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eulagy", - "version": "3.2.1", + "version": "3.2.2", "description": "EULAgy takes a text file, converts it to an mp3 and generates a csv based on the Amazon Comprehend findings", "main": "src/app.ts", "scripts": { @@ -30,6 +30,7 @@ "@aws-sdk/client-polly": ">=3.454.0", "@aws-sdk/client-s3": ">=3.456.0", "@types/aws-lambda": ">=8.10.129", + "@types/node": "^20.10.1", "debug": "4.3.4", "minimatch": ">=3.12", "ms": "2.1.2", @@ -49,4 +50,4 @@ "url": "https://github.com/eebbesen/eulagy/issues" }, "homepage": "https://github.com/eebbesen/eulagy#readme" -} \ No newline at end of file +} diff --git a/scripts/package.sh b/scripts/package.sh index 1367245..ada8835 100644 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -1,14 +1,14 @@ #!/bin/bash set -e -setopt localoptions rmstarsilent +# setopt localoptions rmstarsilent # not bash, but you need to run if you zsh echo 'removing node_modules' -rm -rf node_modules/* +rm -rf node_modules/* echo 'done clearing node_modules' echo 'npm install --omit=dev' -npm install --omit=dev +npm install --omit=dev echo 'running tsc to generate .js files for prod only' rm -rf distProd/* diff --git a/src/app.ts b/src/app.ts index d0512b5..19c9b1c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -6,13 +6,15 @@ import { type StartSpeechSynthesisTaskCommandOutput } from '@aws-sdk/client-poll import { type DeleteObjectCommandOutput, type GetObjectCommandOutput, type PutObjectCommandOutput } from '@aws-sdk/client-s3' import { type DetectKeyPhrasesCommandOutput } from '@aws-sdk/client-comprehend' import { type S3Event } from 'aws-lambda' - import { log4TSProvider } from './config/LogConfig' const log = log4TSProvider.getLogger('App') export async function handler (event: S3Event): Promise { log.info('incoming event', JSON.stringify(event)) + + Utils.bucketProperty() // check early since program need this + const rec: S3Event['Records'] = event.Records const fileName: string = rec[0].s3.object.key log.info('processing file', fileName) diff --git a/src/bucketUtils.ts b/src/bucketUtils.ts index f8dc27e..3545da8 100644 --- a/src/bucketUtils.ts +++ b/src/bucketUtils.ts @@ -12,6 +12,7 @@ import { PutObjectCommand, type PutObjectCommandOutput } from '@aws-sdk/client-s3' +import * as Utils from './utils' import { log4TSProvider } from './config/LogConfig' const log = log4TSProvider.getLogger('BucketUtils') @@ -22,7 +23,7 @@ export async function listBuckets (): Promise { }; export function createBucket (name: string): void { - const bucketName = (name.length > 0) ? name : 'eulagy' + const bucketName = (name.length > 0) ? name : Utils.bucketProperty() listBuckets() .then(bs => { @@ -47,24 +48,24 @@ export function createBucket (name: string): void { // lists files in S3 bucket export async function listBucketFiles (name: string): Promise { - const bucketName = (name.length > 0) ? name : 'eulagy' + const bucketName = (name.length > 0) ? name : Utils.bucketProperty() const listObjectsCommand = new ListObjectsCommand({ Bucket: bucketName }) return await client.send(listObjectsCommand) }; export async function downloadFile (name: string): Promise { - const getObjectCommand = new GetObjectCommand({ Bucket: 'eulagy', Key: name, RequestPayer: 'requester' }) + const getObjectCommand = new GetObjectCommand({ Bucket: Utils.bucketProperty(), Key: name, RequestPayer: 'requester' }) return await client.send(getObjectCommand) } export async function deleteFile (name: string): Promise { - const deleteObjectCommand = new DeleteObjectCommand({ Bucket: 'eulagy', Key: name }) + const deleteObjectCommand = new DeleteObjectCommand({ Bucket: Utils.bucketProperty(), Key: name }) return await client.send(deleteObjectCommand) }; // uploads one file to S3 bucket export async function uploadFile (name: string, data: string): Promise { log.debug(`file ${name} size is ${data.length}`) - const putObjectCommand = new PutObjectCommand({ Bucket: 'eulagy', Key: name, Body: data, ContentLength: data.length }) + const putObjectCommand = new PutObjectCommand({ Bucket: Utils.bucketProperty(), Key: name, Body: data, ContentLength: data.length }) return await client.send(putObjectCommand) } diff --git a/src/pollyUtils.ts b/src/pollyUtils.ts index c3868e4..f148879 100644 --- a/src/pollyUtils.ts +++ b/src/pollyUtils.ts @@ -3,6 +3,7 @@ import { StartSpeechSynthesisTaskCommand, type StartSpeechSynthesisTaskCommandOutput } from '@aws-sdk/client-polly' +import * as Utils from './utils' const pollyClient = new PollyClient({}) @@ -28,7 +29,7 @@ export async function startSynthesizeSpeech (text: RegExpMatchArray): Promise { .then(async (ret: any) => { log.debug('After upload', JSON.stringify(ret)) expect(ret?.$metadata?.httpStatusCode).toEqual(200) - return await S3Helper.listBucketFiles('eulagy') + return await S3Helper.listBucketFiles(Utils.bucketProperty()) }) .then(async (ret: any) => { log.debug('After upload list files', JSON.stringify(ret)) @@ -48,7 +49,7 @@ describe('uploadFile, listBucketFiles, downloadFile, and deleteFile', () => { .then(async (ret: any) => { log.debug('After delete', JSON.stringify(ret)) expect(ret?.$metadata?.httpStatusCode).toEqual(204) - return await S3Helper.listBucketFiles('eulagy') + return await S3Helper.listBucketFiles(Utils.bucketProperty()) }) .then((ret: any) => { log.debug('After delete list files', JSON.stringify(ret)) diff --git a/test/comprehendUtils.test.ts b/test/comprehendUtils.test.ts index 98eb2c1..db217d8 100644 --- a/test/comprehendUtils.test.ts +++ b/test/comprehendUtils.test.ts @@ -39,7 +39,7 @@ describe('detectSentiment', () => { it('throws error when no text', async () => { await extractChunks('test/files/empty.txt') .then((chunks: RegExpMatchArray) => { - void expect(async () => await ComprehendUtils.detectSentiment(chunks)).rejects.toThrow('Empty text') + expect(async () => await ComprehendUtils.detectSentiment(chunks)).rejects.toThrow('Empty text') }) }) }) @@ -58,7 +58,7 @@ describe('keyPhrases', () => { it('throws error when no text', async () => { await extractChunks('test/files/empty.txt') .then(async (chunks: RegExpMatchArray) => { - void expect(async () => await ComprehendUtils.detectKeyPhrases(chunks)).rejects.toThrow('Empty text') + expect(async () => await ComprehendUtils.detectKeyPhrases(chunks)).rejects.toThrow('Empty text') }) }) }) diff --git a/test/pollyUtils.test.ts b/test/pollyUtils.test.ts index b75da84..bd3c8a3 100644 --- a/test/pollyUtils.test.ts +++ b/test/pollyUtils.test.ts @@ -22,6 +22,6 @@ describe('startSynthesizeSpeech', () => { it('throws error when no text', async () => { const chunks: any = 'bcd'.match(/[a]{1,2999}/g) - void expect(async () => await PollyUtils.startSynthesizeSpeech(chunks)).rejects.toThrow('No text') + expect(async () => await PollyUtils.startSynthesizeSpeech(chunks)).rejects.toThrow('No text') }) }) diff --git a/test/safeUtils.test.ts b/test/safeUtils.test.ts index b0107b2..bc82c5d 100644 --- a/test/safeUtils.test.ts +++ b/test/safeUtils.test.ts @@ -71,3 +71,30 @@ describe('chunkText', () => { expect(() => Utils.chunkText('', 1)).toThrow('No text extracted') }) }) + +describe('bucketProperty', () => { + const originalProcessEnv = process.env + afterEach(() => { process.env = originalProcessEnv }) + + it('throws error when empty BUCKET_NAME', () => { + process.env = { ...process.env, BUCKET_NAME: '' } + expect(() => Utils.bucketProperty()).toThrow('No bucket name specified. BUCKET_NAME environment variable required.') + }) + + it('throws error when null BUCKET_NAME', () => { + let undefinedVal + process.env = { ...process.env, BUCKET_NAME: undefinedVal } + expect(() => Utils.bucketProperty()).toThrow('No bucket name specified. BUCKET_NAME environment variable required.') + }) + + it('throws error when no BUCKET_NAME key', () => { + delete process.env.BUCKET_NAME + expect(() => Utils.bucketProperty()).toThrow('No bucket name specified. BUCKET_NAME environment variable required.') + }) + + it('accepts populated value', () => { + process.env = { ...process.env, BUCKET_NAME: 'someval' } + Utils.bucketProperty() + }) + +}) diff --git a/uploaded/.keep b/uploaded/.keep deleted file mode 100644 index e69de29..0000000