Skip to content

Commit

Permalink
Recording response errors (#181)
Browse files Browse the repository at this point in the history
* Add not found errors

* Deprecate isInvalidId

* Add tests

* Add errors to PutRecordingTextTrackResponse

* Make json responses behavior same as xml responses

* Add/adjust tests

* Added mssing return type hints

---------

Co-authored-by: Felix Jacobi <felix@jacobi-hamburg.net>
  • Loading branch information
SamuelWei and FelixJacobi committed Mar 3, 2024
1 parent f217d82 commit 2ee1140
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 16 deletions.
18 changes: 5 additions & 13 deletions src/Responses/BaseResponseAsJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,19 @@ public function getRawArray(): array
return json_decode(json_encode($this->data), true);
}

public function getMessage(): ?string
public function getMessage(): string
{
if ($this->failed()) {
return $this->data->response->message;
}

return null;
return $this->data->response->message ?? '';
}

public function getMessageKey(): ?string
public function getMessageKey(): string
{
if ($this->failed()) {
return $this->data->response->messageKey;
}

return null;
return $this->data->response->messageKey ?? '';
}

public function getReturnCode(): string
{
return $this->data->response->returncode;
return $this->data->response->returncode ?? '';
}

public function success(): bool
Expand Down
9 changes: 9 additions & 0 deletions src/Responses/DeleteRecordingsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,24 @@
*/
class DeleteRecordingsResponse extends BaseResponse
{
/** @deprecated and will be removed in 6.0. Use KEY_NOT_FOUND instead */
public const KEY_INVALID_ID = 'InvalidRecordingId';

public const KEY_NOT_FOUND = 'notFound';

public function isDeleted(): bool
{
return $this->rawXml->deleted->__toString() == 'true';
}

/** @deprecated and will be removed in 6.0. Use isNotFound instead */
public function isInvalidId(): bool
{
return $this->getMessageKey() === self::KEY_INVALID_ID;
}

public function isNotFound(): bool
{
return $this->getMessageKey() === self::KEY_NOT_FOUND;
}
}
7 changes: 7 additions & 0 deletions src/Responses/PublishRecordingsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@
*/
class PublishRecordingsResponse extends BaseResponse
{
public const KEY_NOT_FOUND = 'notFound';

public function isPublished(): bool
{
return $this->rawXml->published->__toString() === 'true';
}

public function isNotFound(): bool
{
return $this->getMessageKey() === self::KEY_NOT_FOUND;
}
}
20 changes: 19 additions & 1 deletion src/Responses/PutRecordingTextTrackResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ class PutRecordingTextTrackResponse extends BaseResponseAsJson
public const KEY_SUCCESS = 'upload_text_track_success';
public const KEY_FAILED = 'upload_text_track_failed';
public const KEY_EMPTY = 'empty_uploaded_text_track';
public const KEY_NO_RECORDINGS = 'noRecordings';
public const KEY_INVALID_KIND = 'invalidKind';
public const KEY_INVALID_LANG = 'invalidLang';
public const KEY_PARAM_ERROR = 'paramError';

public function getRecordID(): string
{
return $this->data->response->recordId;
return $this->data->response->recordId ?? '';
}

public function isUploadTrackSuccess(): bool
Expand All @@ -49,6 +52,21 @@ public function isUploadTrackEmpty(): bool
return $this->getMessageKey() === self::KEY_EMPTY;
}

public function isNoRecordings(): bool
{
return $this->getMessageKey() === self::KEY_NO_RECORDINGS;
}

public function isInvalidLang(): bool
{
return $this->getMessageKey() === self::KEY_INVALID_LANG;
}

public function isInvalidKind(): bool
{
return $this->getMessageKey() === self::KEY_INVALID_KIND;
}

public function isKeyParamError(): bool
{
return $this->getMessageKey() === self::KEY_PARAM_ERROR;
Expand Down
7 changes: 7 additions & 0 deletions src/Responses/UpdateRecordingsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@
*/
class UpdateRecordingsResponse extends BaseResponse
{
public const KEY_NOT_FOUND = 'notFound';

public function isUpdated(): bool
{
return $this->rawXml->updated->__toString() === 'true';
}

public function isNotFound(): bool
{
return $this->getMessageKey() === self::KEY_NOT_FOUND;
}
}
5 changes: 5 additions & 0 deletions tests/fixtures/not_found_error.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<response>
<returncode>FAILED</returncode>
<messageKey>notFound</messageKey>
<message>We could not find recordings</message>
</response>
4 changes: 2 additions & 2 deletions tests/unit/BigBlueButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ public function testPutRecordingTextTrack(): void
$response = $this->bbb->putRecordingTextTrack($params);

$this->assertTrue($response->success());
$this->assertNull($response->getMessageKey());
$this->assertNull($response->getMessage());
$this->assertEquals('upload_text_track_success', $response->getMessageKey());
$this->assertEquals('Text track uploaded successfully', $response->getMessage());
$this->assertSame('baz', $response->getRecordID());
$this->assertSame('SUCCESS', $response->getReturnCode());
}
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/Responses/DeleteRecordingsResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ public function testDeleteRecordingsResponseTypes()
$this->assertEachGetterValueIsString($this->delete, ['getReturnCode']);
$this->assertEachGetterValueIsBoolean($this->delete, ['isDeleted']);
}

public function testNotFoundError(): void
{
$xml = $this->loadXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'not_found_error.xml');

$delete = new DeleteRecordingsResponse($xml);

$this->assertTrue($delete->failed());
$this->assertTrue($delete->isNotFound());
}
}
10 changes: 10 additions & 0 deletions tests/unit/Responses/PublishRecordingsResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ public function testPublishRecordingsResponseTypes()
$this->assertEachGetterValueIsString($this->publish, ['getReturnCode']);
$this->assertEachGetterValueIsBoolean($this->publish, ['isPublished']);
}

public function testNotFoundError(): void
{
$xml = $this->loadXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'not_found_error.xml');

$publish = new PublishRecordingsResponse($xml);

$this->assertTrue($publish->failed());
$this->assertTrue($publish->isNotFound());
}
}
144 changes: 144 additions & 0 deletions tests/unit/Responses/PutRecordingTextTrackResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/

namespace BigBlueButton\Parameters;

use BigBlueButton\Responses\PutRecordingTextTrackResponse;
use BigBlueButton\TestCase;

final class PutRecordingTextTrackResponseTest extends TestCase
{
public function testUploadSuccess(): void
{
$json = '{
"response": {
"messageKey": "upload_text_track_success",
"message": "Text track uploaded successfully",
"recordId": "baz",
"returncode": "SUCCESS"
}
}';

$response = new PutRecordingTextTrackResponse($json);

$this->assertTrue($response->success());
$this->assertEquals('baz', $response->getRecordID());
$this->assertTrue($response->isUploadTrackSuccess());
}

public function testUploadFailed(): void
{
$json = '{
"response": {
"messageKey": "upload_text_track_failed",
"message": "Text track upload failed.",
"recordId": "baz",
"returncode": "FAILED"
}
}';

$response = new PutRecordingTextTrackResponse($json);

$this->assertTrue($response->failed());
$this->assertEquals('baz', $response->getRecordID());
$this->assertTrue($response->isUploadTrackFailed());
}

public function testUploadEmpty(): void
{
$json = '{
"response": {
"messageKey": "empty_uploaded_text_track",
"message": "Empty uploaded text track.",
"returncode": "FAILED"
}
}';

$response = new PutRecordingTextTrackResponse($json);

$this->assertTrue($response->failed());
$this->assertTrue($response->isUploadTrackEmpty());
}

public function testNoRecordings(): void
{
$json = '{
"response": {
"messageKey": "noRecordings",
"message": "No recording was found for meeting-id-1234.",
"returncode": "FAILED"
}
}';

$response = new PutRecordingTextTrackResponse($json);

$this->assertTrue($response->failed());
$this->assertTrue($response->isNoRecordings());
}

public function testInvalidLang(): void
{
$json = '{
"response": {
"messageKey": "invalidLang",
"message": "Malformed lang param, received=english",
"returncode": "FAILED"
}
}';

$response = new PutRecordingTextTrackResponse($json);

$this->assertTrue($response->failed());
$this->assertTrue($response->isInvalidLang());
}

public function testInvalidKind(): void
{
$json = '{
"response": {
"messageKey": "invalidKind",
"message": "Invalid kind parameter, expected=\'subtitles|captions\' actual=somethingelse",
"returncode": "FAILED"
}
}';

$response = new PutRecordingTextTrackResponse($json);

$this->assertTrue($response->failed());
$this->assertTrue($response->isInvalidKind());
}

public function testHandleMissingJsonKeys(): void
{
$json = '{}';

$response = new PutRecordingTextTrackResponse($json);

$this->assertFalse($response->success());
$this->assertFalse($response->failed());
$this->assertFalse($response->hasChecksumError());
$this->assertEquals('', $response->getRecordID());
$this->assertFalse($response->isUploadTrackSuccess());
$this->assertFalse($response->isUploadTrackFailed());
$this->assertFalse($response->isUploadTrackEmpty());
$this->assertFalse($response->isNoRecordings());
$this->assertFalse($response->isInvalidLang());
$this->assertFalse($response->isInvalidKind());
}
}
10 changes: 10 additions & 0 deletions tests/unit/Responses/UpdateRecordingsResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ public function testUpdateRecordingsResponseTypes()
$this->assertEachGetterValueIsString($this->update, ['getReturnCode']);
$this->assertEachGetterValueIsBoolean($this->update, ['isUpdated']);
}

public function testNotFoundError(): void
{
$xml = $this->loadXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'not_found_error.xml');

$update = new UpdateRecordingsResponse($xml);

$this->assertTrue($update->failed());
$this->assertTrue($update->isNotFound());
}
}

0 comments on commit 2ee1140

Please sign in to comment.