63 lines
2.0 KiB
PHP
63 lines
2.0 KiB
PHP
<?php
|
|
|
|
require __DIR__.'/InboxFixture.php';
|
|
|
|
if (getenv('WAREHOUSE_HTTP_FIXTURE') !== '1' || ($_SERVER['REMOTE_ADDR'] ?? null) !== '127.0.0.1') {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
if ($path === '/health') {
|
|
echo 'ready';
|
|
exit;
|
|
}
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
if (($_SERVER['HTTP_COOKIE'] ?? '') !== 'SGC_TEST_SESSION=synthetic-authorized') {
|
|
http_response_code(401);
|
|
echo '{"message":"synthetic login needed"}';
|
|
exit;
|
|
}
|
|
if (! preg_match('~^/([a-z0-9_-]+)/stock/integracao/entregas$~D', $path, $match) || ($_SERVER['REQUEST_METHOD'] ?? null) !== 'GET') {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
$scenario = $match[1];
|
|
if (preg_match('/^status_([0-9]{3})$/D', $scenario, $code)) {
|
|
http_response_code((int) $code[1]);
|
|
echo '{"message":"synthetic-private-body-do-not-log"}';
|
|
exit;
|
|
}
|
|
if ($scenario === 'redirect') {
|
|
header('Location: /ok/stock/integracao/entregas', true, 302);
|
|
exit;
|
|
}
|
|
if ($scenario === 'html') {
|
|
header('Content-Type: text/html');
|
|
echo '<html>synthetic-private-body-do-not-log</html>';
|
|
exit;
|
|
}
|
|
if ($scenario === 'json_error') {
|
|
echo 'synthetic-private-body-do-not-log';
|
|
exit;
|
|
}
|
|
if ($scenario === 'oversized') {
|
|
echo str_repeat('x', 16384);
|
|
exit;
|
|
}
|
|
if ($scenario === 'slow') {
|
|
usleep(1200000);
|
|
}
|
|
$cursor = $_GET['cursor'] ?? null;
|
|
$page = $scenario === 'paged' && $cursor !== null
|
|
? inboxPage([inboxEvent(2, 'receive', 'sgc:7:warehouse-event:1')], 'cursor-two')
|
|
: inboxPage([inboxEvent()], 'cursor-one', $scenario === 'paged');
|
|
if ($scenario === 'wrong_tenant') {
|
|
$page['items'][0]['tenant_id'] = 8;
|
|
$page['items'][0] = inboxSign($page['items'][0]);
|
|
}
|
|
if ($scenario === 'bad_hash') {
|
|
$page['items'][0]['lines'][0]['quantity_milli'] = 5000;
|
|
}
|
|
$page['fixture_query'] = ['cursor' => $cursor, 'limit' => $_GET['limit'] ?? null];
|
|
echo json_encode($page, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|