Skip to content

Commit

Permalink
Merge pull request #8 from peoray/update-message-test
Browse files Browse the repository at this point in the history
  • Loading branch information
peoray authored Aug 31, 2023
2 parents d0b8749 + 742b1fb commit e4e24bb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_KEY=
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@types/jest": "^29.5.3",
"@types/node": "^20.4.8",
"class-validator": "^0.14.0",
"dotenv": "^16.3.1",
"jest": "^29.6.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Message } from '../../src/services'
import { Message } from './message'
import {
ISendBulkMessage,
ISendMessage,
ISendMessageResponse,
} from '../../src/types'
} from '../../types'
import { keys } from '../../utils/env'

const message = new Message(keys[0])

const message = new Message(
'TLaURAdBvnUNS9sEbugcE2gyRdKd1rNPSVxAG3fQp9sfbtpVh6575KoTon2Fv9'
)
const mockMessage: ISendMessage = {
to: '+2348012345678',
sms: 'Hello World',
Expand Down
34 changes: 34 additions & 0 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as path from 'path'
import { config } from 'dotenv'

// Parsing the env file from the root directory of the project
config({ path: path.join(__dirname, '../../.env') })

interface ENV {
API_KEY: string | undefined
}

interface Config {
API_KEY: string
}

const getConfig = (): ENV => {
return {
API_KEY: process.env.API_KEY,
}
}

const getSanitzedConfig = (configSys: ENV): Config => {
for (const [key, value] of Object.entries(configSys)) {
if (value === undefined) {
throw new Error(`Missing key ${key} in .env`)
}
}
return configSys as Config
}

const configSys = getConfig()

const sanitizedConfig = getSanitzedConfig(configSys)

export const keys = [sanitizedConfig.API_KEY]

0 comments on commit e4e24bb

Please sign in to comment.