Skip to content

Commit

Permalink
refactor: notification rest schema
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhooks committed Apr 21, 2023
1 parent 3f50c0c commit 27d5be9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 37 deletions.
96 changes: 61 additions & 35 deletions includes/restapi/class-notification-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
);
Expand Down
7 changes: 5 additions & 2 deletions tests/phpunit/tests/rest-api/test-notification-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 27d5be9

Please sign in to comment.