Skip to content

Commit

Permalink
feat: #465 add Giveaway as defined in api 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bernard-ng committed Aug 1, 2024
1 parent d9d4fe5 commit 6ebd05c
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Types/GiveawayCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use TelegramBot\Api\BaseType;
use TelegramBot\Api\TypeInterface;

/**
* Class GiveawayCreated.
* This object represents a service message about the creation of a scheduled giveaway.
* Currently holds no information.
*/
class GiveawayCreated extends BaseType implements TypeInterface
{
}
39 changes: 39 additions & 0 deletions tests/Types/ArrayOfChatTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace TelegramBot\Api\Test\Types;

use TelegramBot\Api\Types\Chat;
use TelegramBot\Api\Types\ArrayOfChat;
use PHPUnit\Framework\TestCase;

class ArrayOfChatTest extends TestCase
{
public function testFromResponse()
{
$items = ArrayOfChat::fromResponse([
[
'id' => 123456789,
'type' => 'group',
],
[
'id' => 123456788,
'type' => 'private',
]
]);

$expected = [
Chat::fromResponse([
'id' => 123456789,
'type' => 'group',
]),
Chat::fromResponse([
'id' => 123456788,
'type' => 'private',
])
];

foreach ($items as $key => $item) {
$this->assertEquals($expected[$key], $item);
}
}
}
42 changes: 42 additions & 0 deletions tests/Types/GiveawayCompletedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace TelegramBot\Api\Test\Types;

use TelegramBot\Api\Test\AbstractTypeTest;
use TelegramBot\Api\Types\GiveawayCompleted;

class GiveawayCompletedTest extends AbstractTypeTest
{
protected static function getType()
{
return GiveawayCompleted::class;
}

public static function getMinResponse()
{
return [
'winner_count' => 1
];
}

public static function getFullResponse()
{
return [
'winner_count' => 1,
'unclaimed_prize_count' => 1,
'giveaway_message' => MessageTest::getMinResponse()
];
}

protected function assertMinItem($item)
{
$this->assertEquals(1, $item->getWinnerCount());
}

protected function assertFullItem($item)
{
$this->assertEquals(1, $item->getWinnerCount());
$this->assertEquals(1, $item->getUnclaimedPrizeCount());
$this->assertEquals(MessageTest::createMinInstance(), $item->getGiveawayMessage());
}
}
32 changes: 32 additions & 0 deletions tests/Types/GiveawayCreatedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace TelegramBot\Api\Test\Types;

use TelegramBot\Api\Test\AbstractTypeTest;
use TelegramBot\Api\Types\GiveawayCreated;

class GiveawayCreatedTest extends AbstractTypeTest
{
protected static function getType()
{
return GiveawayCreated::class;
}

public static function getMinResponse()
{
return [];
}

public static function getFullResponse()
{
return [];
}

protected function assertMinItem($item)
{
}

protected function assertFullItem($item)
{
}
}
66 changes: 66 additions & 0 deletions tests/Types/GiveawayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace TelegramBot\Api\Test\Types;

use TelegramBot\Api\Types\Giveaway;
use TelegramBot\Api\Test\AbstractTypeTest;

class GiveawayTest extends AbstractTypeTest
{
protected static function getType()
{
return Giveaway::class;
}

public static function getMinResponse()
{
return [
'chats' => [
ChatTest::getMinResponse()
],
'winners_selection_date' => 1682343643,
'winner_count' => 1,
];
}

public static function getFullResponse()
{
return [
'chats' => [
ChatTest::getMinResponse()
],
'winners_selection_date' => 1682343643,
'winner_count' => 1,
'only_new_members' => true,
'has_public_winners' => true,
'prize_description' => 'prize',
'country_codes' => ['RU'],
'premium_subscription_month_count' => 1,
];
}

protected function assertMinItem($item)
{
$this->assertEquals(1, $item->getWinnerCount());
$this->assertEquals(1682343643, $item->getWinnersSelectionDate());
$this->assertIsArray($item->getChats());

$this->assertNull($item->getOnlyNewMembers());
$this->assertNull($item->getHasPublicWinners());
$this->assertNull($item->getPrizeDescription());
$this->assertNull($item->getCountryCodes());
$this->assertNull($item->getPremiumSubscriptionMonthCount());
}

protected function assertFullItem($item)
{
$this->assertEquals(1, $item->getWinnerCount());
$this->assertEquals(1682343643, $item->getWinnersSelectionDate());
$this->assertIsArray($item->getChats());
$this->assertTrue($item->getOnlyNewMembers());
$this->assertTrue($item->getHasPublicWinners());
$this->assertEquals('prize', $item->getPrizeDescription());
$this->assertIsArray($item->getCountryCodes());
$this->assertEquals(1, $item->getPremiumSubscriptionMonthCount());
}
}
74 changes: 74 additions & 0 deletions tests/Types/GiveawayWinnersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace TelegramBot\Api\Test\Types;

use TelegramBot\Api\Test\AbstractTypeTest;
use TelegramBot\Api\Types\GiveawayWinners;

class GiveawayWinnersTest extends AbstractTypeTest
{
protected static function getType()
{
return GiveawayWinners::class;
}

public static function getMinResponse()
{
return [
'chat' => ChatTest::getMinResponse(),
'giveaway_message_id' => 1,
'winners_selection_date' => 1682343643,
'winner_count' => 1,
'winners' => [
UserTest::getMinResponse()
],
];
}

public static function getFullResponse()
{
return [
'chat' => ChatTest::getMinResponse(),
'giveaway_message_id' => 1,
'winners_selection_date' => 1682343643,
'winner_count' => 1,
'winners' => [
UserTest::getMinResponse()
],
'additional_chat_count' => 1,
'premium_subscription_month_count' => 1,
'unclaimed_prize_count' => 0,
'only_new_members' => true,
'was_refunded' => true,
'prize_description' => 'prize',
];
}

protected function assertMinItem($item)
{
$this->assertEquals(1, $item->getGiveawayMessageId());
$this->assertEquals(1682343643, $item->getWinnersSelectionDate());
$this->assertEquals(1, $item->getWinnerCount());
$this->assertEquals([UserTest::createMinInstance()], $item->getWinners());
$this->assertNull($item->getAdditionalChatCount());
$this->assertNull($item->getPremiumSubscriptionMonthCount());
$this->assertNull($item->getUnclaimedPrizeCount());
$this->assertNull($item->getOnlyNewMembers());
$this->assertNull($item->getWasRefunded());
$this->assertNull($item->getPrizeDescription());
}

protected function assertFullItem($item)
{
$this->assertEquals(1, $item->getGiveawayMessageId());
$this->assertEquals(1682343643, $item->getWinnersSelectionDate());
$this->assertEquals(1, $item->getWinnerCount());
$this->assertEquals([UserTest::createMinInstance()], $item->getWinners());
$this->assertEquals(1, $item->getAdditionalChatCount());
$this->assertEquals(1, $item->getPremiumSubscriptionMonthCount());
$this->assertEquals(0, $item->getUnclaimedPrizeCount());
$this->assertTrue($item->getOnlyNewMembers());
$this->assertTrue($item->getWasRefunded());
$this->assertEquals('prize', $item->getPrizeDescription());
}
}

0 comments on commit 6ebd05c

Please sign in to comment.