-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(stats of trips):Users should get stats of trips made in the last X…
… timeframe add getStast function add findStats helper [finishes #168781712]
- Loading branch information
Showing
9 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import { describe, it, before } from 'mocha'; | ||
import app from '../index'; | ||
import mockData from './mockData/mockData'; | ||
|
||
chai.should(); | ||
chai.use(chaiHttp); | ||
|
||
let userToken; | ||
let supplierToken; | ||
|
||
describe('stats Requests Tests', () => { | ||
before(done => { | ||
chai.request(app) | ||
.post('/api/v1/users/login') | ||
.send(mockData.registeredUser) | ||
.end((err, res) => { | ||
userToken = res.body.data.token; | ||
}); | ||
chai.request(app) | ||
.post('/api/v1/users/login') | ||
.send(mockData.supplier) | ||
.end((err, res) => { | ||
supplierToken = res.body.data.token; | ||
done(); | ||
}); | ||
}); | ||
|
||
|
||
it('Should return stats ', done => { | ||
chai.request(app) | ||
.get('/api/v1/requests/stats?startDate=2019-11-07&endDate=2019-01-03') | ||
.set('Authorization', `Bearer ${userToken}`) | ||
.end((err, res) => { | ||
res.should.have.property('status').eql(200); | ||
res.body.should.have.property('message').eql('Your number of trips are:'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('Should return stats with invalid date', done => { | ||
chai.request(app) | ||
.get('/api/v1/requests/stats?startDate=2019-11-07&endDate=2019-12-03') | ||
.set('Authorization', `Bearer ${userToken}`) | ||
.end((err, res) => { | ||
res.should.have.property('status').eql(400); | ||
res.body.should.have.property('message').eql('endDate must not be greater than startDate'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('Should return stats with invalid date', done => { | ||
chai.request(app) | ||
.get('/api/v1/requests/stats?startDate=2019-11-07&endDate=2019-11-07') | ||
.set('Authorization', `Bearer ${userToken}`) | ||
.end((err, res) => { | ||
res.should.have.property('status').eql(400); | ||
res.body.should.have.property('message').eql('Dates are similar use different dates'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('Should return 403 status, Supplier not allowed', done => { | ||
chai.request(app) | ||
.get('/api/v1/requests/stats?startDate=2019-11-07&endDate=2019-01-03') | ||
.set('Authorization', `Bearer ${supplierToken}`) | ||
.end((err, res) => { | ||
res.should.have.property('status').eql(403); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('Should return 400 status, with invalid input', done => { | ||
chai.request(app) | ||
.get('/api/v1/requests/stats?days=-23') | ||
.set('Authorization', `Bearer ${userToken}`) | ||
.end((err, res) => { | ||
res.should.have.property('status').eql(400); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters