Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Api/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,18 @@ public function postUserMessage(string $conversationId, string $sender, string $

return $this->hydrator->hydrate($response, Model\Conversation\MessageCreated::class);
}

/**
* @throws Exception
*/
public function delete(string $conversationId): Model\Conversation\MessageDeleted
{
$response = $this->httpDelete("conversations/$conversationId");

if (200 !== $response->getStatusCode()) {
$this->handleErrors($response);
}

return $this->hydrator->hydrate($response, Model\Conversation\MessageDeleted::class);
}
}
9 changes: 9 additions & 0 deletions src/Model/Conversation/MessageDeleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Shapin\TalkJS\Model\Conversation;

class MessageDeleted
{
}
27 changes: 27 additions & 0 deletions tests/FunctionalTests/ConversationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Shapin\TalkJS\Tests\FunctionalTests;

use Shapin\TalkJS\Exception\Domain\NotFoundException;
use Shapin\TalkJS\Model\Conversation\Conversation;
use Shapin\TalkJS\Model\Conversation\ConversationCollection;
use Shapin\TalkJS\Model\Conversation\ConversationCreatedOrUpdated;
Expand All @@ -17,6 +18,7 @@
use Shapin\TalkJS\Model\Conversation\Message;
use Shapin\TalkJS\Model\Conversation\MessageCollection;
use Shapin\TalkJS\Model\Conversation\MessageCreated;
use Shapin\TalkJS\Model\Conversation\MessageDeleted;
use Shapin\TalkJS\Model\Conversation\ParticipationUpdated;

final class ConversationTest extends TestCase
Expand Down Expand Up @@ -145,4 +147,29 @@ public function testAll()
$this->assertSame($conversationId, $message->getConversationId());
$this->assertNull($message->getAttachment());
}

public function testShouldDeleteConversation()
{
$randomTestString = bin2hex(random_bytes(10));
$conversationId = "conversation_$randomTestString";

// create a new conversation to delete it
$this->api->createOrUpdate($conversationId, [
'participants' => ['my_user'],
'subject' => 'An amazing conversation',
'welcomeMessages' => ['Hello', 'World'],
'photoUrl' => 'photo_url',
]);

$conversation = $this->api->get($conversationId);
$this->assertEquals($conversationId, $conversation->getId());

// delete the conversation
$messageDeleted = $this->api->delete($conversationId);
$this->assertInstanceOf(MessageDeleted::class, $messageDeleted);

// unable to retrieve deleted conversation
$this->expectException(NotFoundException::class);
$conversation = $this->api->get($conversationId);
}
}