Skip to content

Commit

Permalink
initial setup whatsapp business
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjiunchetti committed Oct 27, 2023
1 parent 05763fb commit 2033710
Show file tree
Hide file tree
Showing 20 changed files with 711 additions and 24 deletions.
18 changes: 18 additions & 0 deletions backend/whatsapp-business-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
19 changes: 19 additions & 0 deletions backend/whatsapp-business-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable */
export default {
displayName: 'whatsapp-business-e2e',
preset: '../../jest.preset.js',
globalSetup: '<rootDir>/src/support/global-setup.ts',
globalTeardown: '<rootDir>/src/support/global-teardown.ts',
setupFiles: ['<rootDir>/src/support/test-setup.ts'],
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
},
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/whatsapp-business-e2e',
}
23 changes: 23 additions & 0 deletions backend/whatsapp-business-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "whatsapp-business-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"implicitDependencies": ["whatsapp-business"],
"projectType": "application",
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{e2eProjectRoot}"],
"options": {
"jestConfig": "backend/whatsapp-business-e2e/jest.config.ts",
"passWithNoTests": true
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["backend/whatsapp-business-e2e/**/*.{js,ts}"]
}
}
}
}
10 changes: 10 additions & 0 deletions backend/whatsapp-business-e2e/src/support/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
var __TEARDOWN_MESSAGE__: string

module.exports = async function () {
// Start services that that the app needs to run (e.g. database, docker-compose, etc.).
console.log('\nSetting up...\n')

// Hint: Use `globalThis` to pass variables to global teardown.
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n'
}
7 changes: 7 additions & 0 deletions backend/whatsapp-business-e2e/src/support/global-teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable */

module.exports = async function () {
// Put clean up logic here (e.g. stopping services, docker-compose, etc.).
// Hint: `globalThis` is shared between setup and teardown.
console.log(globalThis.__TEARDOWN_MESSAGE__)
}
10 changes: 10 additions & 0 deletions backend/whatsapp-business-e2e/src/support/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */

import axios from 'axios'

module.exports = async function () {
// Configure axios for tests to use.
const host = process.env.HOST ?? 'localhost'
const port = process.env.PORT ?? '3000'
axios.defaults.baseURL = `http://${host}:${port}`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import axios from 'axios'

describe('GET /', () => {
it('should return a message', async () => {
const res = await axios.get(`/`)

expect(res.status).toBe(200)
expect(res.data).toEqual({ message: 'Hello API' })
})
})
13 changes: 13 additions & 0 deletions backend/whatsapp-business-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
}
9 changes: 9 additions & 0 deletions backend/whatsapp-business-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.ts"]
}
18 changes: 18 additions & 0 deletions backend/whatsapp-business/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
24 changes: 24 additions & 0 deletions backend/whatsapp-business/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is generated by Nx.
#
# Build the docker image with `npx nx docker-build whatsapp-business`.
# Tip: Modify "docker-build" options in project.json to change docker build args.
#
# Run the container with `docker run -p 3000:3000 -t whatsapp-business`.
FROM docker.io/node:lts-alpine

ENV HOST=0.0.0.0
ENV PORT=3000

WORKDIR /app

RUN addgroup --system whatsapp-business && \
adduser --system -G whatsapp-business whatsapp-business

COPY dist/backend/whatsapp-business whatsapp-business
RUN chown -R whatsapp-business:whatsapp-business .

# You can remove this install step if you build with `--bundle` option.
# The bundled output will include external dependencies.
RUN npm --prefix whatsapp-business --omit=dev -f install

CMD [ "node", "whatsapp-business" ]
11 changes: 11 additions & 0 deletions backend/whatsapp-business/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'whatsapp-business',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': '@swc/jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/backend/whatsapp-business',
}
82 changes: 82 additions & 0 deletions backend/whatsapp-business/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "whatsapp-business",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "backend/whatsapp-business/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"platform": "node",
"outputPath": "dist/backend/whatsapp-business",
"format": ["cjs"],
"bundle": false,
"main": "backend/whatsapp-business/src/main.ts",
"tsConfig": "backend/whatsapp-business/tsconfig.app.json",
"assets": ["backend/whatsapp-business/src/assets"],
"generatePackageJson": true,
"esbuildOptions": {
"sourcemap": true,
"outExtension": {
".js": ".js"
}
}
},
"configurations": {
"development": {},
"production": {
"generateLockfile": true,
"esbuildOptions": {
"sourcemap": false,
"outExtension": {
".js": ".js"
}
}
}
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "whatsapp-business:build"
},
"configurations": {
"development": {
"buildTarget": "whatsapp-business:build:development"
},
"production": {
"buildTarget": "whatsapp-business:build:production"
}
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["backend/whatsapp-business/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "backend/whatsapp-business/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
},
"docker-build": {
"dependsOn": ["build"],
"command": "docker build -f backend/whatsapp-business/Dockerfile . -t whatsapp-business"
}
},
"tags": []
}
Empty file.
14 changes: 14 additions & 0 deletions backend/whatsapp-business/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import express from 'express'

const host = process.env.HOST ?? 'localhost'
const port = process.env.PORT ? Number(process.env.PORT) : 3000

const app = express()

app.get('/', (req, res) => {
res.send({ message: 'Hello API' })
})

app.listen(port, host, () => {
console.log(`[ ready ] http://${host}:${port}`)
})
10 changes: 10 additions & 0 deletions backend/whatsapp-business/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
16 changes: 16 additions & 0 deletions backend/whatsapp-business/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
}
14 changes: 14 additions & 0 deletions backend/whatsapp-business/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
"storybook": "nx run-many --target=storybook --all=true",
"leilao": "nx serve leilao",
"lister": "nx serve lister",
"whatsapp": "nx serve whatsapp-business",
"ui-components": "nx storybook ui-components"
},
"private": true,
"dependencies": {
"@nx/next": "16.7.4",
"@swc/helpers": "~0.5.0",
"axios": "^1.0.0",
"express": "~4.18.1",
"next": "13.4.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand All @@ -21,10 +24,12 @@
},
"devDependencies": {
"@nx/cypress": "16.7.4",
"@nx/esbuild": "16.10.0",
"@nx/eslint-plugin": "16.7.4",
"@nx/jest": "16.7.4",
"@nx/js": "16.7.4",
"@nx/jest": "16.10.0",
"@nx/js": "16.10.0",
"@nx/linter": "16.7.4",
"@nx/node": "16.10.0",
"@nx/react": "16.7.4",
"@nx/rollup": "16.7.4",
"@nx/storybook": "^16.7.4",
Expand All @@ -44,6 +49,7 @@
"@swc/core": "~1.3.51",
"@swc/jest": "0.2.20",
"@testing-library/react": "14.0.0",
"@types/express": "~4.17.13",
"@types/jest": "^29.4.0",
"@types/node": "18.14.2",
"@types/react": "18.2.14",
Expand All @@ -54,6 +60,7 @@
"babel-jest": "^29.4.1",
"core-js": "^3.6.5",
"cypress": "^12.16.0",
"esbuild": "^0.17.17",
"eslint": "~8.46.0",
"eslint-config-next": "13.4.1",
"eslint-config-prettier": "8.1.0",
Expand Down
Loading

0 comments on commit 2033710

Please sign in to comment.