Skip to content

Commit 6c9b34d

Browse files
committed
reduce routes
1 parent cc59ce8 commit 6c9b34d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+307
-307
lines changed

index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ app.use((err: { status: number }, req: any, res: any, next: Function) => {
6161
}
6262
next();
6363
});
64-
app.use('/api', router);
6564

66-
app.get('/', (req, res) => {
67-
res.send({ message: 'Hello World!' });
68-
});
65+
app.use(router);
6966

7067
export default app;

routes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ import scoreBoard from './router/otherCaller/scoreBoard';
5656

5757
const router = Router();
5858

59+
router.get('/', (req, res) => {
60+
res.send({ message: 'Hello World!' });
61+
});
5962
//caller
6063
router.post('/caller/changePassword', changePassword);
6164
router.post('/caller/createCaller', createCaller);

tests/admin/area/changeAdminPassword.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ afterAll(async () => {
2525
await mongoose.connection.close();
2626
});
2727

28-
describe('post on /api/admin/area/changeAdminPassword', () => {
28+
describe('post on /admin/area/changeAdminPassword', () => {
2929
it('should return 400 if bad new admin password', async () => {
30-
const res = await request(app).post('/api/admin/area/changeAdminPassword').send({
30+
const res = await request(app).post('/admin/area/changeAdminPassword').send({
3131
adminCode: adminPassword,
3232
area: areaId,
3333
newPassword: ' '
@@ -37,7 +37,7 @@ describe('post on /api/admin/area/changeAdminPassword', () => {
3737
});
3838

3939
it('should return 404 if no area found', async () => {
40-
const res = await request(app).post('/api/admin/area/changeAdminPassword').send({
40+
const res = await request(app).post('/admin/area/changeAdminPassword').send({
4141
adminCode: adminPassword,
4242
area: new mongoose.Types.ObjectId(),
4343
newPassword: 'newPassword'
@@ -48,7 +48,7 @@ describe('post on /api/admin/area/changeAdminPassword', () => {
4848

4949
it('should return 400 if new password is too long', async () => {
5050
const res = await request(app)
51-
.post('/api/admin/area/changeAdminPassword')
51+
.post('/admin/area/changeAdminPassword')
5252
.send({
5353
adminCode: adminPassword,
5454
area: areaId,
@@ -59,7 +59,7 @@ describe('post on /api/admin/area/changeAdminPassword', () => {
5959
});
6060

6161
it('should return 400 if new password is not a hash', async () => {
62-
const res = await request(app).post('/api/admin/area/changeAdminPassword').send({
62+
const res = await request(app).post('/admin/area/changeAdminPassword').send({
6363
adminCode: adminPassword,
6464
area: areaId,
6565
newPassword:
@@ -71,7 +71,7 @@ describe('post on /api/admin/area/changeAdminPassword', () => {
7171
});
7272

7373
it('should return 200 if OK', async () => {
74-
const res = await request(app).post('/api/admin/area/changeAdminPassword').send({
74+
const res = await request(app).post('/admin/area/changeAdminPassword').send({
7575
adminCode: 'password',
7676
area: areaId,
7777
newPassword: 'newPassword'
@@ -98,7 +98,7 @@ describe('post on /api/admin/area/changeAdminPassword', () => {
9898
adminPassword: password
9999
})
100100
).id;
101-
const res = await request(app).post('/api/admin/area/changeAdminPassword').send({
101+
const res = await request(app).post('/admin/area/changeAdminPassword').send({
102102
adminCode: password,
103103
area: areaId2,
104104
newPassword: newAreaPassword,

tests/admin/area/changeName.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ afterAll(async () => {
2525
await mongoose.connection.close();
2626
});
2727

28-
describe('post on /api/admin/area/changeName', () => {
28+
describe('post on /admin/area/changeName', () => {
2929
it('should return 400 if bad new name', async () => {
30-
const res = await request(app).post('/api/admin/area/changeName').send({
30+
const res = await request(app).post('/admin/area/changeName').send({
3131
adminCode: adminPassword,
3232
area: areaId,
3333
newName: ' ',
@@ -39,7 +39,7 @@ describe('post on /api/admin/area/changeName', () => {
3939

4040
it('should return 400 if new name is too long', async () => {
4141
const res = await request(app)
42-
.post('/api/admin/area/changeName')
42+
.post('/admin/area/changeName')
4343
.send({
4444
adminCode: adminPassword,
4545
area: areaId,
@@ -51,7 +51,7 @@ describe('post on /api/admin/area/changeName', () => {
5151
});
5252

5353
it('should return 404 if no area found', async () => {
54-
const res = await request(app).post('/api/admin/area/changeName').send({
54+
const res = await request(app).post('/admin/area/changeName').send({
5555
adminCode: adminPassword,
5656
area: new mongoose.Types.ObjectId(),
5757
newName: 'newName',
@@ -62,7 +62,7 @@ describe('post on /api/admin/area/changeName', () => {
6262
});
6363

6464
it('should return 401 if wrong admin code', async () => {
65-
const res = await request(app).post('/api/admin/area/changeName').send({
65+
const res = await request(app).post('/admin/area/changeName').send({
6666
adminCode: 'wrongpassword',
6767
area: areaId,
6868
newName: 'newName'
@@ -72,7 +72,7 @@ describe('post on /api/admin/area/changeName', () => {
7272
});
7373

7474
it('should return 200 if name of area changed', async () => {
75-
const res = await request(app).post('/api/admin/area/changeName').send({
75+
const res = await request(app).post('/admin/area/changeName').send({
7676
adminCode: 'password',
7777
area: areaId,
7878
newName: 'newName'
@@ -84,7 +84,7 @@ describe('post on /api/admin/area/changeName', () => {
8484
});
8585

8686
it('should return 200 if name of area changed with hash', async () => {
87-
const res = await request(app).post('/api/admin/area/changeName').send({
87+
const res = await request(app).post('/admin/area/changeName').send({
8888
adminCode: adminPassword,
8989
area: areaId,
9090
newName: 'newName2',

tests/admin/area/changePassword.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ afterAll(async () => {
2525
await mongoose.connection.close();
2626
});
2727

28-
describe('post on /api/admin/area/changePassword', () => {
28+
describe('post on /admin/area/changePassword', () => {
2929
it('should return 400 if bad new password', async () => {
30-
const res = await request(app).post('/api/admin/area/changePassword').send({
30+
const res = await request(app).post('/admin/area/changePassword').send({
3131
adminCode: adminPassword,
3232
area: areaId,
3333
newPassword: ' ',
@@ -38,7 +38,7 @@ describe('post on /api/admin/area/changePassword', () => {
3838
});
3939

4040
it('should return 404 if no area found', async () => {
41-
const res = await request(app).post('/api/admin/area/changePassword').send({
41+
const res = await request(app).post('/admin/area/changePassword').send({
4242
adminCode: adminPassword,
4343
area: new mongoose.Types.ObjectId(),
4444
newPassword: 'newPassword',
@@ -50,7 +50,7 @@ describe('post on /api/admin/area/changePassword', () => {
5050

5151
it('should return 400 if new password is too long', async () => {
5252
const res = await request(app)
53-
.post('/api/admin/area/changePassword')
53+
.post('/admin/area/changePassword')
5454
.send({
5555
adminCode: adminPassword,
5656
area: areaId,
@@ -62,7 +62,7 @@ describe('post on /api/admin/area/changePassword', () => {
6262
});
6363

6464
it('should return 200 if password of area changed', async () => {
65-
const res = await request(app).post('/api/admin/area/changePassword').send({
65+
const res = await request(app).post('/admin/area/changePassword').send({
6666
adminCode: 'password',
6767
area: areaId,
6868
newPassword: 'newPassword'
@@ -72,7 +72,7 @@ describe('post on /api/admin/area/changePassword', () => {
7272
});
7373

7474
it('should return 200 if password of area changed with hash', async () => {
75-
const res = await request(app).post('/api/admin/area/changePassword').send({
75+
const res = await request(app).post('/admin/area/changePassword').send({
7676
adminCode: adminPassword,
7777
area: areaId,
7878
newPassword: 'newPassword',

tests/admin/caller/addCallerCampaign.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ afterAll(async () => {
5454
await mongoose.connection.close();
5555
});
5656

57-
describe('post on /api/admin/caller/addCallerCampaign', () => {
57+
describe('post on /admin/caller/addCallerCampaign', () => {
5858
it('should return 401 if wrong admin code', async () => {
59-
const res = await request(app).post('/api/admin/caller/addCallerCampaign').send({
59+
const res = await request(app).post('/admin/caller/addCallerCampaign').send({
6060
phone: '+33134567890',
6161
adminCode: 'wrong',
6262
area: areaId,
@@ -66,7 +66,7 @@ describe('post on /api/admin/caller/addCallerCampaign', () => {
6666
expect(res.body.message).toBe('Wrong admin code');
6767
});
6868
it('should return 404 if campaign not found', async () => {
69-
const res = await request(app).post('/api/admin/caller/addCallerCampaign').send({
69+
const res = await request(app).post('/admin/caller/addCallerCampaign').send({
7070
phone: '+33134567890',
7171
adminCode: adminPassword,
7272
area: areaId,
@@ -77,7 +77,7 @@ describe('post on /api/admin/caller/addCallerCampaign', () => {
7777
expect(res.body.message).toBe('Campaign not found');
7878
});
7979
it('should return 404 if caller not found', async () => {
80-
const res = await request(app).post('/api/admin/caller/addCallerCampaign').send({
80+
const res = await request(app).post('/admin/caller/addCallerCampaign').send({
8181
phone: '+33134567891',
8282
adminCode: adminPassword,
8383
area: areaId,
@@ -96,7 +96,7 @@ describe('post on /api/admin/caller/addCallerCampaign', () => {
9696
area: areaId,
9797
campaigns: [campaignId]
9898
});
99-
const res = await request(app).post('/api/admin/caller/addCallerCampaign').send({
99+
const res = await request(app).post('/admin/caller/addCallerCampaign').send({
100100
phone: '+33134567892',
101101
adminCode: adminPassword,
102102
area: areaId,
@@ -110,7 +110,7 @@ describe('post on /api/admin/caller/addCallerCampaign', () => {
110110
});
111111

112112
it('should return 200 if OK', async () => {
113-
const res = await request(app).post('/api/admin/caller/addCallerCampaign').send({
113+
const res = await request(app).post('/admin/caller/addCallerCampaign').send({
114114
phone: '+33134567890',
115115
adminCode: adminPassword,
116116
area: areaId,

tests/admin/caller/callerInfo.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ afterAll(async () => {
5656
await mongoose.connection.close();
5757
});
5858

59-
describe('post on /api/admin/caller/callerInfo', () => {
59+
describe('post on /admin/caller/callerInfo', () => {
6060
it('should return 400 if bad phone number', async () => {
61-
const res = await request(app).post('/api/admin/caller/callerInfo').send({
61+
const res = await request(app).post('/admin/caller/callerInfo').send({
6262
adminCode: adminCode,
6363
phone: 'invalid',
6464
area: areaId,
@@ -69,7 +69,7 @@ describe('post on /api/admin/caller/callerInfo', () => {
6969
});
7070

7171
it('should return 404 if area not found', async () => {
72-
const res = await request(app).post('/api/admin/caller/callerInfo').send({
72+
const res = await request(app).post('/admin/caller/callerInfo').send({
7373
adminCode: adminCode,
7474
phone: '+33634567890',
7575
area: new mongoose.Types.ObjectId(),
@@ -80,7 +80,7 @@ describe('post on /api/admin/caller/callerInfo', () => {
8080
});
8181

8282
it('should return 404 if caller not found', async () => {
83-
const res = await request(app).post('/api/admin/caller/callerInfo').send({
83+
const res = await request(app).post('/admin/caller/callerInfo').send({
8484
adminCode: adminCode,
8585
phone: '+33634567891',
8686
area: areaId,
@@ -108,7 +108,7 @@ describe('post on /api/admin/caller/callerInfo', () => {
108108
campaigns: []
109109
})
110110
).id;
111-
const res = await request(app).post('/api/admin/caller/callerInfo').send({
111+
const res = await request(app).post('/admin/caller/callerInfo').send({
112112
adminCode: adminCode,
113113
phone: '+33634567892',
114114
area: Area2Id,
@@ -119,7 +119,7 @@ describe('post on /api/admin/caller/callerInfo', () => {
119119
});
120120

121121
it('should return 200 with caller info', async () => {
122-
const res = await request(app).post('/api/admin/caller/callerInfo').send({
122+
const res = await request(app).post('/admin/caller/callerInfo').send({
123123
adminCode: adminCode,
124124
phone: '+33634567890',
125125
area: areaId,

tests/admin/caller/changeCallerPassword.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ afterAll(async () => {
3535
await mongoose.connection.close();
3636
});
3737

38-
describe('post on /api/admin/caller/changePassword', () => {
38+
describe('post on /admin/caller/changePassword', () => {
3939
it('should return 400 if new pin code is not a number', async () => {
40-
const response = await request(app).post('/api/admin/caller/changePassword').send({
40+
const response = await request(app).post('/admin/caller/changePassword').send({
4141
adminCode: 'password',
4242
newPassword: 'a123',
4343
Callerphone: '+33234567890',
@@ -48,7 +48,7 @@ describe('post on /api/admin/caller/changePassword', () => {
4848
});
4949

5050
it('should return 400 if new pin code is not 4 digits', async () => {
51-
const response = await request(app).post('/api/admin/caller/changePassword').send({
51+
const response = await request(app).post('/admin/caller/changePassword').send({
5252
adminCode: 'password',
5353
newPassword: '12345',
5454
Callerphone: '+33234567890',
@@ -59,7 +59,7 @@ describe('post on /api/admin/caller/changePassword', () => {
5959
});
6060

6161
it('should return 401 if admin code is wrong', async () => {
62-
const response = await request(app).post('/api/admin/caller/changePassword').send({
62+
const response = await request(app).post('/admin/caller/changePassword').send({
6363
adminCode: 'wrongAdminPassword',
6464
newPassword: '1234',
6565
Callerphone: '+33234567890',
@@ -70,7 +70,7 @@ describe('post on /api/admin/caller/changePassword', () => {
7070
});
7171

7272
it('should return 404 if caller not found', async () => {
73-
const response = await request(app).post('/api/admin/caller/changePassword').send({
73+
const response = await request(app).post('/admin/caller/changePassword').send({
7474
adminCode: 'password',
7575
newPassword: '1234',
7676
Callerphone: '+33234567891',
@@ -81,7 +81,7 @@ describe('post on /api/admin/caller/changePassword', () => {
8181
});
8282

8383
it('should return 200 if password changed', async () => {
84-
const response = await request(app).post('/api/admin/caller/changePassword').send({
84+
const response = await request(app).post('/admin/caller/changePassword').send({
8585
adminCode: 'password',
8686
newPassword: '1235',
8787
Callerphone: '+33234567890',
@@ -94,7 +94,7 @@ describe('post on /api/admin/caller/changePassword', () => {
9494
});
9595

9696
it('should return 200 if password changed with hash', async () => {
97-
const response = await request(app).post('/api/admin/caller/changePassword').send({
97+
const response = await request(app).post('/admin/caller/changePassword').send({
9898
adminCode: adminPassword,
9999
newPassword: '1235',
100100
Callerphone: '+33234567890',

tests/admin/caller/changeName.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ afterAll(async () => {
3939
await mongoose.connection.close();
4040
});
4141

42-
describe('post on /api/admin/caller/changeName', () => {
42+
describe('post on /admin/caller/changeName', () => {
4343
it('should return 400 if newName is empty', async () => {
44-
const response = await request(app).post('/api/admin/caller/changeName').send({
44+
const response = await request(app).post('/admin/caller/changeName').send({
4545
adminCode: 'password',
4646
newName: '',
4747
phone: '+33134567890',
@@ -52,7 +52,7 @@ describe('post on /api/admin/caller/changeName', () => {
5252
});
5353

5454
it('should return 401 if admin code is wrong', async () => {
55-
const response = await request(app).post('/api/admin/caller/changeName').send({
55+
const response = await request(app).post('/admin/caller/changeName').send({
5656
adminCode: 'wrongpassword',
5757
newName: 'newName',
5858
phone: '+33134567890',
@@ -63,7 +63,7 @@ describe('post on /api/admin/caller/changeName', () => {
6363
});
6464

6565
it('should return 400 if caller not found', async () => {
66-
const response = await request(app).post('/api/admin/caller/changeName').send({
66+
const response = await request(app).post('/admin/caller/changeName').send({
6767
adminCode: 'password',
6868
newName: 'newName',
6969
phone: '+33134567891',
@@ -74,7 +74,7 @@ describe('post on /api/admin/caller/changeName', () => {
7474
});
7575

7676
it('should return 200 if all parameters are correct', async () => {
77-
const response = await request(app).post('/api/admin/caller/changeName').send({
77+
const response = await request(app).post('/admin/caller/changeName').send({
7878
adminCode: 'password',
7979
newName: 'newName',
8080
phone: '+33134567890',
@@ -84,7 +84,7 @@ describe('post on /api/admin/caller/changeName', () => {
8484
expect(response.body).toMatchObject({ message: 'Caller name changed', OK: true });
8585
});
8686
it('should return 200 if all parameters are correct with hash', async () => {
87-
const response = await request(app).post('/api/admin/caller/changeName').send({
87+
const response = await request(app).post('/admin/caller/changeName').send({
8888
adminCode: adminPassword,
8989
newName: 'newName',
9090
phone: '+33134567890',

0 commit comments

Comments
 (0)