Files
firefly-iii/tests/Api/Webhook/StoreControllerTest.php

107 lines
3.2 KiB
PHP
Raw Normal View History

2021-03-14 10:41:17 +01:00
<?php
/*
* StoreControllerTest.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2021-03-28 11:43:07 +02:00
declare(strict_types=1);
2021-03-14 10:41:17 +01:00
2021-03-28 11:43:07 +02:00
namespace Tests\Api\Webhook;
2022-12-29 19:43:43 +01:00
2021-03-14 10:41:17 +01:00
use Laravel\Passport\Passport;
use Log;
2021-03-21 08:13:19 +01:00
use Tests\Objects\Field;
use Tests\Objects\FieldSet;
use Tests\Objects\TestConfiguration;
2021-03-14 10:41:17 +01:00
use Tests\TestCase;
use Tests\Traits\CollectsValues;
use Tests\Traits\TestHelpers;
/**
* Class StoreControllerTest
*/
class StoreControllerTest extends TestCase
{
2022-12-29 19:43:43 +01:00
use TestHelpers;
use CollectsValues;
2021-03-14 10:41:17 +01:00
/**
2021-03-19 06:12:28 +01:00
* @return array
2021-03-14 10:41:17 +01:00
*/
2021-03-19 06:12:28 +01:00
public function emptyDataProvider(): array
2021-03-14 10:41:17 +01:00
{
2021-03-19 06:12:28 +01:00
return [[[]]];
2021-03-14 10:41:17 +01:00
}
/**
2021-03-19 06:12:28 +01:00
*
2021-03-14 10:41:17 +01:00
*/
2021-03-19 06:12:28 +01:00
public function setUp(): void
2021-03-14 10:41:17 +01:00
{
2021-03-19 06:12:28 +01:00
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
2021-03-14 10:41:17 +01:00
}
/**
* @return array
*/
public function storeDataProvider(): array
{
2021-03-21 08:13:19 +01:00
// some test configs:
2022-12-29 19:43:43 +01:00
$configuration = new TestConfiguration();
2021-03-21 08:13:19 +01:00
// default test set:
$defaultSet = new FieldSet();
$defaultSet->title = 'default_object';
$defaultSet->addField(Field::createBasic('title', 'uuid'));
$defaultSet->addField(Field::createBasic('url', 'secure-url'));
$defaultSet->addField(Field::createBasic('trigger', 'webhook-trigger'));
$defaultSet->addField(Field::createBasic('response', 'webhook-response'));
$defaultSet->addField(Field::createBasic('delivery', 'webhook-delivery'));
$configuration->addMandatoryFieldSet($defaultSet);
2022-12-29 19:43:43 +01:00
$fieldSet = new FieldSet();
2021-03-21 08:13:19 +01:00
$field = Field::createBasic('active', 'boolean');
$fieldSet->addField($field);
$configuration->addOptionalFieldSet('active', $fieldSet);
return $configuration->generateAll();
2021-03-14 10:41:17 +01:00
}
2021-03-19 06:12:28 +01:00
/**
* @param array $submission
*
* emptyDataProvider / storeDataProvider
*
* @dataProvider storeDataProvider
*/
public function testStore(array $submission): void
{
if ([] === $submission) {
2021-03-21 08:13:19 +01:00
$this->markTestSkipped('Empty provider.');
2021-03-19 06:12:28 +01:00
}
2021-03-21 08:13:19 +01:00
Log::debug('testStoreUpdated()');
Log::debug('submission :', $submission['submission']);
Log::debug('expected :', $submission['expected']);
Log::debug('ignore :', $submission['ignore']);
// run account store with a minimal data set:
$address = route('api.v1.webhooks.store');
$this->assertPOST($address, $submission);
2021-03-19 06:12:28 +01:00
}
2021-03-28 11:43:07 +02:00
}