Closed victorigualada closed 9 months ago
In fact, the test that should validate this behavior is broken. This is the test: https://github.com/nylas/nylas-nodejs/blob/27c7f9147d44a8f11f13884c7bb0bea43d171791/__tests__/calendar-restful-model-collection-spec.js#L161-L224
If you look at the day passed to the test in openHours
: https://github.com/nylas/nylas-nodejs/blob/27c7f9147d44a8f11f13884c7bb0bea43d171791/__tests__/calendar-restful-model-collection-spec.js#L172
It's Days.Sunday
and it's value is 6
: https://github.com/nylas/nylas-nodejs/blob/27c7f9147d44a8f11f13884c7bb0bea43d171791/src/models/calendar-availability.ts#L22
The test succeeds but is expecting that the openHours.days
is 0
(Monday)
I've found that the problem comes from this function: https://github.com/nylas/nylas-nodejs/blob/5af2a320ded4fb9c0d560a00188d9d5d73a1288b/src/models/attributes.ts#L110-L121
The function iterates over the keys of the array: for (const num in json)
. So it will return always 0
independently of the value of the array. I changed it to get the value using the key, but it breaks other tests that are dependant on this function:
if (!isNaN(Number(json[num]))) {
nums.push(Number(json[num]));
}
Thanks for opening up this issue @victorigualada, a PR has been opened to address this issue.
Describe the bug
When passing an
openHours
array to theCalendarRestfulModelCollection#availability
it wrongly parses the data and sets the same day for allopenHours
received, being0
(Monday). The error happens in the following line: https://github.com/nylas/nylas-nodejs/blob/cb42d16b3c597d4297e71303066f2266a66084ee/src/models/calendar-restful-model-collection.ts#L151 when creating instantiating theOpenHours
object.To Reproduce
Create the following
SingleAvailabilityQuery
. Note that there twoopenHours
, one for Monday (0
) and one for Tuesday (1
) :Call the
availability
method:This will return only availabilities for Monday as explained in the Bug description due to the bad parsing of
openHours
. The parsedopenHours
will be:Note how both
open_hours.days
are[0]
while they should be[0]
and[1]
Expected behavior
It should return availability for all the days passed as
openHours
SDK Version:
6.10.0