diff --git a/lib/Webhook/WebhookUserNotFound.php b/lib/Webhook/WebhookUserNotFound.php new file mode 100644 index 0000000..9972062 --- /dev/null +++ b/lib/Webhook/WebhookUserNotFound.php @@ -0,0 +1,20 @@ +onEvent(static function (Event $event): void { - if ('ok' !== $event->type) { - throw new UserHubError("Event failed: {$event->type}", apiCode: Code::InvalidArgument); + + $webhook->onEvent(static function (Event $input): void { + if ('ok' !== $input->type) { + throw new UserHubError("Event failed: {$input->type}", apiCode: Code::InvalidArgument); + } + }); + + $webhook->onListUsers(static function (ListCustomUsersRequest $input): ListCustomUsersResponse { + if (100 !== $input->pageSize) { + throw new Error("unexpected page size {$input->pageSize}"); + } + + return new ListCustomUsersResponse(users: [], nextPageToken: ''); + }); + + $webhook->onGetUser(static function (GetCustomUserRequest $input): CustomUser { + if ('not-found' === $input->id) { + throw new WebhookUserNotFound(); } + + return new CustomUser(id: $input->id); }); if ($setTimestamp) { @@ -383,6 +405,57 @@ public static function provideHandleCases(): iterable false, true, ], + [ + 'List users', + 'test', + new WebhookRequest( + headers: [ + 'UserHub-Action' => 'users.list', + ], + body: '{"pageSize":100}', + ), + new WebhookResponse( + statusCode: 200, + body: '{"nextPageToken":"","users":[]}', + ), + true, + false, + true, + ], + [ + 'Get user', + 'test', + new WebhookRequest( + headers: [ + 'UserHub-Action' => 'users.get', + ], + body: '{"id": "1"}', + ), + new WebhookResponse( + statusCode: 200, + body: '{"id":"1","displayName":"","email":"","emailVerified":false,"phoneNumber":"","phoneNumberVerified":false,"imageUrl":"","disabled":false}', + ), + true, + false, + true, + ], + [ + 'Get user not found', + 'test', + new WebhookRequest( + headers: [ + 'UserHub-Action' => 'users.get', + ], + body: '{"id": "not-found"}', + ), + new WebhookResponse( + statusCode: 404, + body: '{"message":"User not found","code":"NOT_FOUND"}', + ), + true, + false, + true, + ], ]; } }