Skip to content

Commit

Permalink
Merge pull request #351 from bluewave-labs/316-write-some-tests-for-b…
Browse files Browse the repository at this point in the history
…ackend-using-vitest

316 write some tests for backend using vitest
  • Loading branch information
DeboraSerra authored Dec 10, 2024
2 parents d8025b2 + 679dd8b commit a0ef4b3
Show file tree
Hide file tree
Showing 62 changed files with 14,179 additions and 633 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
check-latest: true

# Clear npm cache
- name: Clear npm cache
Expand Down Expand Up @@ -87,14 +88,13 @@ jobs:
working-directory: ./frontend
run: npm run build --if-present

# Uncomment the following lines to run tests
# - name: Run tests for backend
# working-directory: ./backend
# run: npm test
- name: Run tests for backend
working-directory: ./backend
run: npm test

- name: Run tests for frontend
working-directory: ./frontend
run: npm test

- name: Run Docker container
run: docker compose up --build -d
run: docker compose up --build -d
Binary file added backend/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"

TEST_DB_USERNAME=user123
TEST_DB_PASSWORD=password123
TEST_DB_NAME=onboarding_db
TEST_DB_NAME=onboarding_db_test
TEST_DB_HOST=localhost
TEST_DB_PORT=5432
10 changes: 7 additions & 3 deletions backend/.env.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Test Environment Configuration

# Database Configuration
TEST_DB_USERNAME=test_user
TEST_DB_PASSWORD=test_password
TEST_DB_NAME=test_db
TEST_DB_USERNAME=user123
TEST_DB_PASSWORD=password123
TEST_DB_NAME=onboarding_db_test
TEST_DB_HOST=localhost
TEST_DB_PORT=5432

POSTGRES_USER=user123
POSTGRES_PASSWORD=password123
POSTGRES_DB=onboarding_db_test

# JWT Secret Key
JWT_SECRET=your_test_jwt_secret_key_here
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
.env
logs/
dist/
.nyc_output
63 changes: 1 addition & 62 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,4 @@
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const dotenv = require('dotenv');
const bodyParser = require('body-parser');
const jsonErrorMiddleware = require('./src/middleware/jsonError.middleware');
const fileSizeValidator = require('./src/middleware/fileSizeValidator.middleware');
const { MAX_FILE_SIZE } = require('./src/utils/constants.helper');

// Load environment variables from .env file
dotenv.config();

const authRoutes = require('./src/routes/auth.routes');
const userRoutes = require('./src/routes/user.routes');
const mocks = require('./src/routes/mocks.routes');
const popup = require('./src/routes/popup.routes');
const guide_log = require('./src/routes/guidelog.routes');
const banner = require('./src/routes/banner.routes');
const teamRoutes = require('./src/routes/team.routes');
const hint = require('./src/routes/hint.routes');
const tourRoutes = require('./src/routes/tour.routes');
const linkRoutes = require('./src/routes/link.routes');
const helperLinkRoutes = require('./src/routes/helperLink.routes');
const guideRoutes = require('./src/routes/guide.routes');

const app = express();

app.use(cors());
app.use(helmet());
app.use(bodyParser.json({ limit: MAX_FILE_SIZE }));
app.use(jsonErrorMiddleware);
// app.use(fileSizeValidator);

const { sequelize } = require("./src/models");

sequelize
.authenticate()
.then(() => console.log('Database connected...'))
.catch((err) => console.log('Error: ' + err));

sequelize
.sync({ force: false })
.then(() => console.log("Models synced with the database..."))
.catch((err) => console.log("Error syncing models: " + err));

app.use('/api/auth', authRoutes);
app.use('/api/users', userRoutes);
app.use('/api/mock/', mocks);
app.use('/api/popup', popup);
app.use('/api/guide_log', guide_log);
app.use('/api/banner', banner);
app.use('/api/team', teamRoutes);
app.use('/api/guide', guideRoutes);
app.use('/api/hint', hint);
app.use('/api/tour', tourRoutes);
app.use('/api/link', linkRoutes);
app.use('/api/helper-link', helperLinkRoutes);

app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ message: 'Internal Server Error' });
});
const app = require("./src/server");

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
Expand Down
Loading

0 comments on commit a0ef4b3

Please sign in to comment.