Skip to content

Commit eb4ee07

Browse files
committed
Updated folder structure and updated test suite
1 parent ad987d5 commit eb4ee07

4 files changed

Lines changed: 33 additions & 18 deletions

File tree

server.js renamed to app.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,4 @@ app.use(express.urlencoded({extended: false}));
3636
// middleware for handling sample api routes
3737
app.use('/api/v1', require('./routes/api/API'));
3838

39-
// use port from environment variables for production
40-
const PORT = process.env.PORT || 5000;
41-
42-
app.listen(PORT,()=>{
43-
console.log(`server running on port ${PORT}`);
44-
})
45-
4639
module.exports = app;

‎bin/www‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env node
2+
3+
const app = require('../app');
4+
5+
// use port from environment variables for production
6+
const PORT = process.env.PORT || 5000;
7+
8+
app.listen(PORT,()=>{
9+
console.log(`server running on port ${PORT}`);
10+
})

‎package.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"yarn": "1.x"
77
},
88
"description": "Engine to handle the rating mechanisms for the clean code",
9-
"main": "server.js",
9+
"main": "bin/www",
1010
"scripts": {
11-
"start": "node server.js",
12-
"dev": "nodemon server.js",
13-
"test": "mocha"
11+
"start": "node ./bin/www",
12+
"dev": "nodemon ./bin/www",
13+
"test": "mocha --exit"
1414
},
1515
"author": "Gaurav Walia",
1616
"license": "ISC",

‎test/test.js‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,52 @@
11
const request = require('supertest');
2-
const app = require('../server');
2+
const app = require('../app');
33

44
describe('testing the code rating engine APIs',() => {
55
let token = "";
6+
let codeId1 = "";
7+
let codeId2 = "";
8+
const SEARCH_USER = "GauravWalia19";
69
beforeEach('get the random codes with token', async () => {
710
try{
811
const res = await request(app)
912
.get('/api/v1/randomCodes')
1013
.expect(200)
1114
token = res.body.accessToken;
15+
codeId1 = res.body.codeObject1.codeId;
16+
codeId2 = res.body.codeObject2.codeId;
1217
}catch(err){
1318
console.log(err)
1419
}
1520
});
1621

17-
it('testing winner calculations', ()=>{
22+
it('testing winner calculations', (done)=>{
1823
request(app)
1924
.put('/api/v1/rateCode')
2025
.type('json')
2126
.send({
2227
'winner': 1,
23-
'codeId1': '55dfc162f8163243c9c7e155e9a9a26b9528be73',
24-
'codeId2': '489e8fe91b2db73cc0f8f78b831fabb1b927d2b5',
28+
codeId1,
29+
codeId2,
2530
'codeRatingEngineToken': token
2631
})
2732
.expect(200)
33+
.end((err, res)=>{
34+
if(err) done(err)
35+
else
36+
done();
37+
})
2838
})
2939

30-
it('search the users', ()=>{
40+
it('search the users', (done)=>{
3141
request(app)
3242
.get('/api/v1/searchUser')
33-
.query({username: 'GauravWalia19'})
43+
.query({username: SEARCH_USER})
3444
.send({'codeRatingEngineToken': token})
3545
.expect(200)
3646
.end((err, res)=>{
37-
if(err) console.log(err)
47+
if(err) done(err)
48+
else
49+
done();
3850
})
3951
})
4052
});

0 commit comments

Comments
 (0)