Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
Added `ProviderPlatformTest` and modified Provider Platform Controller
and Update Request per comments
  • Loading branch information
chrissantillan committed Dec 14, 2023
1 parent e6a8318 commit 17bbac8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 19 deletions.
16 changes: 0 additions & 16 deletions app/Http/Controllers/v1/ProviderPlatformController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ public function index()
return PaginateResource::make($providerPlatforms, ProviderPlatformResource::class);
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
Expand Down Expand Up @@ -56,14 +48,6 @@ public function show(ProviderPlatform $providerPlatform)
return ProviderPlatformResource::make($providerPlatform);
}

/**
* Show the form for editing the specified resource.
*/
public function edit(ProviderPlatform $providerPlatform)
{
//
}

/**
* Update the specified resource in storage.
*/
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Requests/UpdateProviderPlatformRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ public function authorize(): bool
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'name' => 'nullable|string|max:255',
'type' => 'nullable',
'type' => [Rule::enum(ProviderPlatformType::class)],
'description' => 'nullable|string|max:255',
'icon_url' => 'required|url:http,https',
'base_url' => 'required|url:http,https',
'icon_url' => 'nullable|url:http,https',
'account_id' => 'nullable',
'access_key' => 'nullable',
'base_url' => 'nullable|url:http,https',
'state' => [Rule::enum(ProviderPlatformState::class)],
];
}
Expand Down
61 changes: 61 additions & 0 deletions tests/Feature/ProviderPlatformControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Tests\Feature;

use App\Models\ProviderPlatform;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class ProviderPlatformControllerTest extends TestCase
{
use RefreshDatabase;

public string $uri = '/api/v1/provider-platforms';

public function testGetProviderPlatform()
{
$providerPlatform = ProviderPlatform::factory()->create();

$response = $this->get($this->uri.'/'.$providerPlatform->id);

$response->assertStatus(200);
}

public function testGetProviderPlatforms()
{
$response = $this->get($this->uri);
echo $response->getContent();
$response->assertStatus(200);
}

public function testCreateProviderPlatform()
{
$response = $this->post($this->uri.'/', [
'type' => 'canvas_cloud',
'name' => 'Test',
'description' => 'Test desciption',
'icon_url' => 'https://test.placeholder.com/640x480.png/0066cc?text=qui',
'account_id' => '123456789',
'access_key' => 'testaccesskey123',
'base_url' => 'http://testurl.org/qui-nesciunt-qui-expedita',
'state' => 'enabled',
]);
$response->assertStatus(201);
$response->assertCreated();
}

public function testUpdateProviderPlatform()
{
$providerPlatform = \App\Models\ProviderPlatform::factory()->create();
$response = $this->patch($this->uri.'/'.$providerPlatform->id, ['name' => 'TestUpdate']);
$response->assertStatus(200);
assert($response['data']['name'] == 'TestUpdate');
}

public function testDeleteProviderPlatform()
{
$providerPlatform = \App\Models\ProviderPlatform::factory()->create();
$response = $this->delete($this->uri.'/'.$providerPlatform->id);
$response->assertStatus(204);
}
}

0 comments on commit 17bbac8

Please sign in to comment.