resolveMeetingRoomFreeTime: function (session, args) {
return new Promise(function (resolve, reject) {
kgService.getFreeMeetingRooms(session.conversationData.floorEntityList,
session.conversationData.roomEntityList,
session.conversationData.meetingStartTimestamp,
session.conversationData.meetingEndTimestamp,
session.conversationData.meetingStartTime,
session.conversationData.meetingEndTime,
session.conversationData.meetingDuration)
.then(function (roomReservationList) {
**let returnResults = roomReservationList;
session.conversationData.meetingRoomAvailabilityList = roomReservationList;
setTimeout(function () { resolve(returnResults); }, 1000);**
})
.catch(function (error) {
console.log("There is error from getFreeMeetingRooms() "+error);
});
}
)
}
Method getFreeMeetingRooms() looks like as follows.
getFreeMeetingRooms: function (nearestFloorEntity, roomEntityList, startEpoch, endEpoch, startHour, endHour, meetingDuration) {
let deferred = Q.defer();
let query = function (resolve, reject) {
graphDB.cypher({
query: cypherQuery,
params: {
nearestFloorEntity, roomEntityList, startEpoch, endEpoch, startHour, endHour, meetingDuration
}
}, function (err, results) {
return deferred.resolve(results);
});
query();
return deferred.promise;
}
My test case using Mocha and Sion Stub:
it('Should return default value for resolveMeetingRoomFreeTime()', function () {
let args = {};
let session = {
conversationData: {
roomEntityList: [{ id: "ABC", name: "ABC", capacity: 8}],
floorEntityList: "9",
meetingStartTimestamp: 1521659679948,
meetingEndTimestamp: 1521781200000,
meetingStartTime: 1514815200000,
meetingEndTime: 1514847600000,
meetingDuration: 30
}
};
//stubbing call for getFreeMeetingRooms()
var stub = sinon.stub(calendarNeo4jService, "getFreeMeetingRooms")
.withArgs(session.conversationData.floorEntityList,
session.conversationData.roomEntityList,
session.conversationData.meetingStartTimestamp,
session.conversationData.meetingEndTimestamp,
session.conversationData.meetingStartTime,
session.conversationData.meetingEndTime,
session.conversationData.meetingDuration);
var error= calendarEntityResolver.resolveMeetingRoomFreeTime(session, args)
error.then(function name(params) {
})
.then(function (error) {
});
});
问题:
答案 0 :(得分:0)
我认为您正在询问如何使用mocha测试异步功能。如果这是真的,您只需要在it
函数内返回您的承诺。在标记成功之前,Mocha将等待承诺解决或拒绝,这也将允许then
函数中的断言。