AppAction example

class AppActionTest extends TestCase
{
    public function testAsPayload(): void
    {
        $targetUrl = 'https://my-server.com/action';
        $shopUrl = 'https://my-shop.com';
        $appVersion = '1.0.0';
        $entity = 'product';
        $action = 'detail';
        $shopId = Random::getAlphanumericString(12);
        $ids = [Uuid::randomHex()];
        $result = new AppAction(
            $targetUrl,
            $shopUrl,
            $appVersion,
            $entity,
            $action,
            $ids,
            's3cr3t',
            $shopId,
            Uuid::randomHex()
        );

        
$this->createMock(LoggerInterface::class),
            $this->createMock(ActionButtonResponseFactory::class),
            $this->createMock(ShopIdProvider::class),
            $this->createMock(RouterInterface::class),
            $requestStack,
            $this->createMock(KernelInterface::class)
        );

        static::expectException(AppException::class);
        static::expectExceptionMessage('connection problems');

        $appAction = new AppAction('https://example.com', 'https://localhost', '1.0.0', 'action-id', 'label', [Uuid::randomHex()], 'GET', 'asd', '123123123');

        $executor->execute(
            $appAction,
            Context::createDefaultContext()
        );
    }
}
class OpenNewTabResponseFactoryTest extends TestCase
{
    use GuzzleTestClientBehaviour;

    private OpenNewTabResponseFactory $factory;

    private AppAction $action;

    protected function setUp(): void
    {
        $this->factory = $this->getContainer()->get(OpenNewTabResponseFactory::class);
        $this->action = new AppAction(
            'http://target.url',
            'http://shop.url',
            '1.0.0',
            'customer',
            'action-name',
            [Uuid::randomHex(), Uuid::randomHex()],
            'app-secret',
            'shop-id',
            'action-it'
        );
    }

    
class NotificationResponseFactoryTest extends TestCase
{
    use GuzzleTestClientBehaviour;

    private NotificationResponseFactory $factory;

    private AppAction $action;

    protected function setUp(): void
    {
        $this->factory = $this->getContainer()->get(NotificationResponseFactory::class);
        $this->action = new AppAction(
            'http://target.url',
            'http://shop.url',
            '1.0.0',
            'customer',
            'action-name',
            [Uuid::randomHex(), Uuid::randomHex()],
            'app-secret',
            'shop-id',
            'action-it'
        );
    }

    
class ActionButtonResponseFactoryTest extends TestCase
{
    use GuzzleTestClientBehaviour;

    private ActionButtonResponseFactory $actionButtonResponseFactory;

    private AppAction $action;

    protected function setUp(): void
    {
        $this->actionButtonResponseFactory = $this->getContainer()->get(ActionButtonResponseFactory::class);
        $this->action = new AppAction(
            'http://target.url',
            'http://shop.url',
            '1.0.0',
            'customer',
            'action-name',
            [Uuid::randomHex(), Uuid::randomHex()],
            'app-secret',
            'shop-id',
            'action-it'
        );
    }

    
if ($appSecret === null) {
            throw new MissingAppSecretException();
        }

        $targetUrl = $requestDataBag->get('url');
        $targetHost = \parse_url((string) $targetUrl, \PHP_URL_HOST);
        $allowedHosts = $app->getAllowedHosts() ?? [];
        if (!$targetHost || !\in_array($targetHost$allowedHosts, true)) {
            throw new UnallowedHostException($targetUrl$allowedHosts$app->getName());
        }

        $action = new AppAction(
            $targetUrl,
            $shopUrl,
            $app->getVersion(),
            $requestDataBag->get('entity'),
            $requestDataBag->get('action'),
            $requestDataBag->get('ids')->all(),
            $appSecret,
            $this->shopIdProvider->getShopId(),
            Uuid::randomHex()
        );

        
class ReloadDataResponseFactoryTest extends TestCase
{
    use GuzzleTestClientBehaviour;

    private ReloadDataResponseFactory $factory;

    private AppAction $action;

    protected function setUp(): void
    {
        $this->factory = $this->getContainer()->get(ReloadDataResponseFactory::class);
        $this->action = new AppAction(
            'http://target.url',
            'http://shop.url',
            '1.0.0',
            'customer',
            'action-name',
            [Uuid::randomHex(), Uuid::randomHex()],
            'app-secret',
            'shop-id',
            'action-it'
        );
    }

    
class OpenModalResponseFactoryTest extends TestCase
{
    use GuzzleTestClientBehaviour;

    private OpenModalResponseFactory $factory;

    private AppAction $action;

    protected function setUp(): void
    {
        $this->factory = $this->getContainer()->get(OpenModalResponseFactory::class);
        $this->action = new AppAction(
            'http://target.url',
            'http://shop.url',
            '1.0.0',
            'customer',
            'action-name',
            [Uuid::randomHex(), Uuid::randomHex()],
            'app-secret',
            'shop-id',
            'action-it'
        );
    }

    


        try {
            $shopId = $this->shopIdProvider->getShopId();
        } catch (AppUrlChangeDetectedException) {
            throw new ActionNotFoundException();
        }

        /** @var string $secret */
        $secret = $actionButton->getApp()->getAppSecret();

        return new AppAction(
            $actionButton->getUrl(),
            $this->url,
            $actionButton->getApp()->getVersion(),
            $actionButton->getEntity(),
            $actionButton->getAction(),
            $ids,
            $secret,
            $shopId,
            $actionId
        );
    }
}
protected function setUp(): void
    {
        $this->executor = $this->getContainer()->get(Executor::class);
        $this->schemaLocation = $this->getContainer()->getParameter('kernel.project_dir') . self::SCHEMA_LOCATION;
    }

    public function testExecutorUsesCorrectSchema(): void
    {
        $appUrl = EnvironmentHelper::getVariable('APP_URL');
        static::assertIsString($appUrl);

        $action = new AppAction(
            'https://test.com/my-action',
            $appUrl,
            '1.0.0',
            'product',
            'detail',
            [Uuid::randomHex()],
            's3cr3t',
            Random::getAlphanumericString(12),
            Uuid::randomHex()
        );

        
Home | Imprint | This part of the site doesn't use cookies.