|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Hypernode\Api\Service; |
| 6 | + |
| 7 | +use GuzzleHttp\Psr7\Response; |
| 8 | +use Hypernode\Api\HypernodeClientTestCase; |
| 9 | +use Hypernode\Api\Resource\Logbook\Flow; |
| 10 | + |
| 11 | +class LogbookTest extends HypernodeClientTestCase |
| 12 | +{ |
| 13 | + public function testGetListFetchesLogbook() |
| 14 | + { |
| 15 | + $this->responses->append( |
| 16 | + new Response(200, [], json_encode([ |
| 17 | + 'count' => 2, |
| 18 | + 'next' => null, |
| 19 | + 'previous' => null, |
| 20 | + 'results' => [ |
| 21 | + [ |
| 22 | + 'uuid' => 'c130c04f-794e-4f55-b34b-eb8f60472224', |
| 23 | + 'state' => 'running', |
| 24 | + 'name' => 'update_node', |
| 25 | + 'created_at' => '2022-09-12T12:19:15Z', |
| 26 | + 'updated_at' => '2022-09-12T12:20:30Z', |
| 27 | + 'logbook' => 'johndoe', |
| 28 | + ], |
| 29 | + [ |
| 30 | + 'uuid' => 'e2f39684-3ce0-48d1-acda-13fa064709b5', |
| 31 | + 'state' => 'success', |
| 32 | + 'name' => 'create_backup', |
| 33 | + 'created_at' => '2022-09-12T11:08:10Z', |
| 34 | + 'updated_at' => '2022-09-12T11:08:27Z', |
| 35 | + 'logbook' => 'johndoe', |
| 36 | + ], |
| 37 | + ] |
| 38 | + ])), |
| 39 | + ); |
| 40 | + |
| 41 | + $flows = $this->client->logbook->getList('johndoe'); |
| 42 | + [$flow1, $flow2] = $flows; |
| 43 | + |
| 44 | + $this->assertCount(2, $flows); |
| 45 | + |
| 46 | + $this->assertInstanceOf(Flow::class, $flow1); |
| 47 | + $this->assertEquals('running', $flow1->state); |
| 48 | + $this->assertEquals('update_node', $flow1->name); |
| 49 | + |
| 50 | + $this->assertInstanceOf(Flow::class, $flow2); |
| 51 | + $this->assertEquals('success', $flow2->state); |
| 52 | + $this->assertEquals('create_backup', $flow2->name); |
| 53 | + } |
| 54 | + |
| 55 | + public function testGetListPagesThroughLogbook() |
| 56 | + { |
| 57 | + $this->responses->append( |
| 58 | + new Response(200, [], json_encode([ |
| 59 | + 'count' => 1, |
| 60 | + 'next' => 'https://api.hypernode.com/logbook/v1/logbooks/johndoe/flows/', |
| 61 | + 'previous' => null, |
| 62 | + 'results' => [ |
| 63 | + [ |
| 64 | + 'uuid' => 'c130c04f-794e-4f55-b34b-eb8f60472224', |
| 65 | + 'state' => 'running', |
| 66 | + 'name' => 'update_node', |
| 67 | + 'created_at' => '2022-09-12T12:19:15Z', |
| 68 | + 'updated_at' => '2022-09-12T12:20:30Z', |
| 69 | + 'logbook' => 'johndoe', |
| 70 | + ], |
| 71 | + ] |
| 72 | + ])), |
| 73 | + new Response(200, [], json_encode([ |
| 74 | + 'count' => 1, |
| 75 | + 'next' => null, |
| 76 | + 'previous' => null, |
| 77 | + 'results' => [ |
| 78 | + [ |
| 79 | + 'uuid' => 'e2f39684-3ce0-48d1-acda-13fa064709b5', |
| 80 | + 'state' => 'success', |
| 81 | + 'name' => 'create_backup', |
| 82 | + 'created_at' => '2022-09-12T11:08:10Z', |
| 83 | + 'updated_at' => '2022-09-12T11:08:27Z', |
| 84 | + 'logbook' => 'johndoe', |
| 85 | + ], |
| 86 | + ] |
| 87 | + ])), |
| 88 | + ); |
| 89 | + |
| 90 | + $flows = $this->client->logbook->getList('johndoe'); |
| 91 | + [$flow1, $flow2] = $flows; |
| 92 | + |
| 93 | + $this->assertCount(2, $flows); |
| 94 | + |
| 95 | + $this->assertInstanceOf(Flow::class, $flow1); |
| 96 | + $this->assertEquals('running', $flow1->state); |
| 97 | + $this->assertEquals('update_node', $flow1->name); |
| 98 | + |
| 99 | + $this->assertInstanceOf(Flow::class, $flow2); |
| 100 | + $this->assertEquals('success', $flow2->state); |
| 101 | + $this->assertEquals('create_backup', $flow2->name); |
| 102 | + } |
| 103 | +} |
0 commit comments