Skip to content

Commit

Permalink
update tests for calendars, contacts, events, deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlin committed Sep 27, 2021
1 parent 185ac29 commit 22a9a2f
Show file tree
Hide file tree
Showing 13 changed files with 966 additions and 320 deletions.
26 changes: 16 additions & 10 deletions src/Calendars/Availability.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(Options $options)
*/
public function availabilityForASingleMeeting(array $params = []): array
{
V::doValidate($this->getMeetingRules(), $params);
V::doValidate($this->getMeetingRules(true), $params);

return $this->options
->getSync()
Expand All @@ -74,7 +74,7 @@ public function availabilityForASingleMeeting(array $params = []): array
*/
public function availabilityForMultipleMeetings(array $params = []): array
{
V::doValidate($this->getMeetingRules(), $params);
V::doValidate($this->getMeetingRules(false), $params);

return $this->options
->getSync()
Expand All @@ -88,8 +88,14 @@ public function availabilityForMultipleMeetings(array $params = []): array
/**
* @return \Nylas\Utilities\Validator
*/
private function getMeetingRules(): V
private function getMeetingRules(bool $single): V
{
$emailsRules = match ($single)
{
true => V::simpleArray(V::email()),
false => V::simpleArray(V::simpleArray(V::email())),
};

$timeSlot = V::keySet(
V::key('object', V::stringType()->notEmpty()),
V::key('status', V::stringType()->notEmpty()),
Expand All @@ -98,28 +104,28 @@ private function getMeetingRules(): V
);

$freeBusy = V::keySet(
V::key('object', V::stringType()->notEmpty()),
V::key('email', V::email()),
V::key('time_slot', V::simpleArray($timeSlot)),
V::key('object', V::stringType()->notEmpty()),
V::key('time_slots', V::simpleArray($timeSlot)),
);

$openHours = V::keySet(
V::key('end', V::anyOf(V::equals(0), V::time('H:i'))),
V::key('start', V::anyOf(V::equals(0), V::time('H:i'))),
V::key('end', V::time('H:i')),
V::key('start', V::time('H:i')),
V::key('days', V::simpleArray(V::in(['0', '1', '2', '3', '4', '5', '6']))),
V::key('emails', V::simpleArray(V::email())),
V::key('emails', $emailsRules),
V::key('timezone', V::in(DateTimeZone::listIdentifiers())),
V::key('object_type', V::equals('open_hours')),
);

return V::keySet(
V::key('emails', V::simpleArray(V::email())),
V::key('emails', $emailsRules),
V::key('end_time', V::timestampType()),
V::key('start_time', V::timestampType()),
V::key('free_busy', V::simpleArray($freeBusy)),
V::key('open_hours', V::simpleArray($openHours), false),
V::key('interval_minutes', V::intType()),
V::key('duration_minutes', V::intType()),
V::keyOptional('open_hours', V::simpleArray($openHours)),
);
}

Expand Down
10 changes: 7 additions & 3 deletions src/Calendars/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,15 @@ public function deleteACalendar(mixed $calendarId): array
public function calendarFreeOrBusy(array $params = []): array
{
V::doValidate(V::keySet(
V::keyOptional('end_time', V::timestampType()),
V::keyOptional('start_time', V::timestampType()),
V::keyOptional('emails', V::simpleArray(V::email()))
V::key('end_time', V::timestampType()),
V::key('start_time', V::timestampType()),
V::key('emails', V::simpleArray(V::email()))
), $params);

// @todo the nylas docs require to pass Unix timestamp as a string, ball shit!
$params['end_time'] = (string) $params['end_time'];
$params['start_time'] = (string) $params['start_time'];

return $this->options
->getSync()
->setFormParams($params)
Expand Down
9 changes: 6 additions & 3 deletions src/Contacts/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function updateAContact(string $contactId, array $params): array
*
* @return array
*/
public function deleteContact(mixed $contactId): array
public function deleteAContact(mixed $contactId): array
{
$contactId = Helper::fooToArray($contactId);

Expand Down Expand Up @@ -213,7 +213,10 @@ public function returnsAContactsPicture(array $params): array
};
}

return $this->options->getAsync()->pool($queues, true);
$picId = Helper::generateArray($downloadArr, 'id');
$pools = $this->options->getAsync()->pool($queues, true);

return Helper::concatPoolInfos($picId, $pools);
}

// ------------------------------------------------------------------------------
Expand All @@ -225,7 +228,7 @@ public function returnsAContactsPicture(array $params): array
*
* @return array
*/
public function getContactGroups(): array
public function returnContactGroups(): array
{
return $this->options
->getSync()
Expand Down
2 changes: 1 addition & 1 deletion src/Drafts/Draft.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private function arrayOfObject(): V
return V::simpleArray(
V::keySet(
V::key('email', V::email()),
V::key('name', V::stringType(), false)
V::key('name', V::stringType()->notEmpty())
)
);
}
Expand Down
101 changes: 51 additions & 50 deletions src/Events/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class Validation
public static function getEventRules(): V
{
return V::keySet(
V::key('when', self::timeRules()),
V::key('when', self::whenRules()),
V::key('calendar_id', V::stringType()->notEmpty()),
V::keyOptional('busy', V::boolType()),
V::keyOptional('read_only', V::boolType()),
V::keyOptional('title', V::stringType()->notEmpty()),
V::keyOptional('read_only', V::boolType()),
V::keyOptional('location', V::stringType()->notEmpty()),
V::keyOptional('metadata', V::arrayType()),
V::keyOptional('recurrence', self::recurrenceRules()),
Expand Down Expand Up @@ -110,30 +110,32 @@ private static function participantsRules(): V
// ------------------------------------------------------------------------------

/**
* get event time rules
* get event when rules
*
* @return \Nylas\Utilities\Validator
*/
private static function timeRules(): V
private static function whenRules(): V
{
return V::anyOf(
// time
V::keySet(V::key('time', V::timestampType())),
V::keySet(V::keyOptional('time', V::timestampType())),

// date
V::keySet(V::key('date', V::date('Y-m-d'))),
V::keySet(V::keyOptional('date', V::date('Y-m-d'))),

// timespan
// date span
V::keySet(
V::key('end_time', V::timestampType()),
V::key('start_time', V::timestampType())
V::keyOptional('end_date', V::date('Y-m-d')),
V::keyOptional('start_date', V::date('Y-m-d'))
),

// date span
// timespan
V::keySet(
V::key('end_date', V::date('Y-m-d')),
V::key('start_date', V::date('Y-m-d'))
)
V::keyOptional('end_time', V::timestampType()),
V::keyOptional('start_time', V::timestampType()),
V::keyOptional('end_timezone', V::in(DateTimeZone::listIdentifiers())),
V::keyOptional('start_timezone', V::in(DateTimeZone::listIdentifiers()))
),
);
}

Expand All @@ -146,24 +148,24 @@ private static function timeRules(): V
*/
private static function notificationRules(): V
{
return V::each(V::oneOf(
V::keySet(V::key('sms', V::keySet(
V::key('type', V::equals('sms')),
V::key('message', V::stringType()->notEmpty()),
V::key('minutes_before_events', V::intType()),
))),
V::keySet(V::key('email', V::keySet(
V::key('type', V::equals('email')),
V::key('body', V::stringType()->notEmpty()),
V::key('subject', V::stringType()->notEmpty()),
V::key('minutes_before_events', V::intType()),
))),
V::keySet(V::key('webhooks', V::keySet(
V::key('url', V::url()),
V::key('type', V::equals('webhook')),
V::key('payload', V::stringType()->notEmpty()),
V::key('minutes_before_events', V::intType()),
))),
return V::each(V::anyOf(
V::keySet(
V::keyOptional('type', V::equals('sms')),
V::keyOptional('message', V::stringType()->notEmpty()),
V::keyOptional('minutes_before_events', V::intType()),
),
V::keySet(
V::keyOptional('type', V::equals('email')),
V::keyOptional('body', V::stringType()->notEmpty()),
V::keyOptional('subject', V::stringType()->notEmpty()),
V::keyOptional('minutes_before_events', V::intType()),
),
V::keySet(
V::keyOptional('url', V::url()),
V::keyOptional('type', V::equals('webhook')),
V::keyOptional('payload', V::stringType()->notEmpty()),
V::keyOptional('minutes_before_events', V::intType()),
),
));
}

Expand All @@ -176,49 +178,48 @@ private static function notificationRules(): V
*/
private static function conferenceRules(): V
{
$autocreate = V::keySet(
V::key('provider', V::in(['Google Meet', 'Zoom Meeting'])),
V::key('autocreate', V::arrayType()),
);

$webEx = V::keySet(
V::key('provider', V::equals('WebEx')),
V::key('details', V::keySet(
V::key('password', V::stringType()),
V::key('pin', V::stringType()),
V::key('url', V::stringType())
V::keyOptional('password', V::stringType()),
V::keyOptional('pin', V::stringType()),
V::keyOptional('url', V::stringType())
))
);

$zoomMeeting = V::keySet(
V::key('provider', V::equals('Zoom Meeting')),
V::key('details', V::keySet(
V::key('meeting_code', V::stringType()),
V::key('password', V::stringType()),
V::key('url', V::stringType()),
V::keyOptional('meeting_code', V::stringType()),
V::keyOptional('password', V::stringType()),
V::keyOptional('url', V::stringType()),
))
);

$goToMeeting = V::keySet(
V::key('provider', V::equals('GoToMeeting')),
V::key('details', V::keySet(
V::key('meeting_code', V::stringType()),
V::key('phone', V::simpleArray()),
V::key('url', V::stringType()),
V::keyOptional('meeting_code', V::stringType()),
V::keyOptional('phone', V::simpleArray()),
V::keyOptional('url', V::stringType()),
))
);

$googleMeet = V::keySet(
V::key('provider', V::equals('Google Meet')),
V::key('details', V::keySet(
V::key('phone', V::simpleArray()),
V::key('pin', V::stringType()),
V::key('url', V::stringType()),
V::keyOptional('phone', V::simpleArray()),
V::keyOptional('pin', V::stringType()),
V::keyOptional('url', V::stringType()),
))
);

return V::oneOf(
V::keySet(V::key('details', V::oneOf($webEx, $zoomMeeting, $goToMeeting, $googleMeet))),
V::keySet(V::key('autocreate', V::keySet(
V::key('provider', V::in(['Google Meet', 'Zoom Meeting'])),
V::key('autocreate', V::arrayType()),
))),
);
return V::anyOf($autocreate, $webEx, $zoomMeeting, $goToMeeting, $googleMeet);
}

// ------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Request/AbsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function setFormFiles(array $files) : self
/**
* set header params
*
* @see https://docs.nylas.com/docs/using-access-tokens
* @see https://developer.nylas.com/docs/the-basics/authentication/authorizing-api-requests/
*
* @param array $headers
*
Expand Down
Loading

0 comments on commit 22a9a2f

Please sign in to comment.