Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NOC-1903): Unit testing and API testing with jest + supertest #7

Merged
merged 16 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
PORT=3000
NGINX_PORT=80

INTERCOM_API_KEY=YOUR_INTERCOM_API_KEY
OPEN_WEATHER_MAP_API_KEY=YOUR_OPEN_WEATHER_MAP_API_KEY
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
TELNYX_API_KEY=YOUR_TELNYX_API_KEY

Expand All @@ -7,10 +11,6 @@ POSTGRES_PORT=5432
POSTGRES_USER=ai_chatbot
POSTGRES_DATABASE=ai_chatbot
POSTGRES_PASSWORD=postgres

POSTGRES_DEV_PORT=25432

NGINX_PORT=80
API_PORT=3000

LOCAL=true
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
'plugin:jsx-a11y/recommended',
'prettier',
'plugin:prettier/recommended',
'plugin:jest/recommended',
],
rules: {
indent: 0,
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:19.8.1
FROM node:20.9.0

# set working directory
WORKDIR /src/app
Expand All @@ -12,7 +12,7 @@ RUN yarn
COPY . ./

# compile backend ts into js
RUN yarn run build:backend
RUN yarn run build

# make the entrypoint script executable
RUN chmod +x entrypoint.sh
Expand Down
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tag := red
service := ai-chatbot
port := 3000

main_image := registry.internal.telnyx.com/jenkins/$(service):$(tag)
main_image := $(service):$(tag)
node_version := 19.8.1

docker_build_args = \
Expand All @@ -17,10 +17,18 @@ docker_build_args = \
build:
docker build $(docker_build_args) --tag $(main_image) .

.PHONY:
.PHONY: start
start:
docker run -d -p $(port):$(port) $(main_image)
docker compose up -d

.PHONY: stop
stop:
docker compose down

.PHONY: startdev
startdev:
docker compose -f docker-compose.yml up -d

.PHONY: test
test:
$(info ************ NO TESTING YET ************)
yarn run test
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
env_file:
- .env
ports:
- '${API_PORT}:${API_PORT}'
- '${PORT}:${PORT}'
depends_on:
- postgres
networks:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
env_file:
- .env
expose:
- '${API_PORT}'
- '${PORT}'
depends_on:
- postgres
networks:
Expand Down
2 changes: 1 addition & 1 deletion infra/nginx/templates/api.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ server {
server_name _;

location / {
proxy_pass http://api:${API_PORT}/;
proxy_pass http://api:${PORT}/;
proxy_set_header X-Request-Id $request_id;
}
}
5 changes: 5 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
113 changes: 17 additions & 96 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,155 +1,76 @@
{
"name": "ai-chatbot",
"version": "0.0.1",
"description": "A service for the NOC AI Chat Bot.",
"description": "A NodeJS backend with the essential building block components to develop robust chatbots powered by AI, utilizing Telnyx Inference and Storage API Products.",
"main": "server/server.ts",
"type": "module",
"scripts": {
"dev:backend": "tsc-watch --project ./server --outDir ./app --onSuccess \"node ./app/server.js\"",
"dev:frontend": "webpack serve --progress --config webpack/webpack.config.cjs --env env=dev",
"dev:build:frontend": "webpack --config webpack/webpack.config.cjs --env env=dev",
"build:frontend": "webpack --config webpack/webpack.config.cjs --env env=prod",
"build:backend": "tsc --project ./server/tsconfig.json",
"build:fr": "tsc --project ./src/tsconfig.json --traceResolution",
"build": "tsc --project ./server/tsconfig.json",
"server": "node ./app/server.js",
"lint": "eslint --fix \"./src/**/*.{js,jsx,ts,tsx,json}\"",
"format": "prettier --write \"./src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
"embeddings": "tsx server/handlers/embeddings/devdocs.ts"
"dev:backend": "tsc-watch --project ./server --outDir ./app --onSuccess \"node ./app/server.js\"",
"test": "yarn node --no-warnings --experimental-vm-modules $(yarn bin jest) --config jest.config.cjs ./app/__tests__",
"test:debug": "DEBUG=jest yarn node --experimental-vm-modules $(yarn bin jest) --config jest.config.cjs ./app/__tests__"
},
"engines": {
"node": ">=19"
"node": ">=20.0.0"
},
"repository": "https://github.com/team-telnyx/noc-integrations",
"repository": "https://github.com/team-telnyx/ai-chatbot",
"author": "[email protected]",
"license": "MIT",
"private": true,
"private": false,
"dependencies": {
"@bugsnag/js": "^7.20.0",
"@bugsnag/plugin-express": "^7.19.0",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@fontsource/roboto": "^4.5.8",
"@hcaptcha/react-hcaptcha": "^1.9.1",
"@microsoft/fetch-event-source": "^2.0.1",
"@mui/icons-material": "^5.11.0",
"@mui/lab": "^5.0.0-alpha.127",
"@mui/material": "^5.11.5",
"@mui/x-data-grid": "^6.2.0",
"@mui/x-date-pickers": "^6.7.0",
"@reduxjs/toolkit": "^1.9.1",
"axios": "^1.6.0",
"cheerio": "^1.0.0-rc.12",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"csvtojson": "^2.0.10",
"dayjs": "^1.11.8",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-hcaptcha": "^0.0.3",
"express-session": "^1.17.3",
"github-slugger": "^2.0.0",
"glob": "^9.3.2",
"gpt-3-encoder": "^1.1.4",
"graphql": "^16.8.1",
"html-entities": "^2.3.3",
"html-to-text": "^9.0.5",
"html-webpack-plugin": "^5.5.0",
"js-tiktoken": "^1.0.10",
"json-2-csv": "^4.0.0",
"jsonwebtoken": "^9.0.2",
"linkify-react": "^4.1.1",
"linkifyjs": "^4.1.1",
"mdast-util-from-markdown": "^1.3.0",
"mdast-util-gfm": "^2.0.2",
"mdast-util-mdx": "^2.0.1",
"mdast-util-mdx-jsx": "^2.1.2",
"mdast-util-to-markdown": "^1.5.0",
"mdast-util-to-string": "^3.2.0",
"micromark-extension-gfm": "^2.0.1",
"micromark-extension-mdxjs": "^1.0.0",
"node-cron": "^3.0.2",
"node-html-markdown": "^1.3.0",
"openai": "^4.24.7",
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"pdf-lib": "^1.17.1",
"pdf-parse": "^1.1.1",
"pdf2json": "^3.0.5",
"pg": "^8.9.0",
"pg-pool": "^3.5.2",
"prom-client": "^14.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "6.0.3",
"react-query": "^3.39.3",
"react-redux": "^8.0.5",
"react-router-dom": "^6.6.2",
"react-spinners": "^0.13.8",
"react-syntax-highlighter": "^15.5.0",
"socket.io": "^4.6.1",
"socket.io-client": "3.1.2",
"string-similarity": "^4.0.4",
"styled-components": "^5.3.9",
"unist-builder": "^3.0.1",
"unist-util-filter": "^4.0.1",
"uuid": "^9.0.0",
"uuid4": "^2.0.3",
"uuidv4": "^6.2.13",
"weaviate-ts-client": "1.2.0",
"xml-js": "^1.6.11"
"uuid": "^9.0.0"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/runtime": "^7.20.7",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
"@types/bugsnag": "^3.1.0",
"@jest/globals": "^29.7.0",
"@types/cors": "^2.8.13",
"@types/express": "^4.17.15",
"@types/mdast": "^4.0.3",
"@types/node-cron": "^3.0.7",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"@types/react-syntax-highlighter": "15.5.6",
"@types/socket.io-client": "^3.0.0",
"@types/string-similarity": "^4.0.2",
"@types/styled-components": "^5.1.26",
"@types/supertest": "^6.0.2",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"babel-loader": "^9.1.2",
"babel-plugin-module-resolver": "4.1.0",
"css-loader": "^6.7.3",
"eslint": "^8.0.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.6.0",
"eslint-config-standard-with-typescript": "^26.0.0",
"eslint-import-resolver-babel-module": "^5.3.1",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"node-sass": "^8.0.0",
"jest": "^29.7.0",
"prettier": "^2.8.2",
"react-refresh": "^0.14.0",
"sass": "^1.57.1",
"sass-extract": "^2.1.0",
"sass-extract-js": "^0.4.0",
"sass-extract-loader": "^1.1.0",
"sass-loader": "^13.2.0",
"style-loader": "^3.3.1",
"supertest": "^6.3.4",
"ts-jest": "^29.1.2",
"tsc-watch": "^6.0.0",
"tsx": "^3.12.6",
"typescript": "*",
"webpack": "^5.76.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1",
"webpack-merge": "^5.8.0"
"typescript": "*"
}
}
Loading
Loading