Skip to content

Commit

Permalink
Merge pull request #286 from pchemali/master
Browse files Browse the repository at this point in the history
Conversation CustomField text property missing from API
  • Loading branch information
miguelrs authored Feb 18, 2022
2 parents 658c37e + 7eb8c61 commit da2db3f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Conversations/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class CustomField implements Extractable, Hydratable
*/
private $value;

/**
* @var string|null
*/
private $text;

public function hydrate(array $data, array $embedded = [])
{
if (isset($data['id'])) {
Expand All @@ -33,6 +38,7 @@ public function hydrate(array $data, array $embedded = [])

$this->setName($data['name'] ?? null);
$this->setValue($data['value'] ?? null);
$this->setText($data['text'] ?? null);
}

/**
Expand All @@ -44,6 +50,7 @@ public function extract(): array
'id' => $this->getId(),
'name' => $this->getName(),
'value' => $this->getValue(),
'text' => $this->getText(),
];

if ($this->getValue() instanceof \DateTimeInterface) {
Expand Down Expand Up @@ -96,4 +103,18 @@ public function setValue($value): self

return $this;
}

public function getText(): ?string {
return $this->text;
}

/**
* @param string|null $text
*/
public function setText($text): self
{
$this->text = $text;

return $this;
}
}
2 changes: 2 additions & 0 deletions tests/Conversations/ConversationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public function testExtract()
$this->assertInstanceOf(CustomField::class, $customField->setId(936));
$this->assertInstanceOf(CustomField::class, $customField->setName('Account Type'));
$customField->setValue('Administrator');
$customField->setText('Administrator');
$conversation->setCustomFields(new Collection([
$customField,
]));
Expand Down Expand Up @@ -349,6 +350,7 @@ public function testExtract()
'id' => 936,
'name' => 'Account Type',
'value' => 'Administrator',
'text' => 'Administrator',
]],
$extractedConversation['fields']
);
Expand Down
6 changes: 6 additions & 0 deletions tests/Conversations/CustomFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public function testHydrate()
'id' => 6688,
'name' => 'Account Type',
'value' => 'Premium',
'text' => 'Premium',
]);

$this->assertSame(6688, $customField->getId());
$this->assertSame('Account Type', $customField->getName());
$this->assertSame('Premium', $customField->getValue());
$this->assertSame('Premium', $customField->getText());
}

public function testExtract()
Expand All @@ -29,11 +31,13 @@ public function testExtract()
$this->assertInstanceOf(CustomField::class, $customField->setId(6688));
$this->assertInstanceOf(CustomField::class, $customField->setName('Account Type'));
$this->assertInstanceOf(CustomField::class, $customField->setValue('Premium'));
$this->assertInstanceOf(CustomField::class, $customField->setText('Premium'));

$this->assertSame([
'id' => 6688,
'name' => 'Account Type',
'value' => 'Premium',
'text' => 'Premium',
], $customField->extract());
}

Expand All @@ -48,6 +52,7 @@ public function testExtractFormatsDateTime()
'id' => 6688,
'name' => 'Account Type',
'value' => '2017-01-02',
'text' => null,
], $customField->extract());
}

Expand All @@ -59,6 +64,7 @@ public function testExtractNewEntity()
'id' => null,
'name' => null,
'value' => null,
'text' => null,
], $customField->extract());
}
}
2 changes: 2 additions & 0 deletions tests/Conversations/CustomFieldsCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function testExtract()
$customField->setId(936);
$customField->setName('Account Type');
$customField->setValue('Administrator');
$customField->setText('Administrator');

$customFieldsCollection->setCustomFields([
$customField,
Expand All @@ -29,6 +30,7 @@ public function testExtract()
'id' => 936,
'name' => 'Account Type',
'value' => 'Administrator',
'text' => 'Administrator',
],
],
], $customFieldsCollection->extract());
Expand Down

0 comments on commit da2db3f

Please sign in to comment.