From 27d5be954c06a896691c7adaecb5af2ebaf4bc74 Mon Sep 17 00:00:00 2001 From: John Hooks Date: Fri, 21 Apr 2023 13:43:36 -0700 Subject: [PATCH] refactor: notification rest schema --- .../restapi/class-notification-controller.php | 96 ++++++++++++------- .../rest-api/test-notification-controller.php | 7 +- 2 files changed, 66 insertions(+), 37 deletions(-) diff --git a/includes/restapi/class-notification-controller.php b/includes/restapi/class-notification-controller.php index a3100cfd..6ddb3322 100644 --- a/includes/restapi/class-notification-controller.php +++ b/includes/restapi/class-notification-controller.php @@ -108,95 +108,121 @@ public function get_item_schema() { 'title' => 'notification', 'type' => 'object', 'properties' => array( - 'id' => array( - 'description' => __( 'Unique identifier for the notification.' ), - 'type' => 'integer', - 'context' => array( 'view', 'edit', 'embed' ), + 'accept_label' => array( + 'description' => __( 'The label of the accept action.' ), + 'type' => 'string', + 'context' => array( 'view', 'embed' ), 'readonly' => true, ), - 'channel_name' => array( + 'accept_link' => array( + 'description' => __( 'The URL of the accept action..' ), + 'type' => 'string', + 'context' => array( 'view', 'embed' ), + 'readonly' => true, + ), + 'channel_name' => array( 'description' => __( 'Unique identifier for the notification channel.' ), 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), + 'context' => array( 'view', 'embed' ), 'readonly' => true, ), - 'channel_title' => array( + 'channel_title' => array( 'description' => __( 'The title of the notification channel.' ), 'type' => 'string', 'context' => array( 'view', 'embed' ), 'readonly' => true, ), - 'created_at' => array( + 'context' => array( + 'description' => __( 'The view context the notification.' ), + 'type' => 'string', + 'context' => array( 'view', 'embed' ), + 'default' => 'adminbar', + 'enum' => array( + 'adminbar', + 'dashboard', + ), + 'readonly' => true, + ), + 'created_at' => array( 'description' => __( "The datetime the notification was broadcast, in the site's timezone." ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'embed' ), + 'readonly' => true, + ), + 'dismiss_label' => array( + 'description' => __( 'The label of the dismiss action.' ), + 'type' => 'string', + 'context' => array( 'view', 'embed' ), + 'readonly' => true, ), - 'dismissed_at' => array( + 'dismissed_at' => array( 'description' => __( "The datetime the notification was dismissed, in the site's timezone." ), 'type' => array( 'string', 'null' ), 'format' => 'date-time', 'context' => array( 'view', 'embed' ), ), - 'displayed_at' => array( + 'displayed_at' => array( 'description' => __( "The datetime the notification was displayed, in the site's timezone." ), 'type' => array( 'string', 'null' ), 'format' => 'date-time', 'context' => array( 'view', 'embed' ), + 'readonly' => true, ), - 'expires_at' => array( + 'expires_at' => array( 'description' => __( "The datetime the notification expires, in the site's timezone." ), 'type' => 'string', 'format' => 'date-time', + 'context' => array( 'view', 'embed' ), + 'readonly' => true, + ), + 'id' => array( + 'description' => __( 'Unique identifier for the notification.' ), + 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), - 'context' => array( - 'description' => __( 'The view context the notification.' ), + 'is_dismissible' => array( + 'description' => __( 'Whether the notification can be dismissed.' ), + 'type' => 'boolean', + 'context' => array( 'view', 'embed' ), + 'readonly' => true, + ), + 'message' => array( + 'description' => __( 'The message content of the notification.' ), 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'default' => 'hub', - 'enum' => array( - 'adminbar', - 'dashboard', - 'hub', - ), + 'context' => array( 'view', 'embed' ), + 'readonly' => true, ), - 'severity' => array( + 'severity' => array( 'description' => __( 'The severity of the notification.' ), 'type' => array( 'string', 'null' ), - 'context' => array( 'view', 'edit', 'embed' ), + 'context' => array( 'view', 'embed' ), 'enum' => array( 'alert', 'info', 'warning', 'success', ), + 'readonly' => true, ), - 'status' => array( + 'status' => array( 'description' => __( 'The status of the notification.' ), 'type' => 'string', - 'default' => 'undisplayed', 'enum' => array( 'undisplayed', 'displayed', 'dismissed', 'new', ), - ), - 'title' => array( - 'description' => __( 'The title of the notification.' ), - 'type' => 'string', 'context' => array( 'view', 'embed' ), + 'readonly' => true, ), - 'message' => array( - 'description' => __( 'The message content of the notification.' ), + 'title' => array( + 'description' => __( 'The title of the notification.' ), 'type' => 'string', 'context' => array( 'view', 'embed' ), - ), - 'meta' => array( - 'description' => __( 'The metadata of the notification.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), ), ); diff --git a/tests/phpunit/tests/rest-api/test-notification-controller.php b/tests/phpunit/tests/rest-api/test-notification-controller.php index 9d8f9a10..2ecc7e76 100644 --- a/tests/phpunit/tests/rest-api/test-notification-controller.php +++ b/tests/phpunit/tests/rest-api/test-notification-controller.php @@ -62,17 +62,20 @@ public function test_get_item_schema() { $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertCount( 13, $properties ); + $this->assertCount( 16, $properties ); + $this->assertArrayHasKey( 'accept_label', $properties ); + $this->assertArrayHasKey( 'accept_link', $properties ); $this->assertArrayHasKey( 'channel_name', $properties ); $this->assertArrayHasKey( 'channel_title', $properties ); $this->assertArrayHasKey( 'context', $properties ); $this->assertArrayHasKey( 'created_at', $properties ); + $this->assertArrayHasKey( 'dismiss_label', $properties ); $this->assertArrayHasKey( 'dismissed_at', $properties ); $this->assertArrayHasKey( 'displayed_at', $properties ); $this->assertArrayHasKey( 'expires_at', $properties ); $this->assertArrayHasKey( 'id', $properties ); + $this->assertArrayHasKey( 'is_dismissible', $properties ); $this->assertArrayHasKey( 'message', $properties ); - $this->assertArrayHasKey( 'meta', $properties ); $this->assertArrayHasKey( 'severity', $properties ); $this->assertArrayHasKey( 'status', $properties ); $this->assertArrayHasKey( 'title', $properties );