Skip to content

Commit ff4c473

Browse files
authored
add tests (#9)
* add mocha.opts,update package.json,add project_directory_structure.md,update webserver.js,update yarn.lock, add webserver.test.js * update the file extension of project_directory_structure.md to .txt * fix workflow * add branch rule for tests branch * disable SSH-key auth in favour of HTTPS clone * optimize the workflow file * add exisiting yarn.lock to root path of repo * migrate from .json eslint config to new spec, update webserver logic and test cases. * add eslint.config.mjs to root of monorepo structure. * update node-version variable to use 22 instead of 16(?) * update project workflow structure dependencies for monorepo structure * restructure entire project for easier management. * update path for tests and linting * update the workflow to verify the lock file exists in the expected subdirectory. * commit and push yarn.lock to root of repo. * update workflow spec again * update workflow path * update workflow * remove yarn lockfile verification step * update working-dir path * update linting workflow, add badge for Mocha tests * update README with badges and update linting workflow * update root readme.md before merge to main * Update webserver logic
1 parent d66a101 commit ff4c473

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

node-express-server/webserver.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ app.use((req, res, next) => {
1818
});
1919

2020
app.get('/', (req, res) => {
21+
const userAgent = new UserAgents().toString();
2122
res.status(200).json({ message: 'Hello Express!' }); // Respond with JSON
22-
console.log(`Received GET request to the API with userAgent:`);
23-
console.log(userAgent.toString());
23+
console.log(`Received GET request to the API with userAgent: ${userAgent}`);
2424
});
2525

2626
app.post('/', (req, res) => {
@@ -35,18 +35,17 @@ app.put('/user', (req, res) => {
3535
throw new Error('Simulated server error');
3636
}
3737
res.status(200).json({ message: 'Resource updated successfully' });
38-
console.log(`Received PUT request from port: ${port} to ${dir}userAgent:`);
39-
console.log(userAgent.toString());
38+
console.log(`Received PUT request from port: ${port} to ${dir} userAgent: ${userAgent}`);
4039
} catch (error) {
4140
res.status(500).json({ error: 'Internal server error' }); // Handle server error
4241
console.error('Error occurred on PUT /user:', error.message);
4342
}
4443
});
4544

4645
app.delete('/user', (req, res) => {
46+
const userAgent = new UserAgents().toString();
4747
res.status(204).send(); // Respond with 204 for successful deletion
48-
console.log(`Received DELETE request from port: ${port} to ${dir}userAgent:`);
49-
console.log(userAgent.toString());
48+
console.log(`Received DELETE request from port: ${port} to ${dir} userAgent: ${userAgent}`);
5049
});
5150

5251
// POST /user route

0 commit comments

Comments
 (0)