91 lines
3.4 KiB
JavaScript
91 lines
3.4 KiB
JavaScript
const Backbone = require('backbone');
|
|
const _ = require('underscore');
|
|
const WCollection = require('../src/js/collection/weather');
|
|
const expect = require('expect.js');
|
|
const sinon = require('sinon');
|
|
|
|
const wData = { 'city':{ 'id':3333231, 'name':'Glasgow City', 'coord':{ 'lon':-4.25, 'lat':55.8667 }, 'country':'GB', 'population':0 }, 'cod':'200', 'message':1.3268098, 'cnt':5, 'list':[{ 'dt':1506945600, 'temp':{ 'day':10.69, 'min':9.99, 'max':10.69, 'night':10.22, 'eve':10.69, 'morn':10.69 }, 'pressure':1001.71, 'humidity':94, 'weather':[{ 'id':500, 'main':'Rain', 'description':'light rain', 'icon':'10d' }], 'speed':7.6, 'deg':279, 'clouds':92, 'rain':0.99 }, { 'dt':1507032000, 'temp':{ 'day':11.13, 'min':9.52, 'max':11.28, 'night':10.11, 'eve':10.33, 'morn':9.52 }, 'pressure':1014.59, 'humidity':80, 'weather':[{ 'id':500, 'main':'Rain', 'description':'light rain', 'icon':'10d' }], 'speed':7.43, 'deg':285, 'clouds':88, 'rain':0.44 }, { 'dt':1507118400, 'temp':{ 'day':10.98, 'min':8.26, 'max':10.98, 'night':8.26, 'eve':9.29, 'morn':10 }, 'pressure':1007.06, 'humidity':93, 'weather':[{ 'id':501, 'main':'Rain', 'description':'moderate rain', 'icon':'10d' }], 'speed':8.77, 'deg':267, 'clouds':92, 'rain':8.52 }, { 'dt':1507204800, 'temp':{ 'day':10.77, 'min':5.92, 'max':10.79, 'night':5.92, 'eve':9.56, 'morn':6.4 }, 'pressure':1012.43, 'humidity':91, 'weather':[{ 'id':500, 'main':'Rain', 'description':'light rain', 'icon':'10d' }], 'speed':7.26, 'deg':291, 'clouds':64 }, { 'dt':1507291200, 'temp':{ 'day':9.28, 'min':5.88, 'max':12.7, 'night':10.84, 'eve':12.7, 'morn':5.88 }, 'pressure':1001.13, 'humidity':0, 'weather':[{ 'id':501, 'main':'Rain', 'description':'moderate rain', 'icon':'10d' }], 'speed':4.32, 'deg':189, 'clouds':100, 'rain':9.37 }] };
|
|
|
|
const wResult = [
|
|
{
|
|
'date': '2/10',
|
|
'datelong': '2017-10-02T13:00:00+01:00',
|
|
'day': 'Mon',
|
|
'icon': 'wi-owm-500',
|
|
'summary': 'light rain',
|
|
'tempHigh': 10,
|
|
'tempLow': 9,
|
|
'time': 1506945600,
|
|
'timestamp': 1506945600
|
|
},
|
|
{
|
|
'date': '3/10',
|
|
'datelong': '2017-10-03T13:00:00+01:00',
|
|
'day': 'Tue',
|
|
'icon': 'wi-owm-500',
|
|
'summary': 'light rain',
|
|
'tempHigh': 11,
|
|
'tempLow': 9,
|
|
'time': 1507032000,
|
|
'timestamp': 1507032000
|
|
},
|
|
{
|
|
'date': '4/10',
|
|
'datelong': '2017-10-04T13:00:00+01:00',
|
|
'day': 'Wed',
|
|
'icon': 'wi-owm-501',
|
|
'summary': 'moderate rain',
|
|
'tempHigh': 10,
|
|
'tempLow': 8,
|
|
'time': 1507118400,
|
|
'timestamp': 1507118400
|
|
},
|
|
{
|
|
'date': '5/10',
|
|
'datelong': '2017-10-05T13:00:00+01:00',
|
|
'day': 'Thu',
|
|
'icon': 'wi-owm-500',
|
|
'summary': 'light rain',
|
|
'tempHigh': 10,
|
|
'tempLow': 5,
|
|
'time': 1507204800,
|
|
'timestamp': 1507204800
|
|
},
|
|
{
|
|
'date': '6/10',
|
|
'datelong': '2017-10-06T13:00:00+01:00',
|
|
'day': 'Fri',
|
|
'icon': 'wi-owm-501',
|
|
'summary': 'moderate rain',
|
|
'tempHigh': 12,
|
|
'tempLow': 5,
|
|
'time': 1507291200,
|
|
'timestamp': 1507291200
|
|
}
|
|
];
|
|
|
|
describe('Weather Collection', () => {
|
|
let collection;
|
|
|
|
sinon.stub(Backbone, 'sync').yieldsTo('success', wData);
|
|
|
|
beforeEach(() => {
|
|
collection = new WCollection();
|
|
});
|
|
|
|
it('should create an empty collection', () => {
|
|
expect(collection.length).to.be(0);
|
|
});
|
|
|
|
it('Should fetch the data', () => {
|
|
collection.fetch();
|
|
expect(collection.length).to.be(5);
|
|
});
|
|
|
|
it('Should reduce the data', () => {
|
|
collection.fetch();
|
|
expect(collection.toJSON()).to.eql(wResult);
|
|
});
|
|
});
|
|
|