Skip to content

Commit

Permalink
refact: add user to share msg
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken committed Jul 28, 2024
1 parent db33e15 commit 96a249b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Domains/Social/Enums/AppEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
enum AppEnum: STRING
{
case SHAREABLE_LINK = 'APP_SHAREABLE_LINK';
case SHAREABLE_LINK_WITH_USERNAME = 'APP_SHAREABLE_LINK_WITH_USERNAME';
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public function share(UserInterface $who, ?UserInterface $to = null): string

$shareUrl = $this->message->app->get(AppEnum::SHAREABLE_LINK->value) ?? $this->message->app->url;

if ($this->message->app->get(AppEnum::SHAREABLE_LINK_WITH_USERNAME->value)) {
$shareUrl .= '/' . $this->message->user->displayname;
}

return $shareUrl . '/' . (! empty($this->message->slug) ? $this->message->slug : $this->message->getId());
}

Expand Down
46 changes: 43 additions & 3 deletions tests/GraphQL/Social/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function testMessages()
createMessage(input: $input) {
id
message
users {
user {
id
}
}
Expand All @@ -252,7 +252,7 @@ public function testMessages()
data {
message
message_types_id,
users {
user {
id
}
}
Expand All @@ -262,6 +262,46 @@ public function testMessages()
)->assertSuccessful();
}

public function testShareMessage()
{
$messageType = MessageType::factory()->create();
$message = fake()->text();
$response = $this->graphQL(
'
mutation createMessage($input: MessageInput!) {
createMessage(input: $input) {
id
message
user {
id
}
}
}
',
[
'input' => [
'message' => $message,
'message_verb' => $messageType->verb,
'system_modules_id' => 1,
'entity_id' => '1',
],
]
);

$createdMessageId = $response['data']['createMessage']['id'];

$this->graphQL(
'
mutation shareMessage($id: ID!) {
shareMessage(id: $id)
}
',
[
'id' => $createdMessageId,
]
)->assertSuccessful();
}

public function testCreateChildMessage()
{
$messageType = MessageType::factory()->create();
Expand Down Expand Up @@ -415,7 +455,7 @@ public function testGroupMessageByDate()
createMessage(input: $input) {
id
message
users {
user {
id
}
}
Expand Down

0 comments on commit 96a249b

Please sign in to comment.