File size: 1,573 Bytes
46252cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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']);
    }
}