Я использую mocha и chai-http для проверки моего сервера API .Проблема в том, что он обрабатывает запрос {stock: 'msft', stock: 'aapl'}
, как если бы он был { stock: 'aapl' }
.
Тест:
var chaiHttp = require('chai-http');
var chai = require('chai');
var assert = chai.assert;
var server = require('../server');
chai.use(chaiHttp);
describe('Functional Tests', function() {
describe('GET /api/stock-prices => stockData object', function() {
it('1 stock', function(done) {
chai.request(server)
.get('/api/stock-prices')
.query({stock: 'goog'})
.end(function(err, res){
console.log(res.body);
//complete this one too
done();
});
});
it('1 stock with like', function(done) {
});
it('1 stock with like again (ensure likes arent double counted)', function(done) {
});
it('2 stocks', function(done) {
chai.request(server)
.get('/api/stock-prices')
.query({stock: 'msft', stock: 'aapl'}) // <-- THIS ONE
.end(function(err, res){
console.log(res.body);
done();
});
});
it('2 stocks with like', function(done) {
});
});
});
Результат:
1. Uncaught error outside test suite
Functional Tests
GET /api/stock-prices => stockData object
{ stockData: { stock: 'GOOG', price: '1019.8300', likes: 14 } }
/ 1 stock (532ms)
2) 1 stock with like
3) 1 stock with like again (ensure likes arent double counted)
{ stockData: { stock: 'AAPL', price: '185.7900', likes: 7 } }
/ 2 stocks (360ms)
4) 2 stocks with like
Выход { stockData: { stock: 'AAPL', price: '185.7900', likes: 7 } }
показывает только одну акцию.Ожидается возврат
{"stockData":[{"stock":"MSFT","price":"104.5600","rel_likes":-5},{"stock":"AAPL","price":"185.7900","rel_likes":5}]}