mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
Rewires module installation to use slug + version + checksum_sha256 instead of the opaque module identifier. ModuleInstaller splits marketplace token handling out of install() into helpers, adopts structured error responses, and validates the downloaded archive's SHA-256 against the marketplace manifest before unpacking. ModuleResource is simplified to accept an already-loaded installed-module instance rather than fetching it from state, exposes access_tier and checksum fields, and drops the auto-disable-on-unpurchased side effect that was bleeding write logic into a read resource. UnzipUpdateRequest accepts a nullable module with a conditional module_name field so the same endpoint serves both app and module updates. ModulesPolicy::manageModules now short-circuits for super-admins so administration flows (token validation, store state) are not blocked on a company-scoped ability. Two new feature tests cover both the authorization bypass and ModuleResource serialization.
102 lines
3.5 KiB
PHP
102 lines
3.5 KiB
PHP
<?php
|
|
|
|
use App\Http\Resources\ModuleResource;
|
|
use App\Models\Module as InstalledModule;
|
|
use Illuminate\Http\Request;
|
|
|
|
it('maps the marketplace payload shape expected by the admin modules ui', function () {
|
|
$payload = (object) [
|
|
'id' => 7,
|
|
'slug' => 'sales-tax-us',
|
|
'name' => 'Sales Tax US',
|
|
'module_name' => 'SalesTaxUs',
|
|
'access_tier' => 'premium',
|
|
'cover' => 'https://example.com/cover.png',
|
|
'short_description' => 'Short description',
|
|
'long_description' => 'Long description',
|
|
'highlights' => ['Fast install'],
|
|
'screenshots' => [['url' => 'https://example.com/shot.png', 'title' => 'Shot']],
|
|
'faq' => [['question' => 'Q', 'answer' => 'A']],
|
|
'links' => [['icon' => 'BookOpenIcon', 'label' => 'Docs', 'link' => 'https://example.com/docs']],
|
|
'video_link' => null,
|
|
'video_thumbnail' => null,
|
|
'type' => 'integration',
|
|
'is_dev' => false,
|
|
'author_name' => 'InvoiceShelf',
|
|
'author_avatar' => 'https://example.com/avatar.png',
|
|
'latest_module_version' => '1.2.0',
|
|
'latest_module_version_updated_at' => now()->toIso8601String(),
|
|
'latest_min_invoiceshelf_version' => '3.0.0',
|
|
'latest_module_checksum_sha256' => hash('sha256', 'sales-tax-us-1.2.0'),
|
|
'installed_module_version' => null,
|
|
'installed_module_version_updated_at' => null,
|
|
'installed' => false,
|
|
'enabled' => false,
|
|
'update_available' => false,
|
|
'reviews' => [],
|
|
'average_rating' => null,
|
|
'monthly_price' => null,
|
|
'yearly_price' => null,
|
|
'purchased' => true,
|
|
'license' => null,
|
|
];
|
|
|
|
$data = (new ModuleResource($payload))->toArray(Request::create('/'));
|
|
|
|
expect($data)->toMatchArray([
|
|
'slug' => 'sales-tax-us',
|
|
'module_name' => 'SalesTaxUs',
|
|
'access_tier' => 'premium',
|
|
'author_name' => 'InvoiceShelf',
|
|
'latest_module_version' => '1.2.0',
|
|
'latest_min_invoiceshelf_version' => '3.0.0',
|
|
]);
|
|
});
|
|
|
|
it('overlays installed module state and update availability locally', function () {
|
|
InstalledModule::query()->create([
|
|
'name' => 'SalesTaxUs',
|
|
'version' => '1.0.0',
|
|
'installed' => true,
|
|
'enabled' => true,
|
|
]);
|
|
|
|
$payload = (object) [
|
|
'id' => 7,
|
|
'slug' => 'sales-tax-us',
|
|
'name' => 'Sales Tax US',
|
|
'module_name' => 'SalesTaxUs',
|
|
'access_tier' => 'public',
|
|
'cover' => null,
|
|
'short_description' => null,
|
|
'long_description' => null,
|
|
'highlights' => null,
|
|
'screenshots' => null,
|
|
'faq' => null,
|
|
'links' => null,
|
|
'video_link' => null,
|
|
'video_thumbnail' => null,
|
|
'type' => null,
|
|
'is_dev' => false,
|
|
'author_name' => 'InvoiceShelf',
|
|
'author_avatar' => null,
|
|
'latest_module_version' => '1.1.0',
|
|
'latest_module_version_updated_at' => now()->toIso8601String(),
|
|
'latest_min_invoiceshelf_version' => '3.0.0',
|
|
'latest_module_checksum_sha256' => hash('sha256', 'sales-tax-us-1.1.0'),
|
|
'reviews' => [],
|
|
'average_rating' => null,
|
|
'monthly_price' => null,
|
|
'yearly_price' => null,
|
|
'purchased' => true,
|
|
'license' => null,
|
|
];
|
|
|
|
$data = (new ModuleResource($payload))->toArray(Request::create('/'));
|
|
|
|
expect($data['installed'])->toBeTrue()
|
|
->and($data['enabled'])->toBeTrue()
|
|
->and($data['installed_module_version'])->toBe('1.0.0')
|
|
->and($data['update_available'])->toBeTrue();
|
|
});
|