2FAuth/tests/Api/v1/Controllers/IconControllerTest.php

86 lines
1.9 KiB
PHP
Raw Normal View History

2021-11-14 01:52:46 +01:00
<?php
namespace Tests\Api\v1\Controllers;
use Illuminate\Foundation\Testing\WithoutMiddleware;
2022-11-22 15:15:52 +01:00
use Illuminate\Http\UploadedFile;
2021-11-30 17:39:33 +01:00
use Tests\FeatureTestCase;
2021-11-14 01:52:46 +01:00
2021-11-22 01:09:54 +01:00
/**
* @covers \App\Api\v1\Controllers\IconController
*/
2021-11-30 17:39:33 +01:00
class IconControllerTest extends FeatureTestCase
2021-11-14 01:52:46 +01:00
{
use WithoutMiddleware;
/**
* @test
*/
public function test_upload_icon_returns_filename()
{
$file = UploadedFile::fake()->image('testIcon.jpg');
$response = $this->json('POST', '/api/v1/icons', [
2022-11-22 15:15:52 +01:00
'icon' => $file,
])
2021-11-14 01:52:46 +01:00
->assertCreated()
->assertJsonStructure([
2022-11-22 15:15:52 +01:00
'filename',
2021-11-14 01:52:46 +01:00
]);
}
/**
* @test
*/
public function test_upload_with_invalid_data_returns_validation_error()
{
$response = $this->json('POST', '/api/v1/icons', [
2022-11-22 15:15:52 +01:00
'icon' => null,
])
2021-11-14 01:52:46 +01:00
->assertStatus(422);
}
2022-12-09 10:52:17 +01:00
/**
* @test
*/
public function test_fetch_logo_returns_filename()
{
$response = $this->json('POST', '/api/v1/icons/default', [
'service' => 'twitter',
])
->assertStatus(201)
->assertJsonStructure([
'filename',
]);
}
/**
* @test
*/
public function test_fetch_unknown_logo_returns_nothing()
{
$response = $this->json('POST', '/api/v1/icons/default', [
'service' => 'unknown_company',
])
->assertNoContent();
}
2021-11-14 01:52:46 +01:00
/**
* @test
*/
public function test_delete_icon_returns_success()
{
$response = $this->json('DELETE', '/api/v1/icons/testIcon.jpg')
->assertNoContent(204);
}
/**
* @test
*/
public function test_delete_invalid_icon_returns_success()
{
$response = $this->json('DELETE', '/api/v1/icons/null')
->assertNoContent(204);
}
2022-11-22 15:15:52 +01:00
}