12-05-2026 Frontend dev
This commit is contained in:
parent
405df0a122
commit
5b8bdf4182
779 changed files with 480564 additions and 6241 deletions
72
tests/Feature/Api/V1/CustomerDataApiTest.php
Normal file
72
tests/Feature/Api/V1/CustomerDataApiTest.php
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Company;
|
||||
use App\Models\NewsletterSubscription;
|
||||
use App\Models\User;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
test('legacy api key requests receive gone response', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->getJson('/api/v1/categories?api_key=legacy-key')
|
||||
->assertStatus(410)
|
||||
->assertJsonPath('message', 'Legacy API keys are no longer supported.');
|
||||
});
|
||||
|
||||
test('api user can read only own companies', function () {
|
||||
/** @var TestCase $this */
|
||||
$user = User::factory()->create();
|
||||
$ownCompany = Company::factory()->presseecho()->create(['name' => 'Eigene Firma']);
|
||||
$otherCompany = Company::factory()->businessportal24()->create(['name' => 'Fremde Firma']);
|
||||
$user->companies()->attach($ownCompany->id, ['role' => 'owner']);
|
||||
|
||||
Sanctum::actingAs($user, ['companies:read']);
|
||||
|
||||
$this->getJson('/api/v1/companies')
|
||||
->assertOk()
|
||||
->assertSee('Eigene Firma')
|
||||
->assertDontSee('Fremde Firma');
|
||||
|
||||
$this->getJson("/api/v1/companies/{$otherCompany->id}")
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('api user can list categories with press release read ability', function () {
|
||||
/** @var TestCase $this */
|
||||
$user = User::factory()->create();
|
||||
Category::factory()->withTranslations()->create();
|
||||
|
||||
Sanctum::actingAs($user, ['press-releases:read']);
|
||||
|
||||
$this->getJson('/api/v1/categories')
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonStructure([
|
||||
'data' => [
|
||||
'*' => ['id', 'portal', 'translations'],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test('api user can subscribe an email to newsletter', function () {
|
||||
/** @var TestCase $this */
|
||||
$user = User::factory()->create();
|
||||
|
||||
Sanctum::actingAs($user, ['newsletter:subscribe']);
|
||||
|
||||
$this->postJson('/api/v1/newsletter/subscribe', [
|
||||
'portal' => 'presseecho',
|
||||
'email' => 'newsletter@example.com',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Muster',
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonPath('data.email', 'newsletter@example.com')
|
||||
->assertJsonPath('data.is_confirmed', false);
|
||||
|
||||
expect(NewsletterSubscription::withoutGlobalScopes()
|
||||
->where('email', 'newsletter@example.com')
|
||||
->where('portal', 'presseecho')
|
||||
->exists())->toBeTrue();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue