Files
app-agent/tests/Feature/BazaarPublishingApiTest.php
T
2026-08-24 19:44:24 +03:30

59 lines
2.1 KiB
PHP

<?php
use App\Models\BazaarRelease;
use App\Models\MobileApp;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
beforeEach(function () {
Http::preventStrayRequests();
});
it('creates and commits a managed Bazaar release', function () {
$app = MobileApp::factory()->create(['package_name' => 'ir.example.publish']);
Http::fake([
'api.pishkhan.cafebazaar.ir/v1/apps/releases/' => Http::response([
'type' => 'success',
'message' => 'New Release successfully created.',
'release' => ['packages' => []],
], 201),
'api.pishkhan.cafebazaar.ir/v1/apps/releases/commit/' => Http::response([
'type' => 'success',
'message' => 'Release successfully committed.',
'release' => ['id' => 159, 'committed' => true],
]),
]);
$headers = appApiHeaders($app, true);
$this->withHeaders($headers)
->postJson('/api/v1/apps/ir.example.publish/bazaar/releases')
->assertCreated();
$this->withHeaders($headers)
->postJson('/api/v1/apps/ir.example.publish/bazaar/releases/commit', [
'changelog_fa' => 'نسخه جدید',
'changelog_en' => 'New release',
'developer_note' => 'Automated release',
'staged_rollout_percentage' => 10,
'auto_publish' => true,
])
->assertSuccessful();
$release = BazaarRelease::firstOrFail();
expect($release->status)->toBe('committed')
->and($release->bazaar_release_id)->toBe(159)
->and($release->staged_rollout_percentage)->toBe(10)
->and($release->auto_publish)->toBeTrue();
Http::assertSent(fn (Request $request): bool => $request->hasHeader('CAFEBAZAAR-PISHKHAN-API-SECRET', $app->bazaar_api_secret));
});
it('rejects publishing without the management key', function () {
$app = MobileApp::factory()->create(['package_name' => 'ir.example.protected']);
$this->withHeaders(appApiHeaders($app))
->postJson('/api/v1/apps/ir.example.protected/bazaar/releases')
->assertForbidden();
});