Skip to content
Open
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
36 changes: 36 additions & 0 deletions .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Backend Integration Tests

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
test-backend:
runs-on: ubuntu-latest

defaults:
run:
working-directory: gurubu-backend

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
cache-dependency-path: gurubu-backend/yarn.lock

- name: Install dependencies
run: yarn install

- name: Run Tests
run: yarn test
env:
NODE_ENV: test
CLIENT_URL: http://localhost:3000
PORT: 5000
9 changes: 6 additions & 3 deletions gurubu-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"scripts": {
"build": "webpack --config webpack.config.js",
"start": "nodemon server.js",
"test": "jest"
"test": "jest",
"test:e2e": "jest --config test/jest.config.js --forceExit --detectOpenHandles",
"test:watch": "jest --config test/jest.config.js --watch"
},
"dependencies": {
"axios": "^1.7.9",
Expand All @@ -29,9 +31,10 @@
"@babel/core": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"babel-loader": "^9.1.3",
"jest": "^29.7.0",
"jest": "^30.2.0",
"nodemon": "^3.0.1",
"supertest": "^7.0.0",
"supertest": "^7.2.2",
"typescript": "^5.9.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-node-externals": "^3.0.0"
Expand Down
33 changes: 19 additions & 14 deletions gurubu-backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,22 @@ app.use("/storypoint", cors(corsOptions), storyPointRoutes);
app.use("/initial-storypoint", cors(corsOptions), initialStoryPointRoutes);
app.use("/ai-workflow", cors(corsOptions), aiWorkflowRoutes);

const PORT = process.env.PORT || 5000;
const server = app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});

const io = socketIO(server, {
cors: {
origin: process.env.CLIENT_URL,
methods: ["GET", "POST"],
credentials: true,
},
});
groomingSocket(io);
cleanRoomsAndUsers();
module.exports = app;


if (require.main === module) {
const PORT = process.env.PORT || 5000;
const server = app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});

const io = socketIO(server, {
cors: {
origin: process.env.CLIENT_URL,
methods: ["GET", "POST"],
credentials: true,
},
});
groomingSocket(io);
cleanRoomsAndUsers();
}
21 changes: 21 additions & 0 deletions gurubu-backend/test/api/room.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const request = require('supertest');
// Gurubu's main file is likely src/index.ts or src/app.ts
// Make sure that file exports 'app'
const app = require('../../server');

describe('Room API Integration', () => {
it('POST /room/create should return a valid roomId', async () => {
const payload = {
groomingType: "0",
nickName: 'testUser1'
};
const response = await request(app)
.post('/room/create')
.send(payload);


expect(response.status).toBe(201);
expect(response.body).toHaveProperty('roomID');
console.log(response.body);
});
});
18 changes: 18 additions & 0 deletions gurubu-backend/test/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require('path');

module.exports = {
// Tell Jest to look for files relative to the project root
rootDir: path.join(__dirname, '.'), // Since this is in the root, '.' is enough

testEnvironment: 'node',

testMatch: ['<rootDir>/api/**/*.test.js'],

moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},

verbose: true,
forceExit: true,
clearMocks: true,
};
Loading