55 lines
2.0 KiB
PHP
55 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Models\BazaarReview;
|
|
use App\Models\MobileApp;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
beforeEach(function () {
|
|
Http::preventStrayRequests();
|
|
});
|
|
|
|
it('synchronizes filtered Bazaar reviews', function () {
|
|
$app = MobileApp::factory()->create(['package_name' => 'ir.example.reviews']);
|
|
Http::fake([
|
|
'sandoghche.cafebazaar.ir/api/v0/reviews/*' => Http::response([
|
|
'next' => null,
|
|
'previous' => null,
|
|
'results' => [[
|
|
'id' => 122280901,
|
|
'user_account_id' => 'user-id',
|
|
'sdk_version' => 33,
|
|
'likes' => 4,
|
|
'dislikes' => 0,
|
|
'app_version_code' => 30200,
|
|
'publish_date' => '2025-01-05T10:12:45+03:30',
|
|
'is_edited' => false,
|
|
'text' => 'Great app',
|
|
'rate' => 5,
|
|
'developer_reply' => null,
|
|
]],
|
|
]),
|
|
]);
|
|
|
|
$this->withHeaders(appApiHeaders($app))
|
|
->getJson('/api/v1/apps/ir.example.reviews/bazaar/reviews?rate_min=4&is_replied=false')
|
|
->assertSuccessful()
|
|
->assertJsonPath('data.results.0.id', 122280901);
|
|
|
|
$review = BazaarReview::firstOrFail();
|
|
expect($review->rate)->toBe(5)->and($review->text)->toBe('Great app');
|
|
});
|
|
|
|
it('replies to a review with management authorization', function () {
|
|
$app = MobileApp::factory()->create(['package_name' => 'ir.example.reply']);
|
|
BazaarReview::factory()->for($app)->create(['bazaar_review_id' => 42]);
|
|
Http::fake([
|
|
'sandoghche.cafebazaar.ir/api/v0/reviews/42/' => Http::response(['text' => 'Thank you', 'email' => 'support@example.test'], 201),
|
|
]);
|
|
|
|
$this->withHeaders(appApiHeaders($app, true))
|
|
->postJson('/api/v1/apps/ir.example.reply/bazaar/reviews/42/reply', ['text' => 'Thank you', 'email' => 'support@example.test'])
|
|
->assertCreated();
|
|
|
|
expect(BazaarReview::firstOrFail()->developer_reply_text)->toBe('Thank you');
|
|
});
|