Files
wehub-resource-sync 4ce4204b6c
CI / Lint (push) Failing after 2s
CI / Build (push) Has been skipped
SDK CI / PHP SDK (push) Failing after 1s
Split PHP SDK / PHP SDK tests (push) Failing after 1s
CI / Test (push) Failing after 1s
CI / Dashboard (push) Failing after 0s
SDK CI / JavaScript SDK (push) Failing after 0s
SDK CI / Python SDK (push) Failing after 2s
SDK CI / Java SDK (push) Failing after 1s
Split PHP SDK / Mirror sdk/php -> rmyndharis/openwa-php (push) Has been skipped
CI / Test (PostgreSQL migrations) (push) Failing after 7m47s
CI / Docker Build (push) Has been skipped
chore: import upstream snapshot with attribution
2026-07-13 12:24:08 +08:00

40 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace OpenWA\Tests;
use PHPUnit\Framework\TestCase;
class TemplatesTest extends TestCase
{
public function testCrudPaths(): void
{
$tpl = ['id' => 't1', 'sessionId' => 's', 'name' => 'welcome', 'body' => 'Hi {{name}}'];
$backend = new MockBackend();
$backend->on(200, [$tpl]); // list
$backend->on(200, $tpl); // get
$backend->on(201, $tpl); // create
$backend->on(200, ['...' => 1] + $tpl); // update
$backend->on(204); // delete
$client = $backend->makeClient();
$client->templates->list('s');
$this->assertSame('/api/sessions/s/templates', $backend->calls()[0]['path']);
$client->templates->get('s', 't1');
$this->assertSame('/api/sessions/s/templates/t1', $backend->calls()[1]['path']);
$client->templates->create('s', ['name' => 'welcome', 'body' => 'Hi {{name}}']);
$this->assertSame('POST', $backend->calls()[2]['method']);
$this->assertSame(['name' => 'welcome', 'body' => 'Hi {{name}}'], $backend->calls()[2]['body']);
$client->templates->update('s', 't1', ['body' => 'Hello {{name}}']);
$this->assertSame('PUT', $backend->calls()[3]['method']);
$this->assertSame(['body' => 'Hello {{name}}'], $backend->calls()[3]['body']);
$client->templates->delete('s', 't1');
$this->assertSame('DELETE', $backend->lastCall()['method']);
}
}