I am trying to write a test to verify that in my response, the time_utc is incrementing by 1 hour for every array and i am expecting to see for 8 days.
As of now my console is giving my for only 24 hours.
Need help to clean up the script.
Below is the response body i am trying to acheive, when i write the script:
"date": "2021-03-25",
"1hourly": [
{
"time_utc": "2021-03-24T23:00:00Z",
"atm": {
"surf_air": {
"temp_apparent_cel": null,
"temp_dew_pt_cel": null,
"temp_cel": null,
"hum_relative_percent": null,
"wind": {
"hazardous_onset_code": null,
"dirn_10m_deg_t": null,
"speed_10m_avg_mps": null,
"gust_speed_10m_max_mps": null,
"mixing_height_m": null
}
}
}
},
{
"time_utc": "2021-03-25T00:00:00Z",
"atm": {
"surf_air": {
"temp_apparent_cel": null,
"temp_dew_pt_cel": null,
"temp_cel": null,
"hum_relative_percent": null,
"wind": {
"hazardous_onset_code": null,
"dirn_10m_deg_t": null,
"speed_10m_avg_mps": null,
"gust_speed_10m_max_mps": null,
"mixing_height_m": null
}
Postman script written as below:
for(var i = 0; i < forecast.length; i++)
{
pm.expect(forecast[i]).to.have.property('date');
pm.expect(forecast[i]).to.have.property('1hourly');
var one_hourly = forecast[i]["1hourly"];
for(var k = 0; k < one_hourly.length; k++)
{
console.log(one_hourly)
//the difference between start and end time should be 1 hour as it is 1hourly forecast
var start_time_utc = moment(one_hourly[k].time_utc);
var end_time_utc = moment(one_hourly[k+1].time_utc);
console.log(start_time_utc, end_time_utc);
var duration = moment.duration(end_time_utc.diff(start_time_utc)).asHours();
console.log (duration);
pm.expect(duration).to.eql(1);