Skip to content

Commit

Permalink
fix: storage_limit can be unlimited (#6989)
Browse files Browse the repository at this point in the history
  • Loading branch information
SecurID committed Oct 31, 2023
1 parent 0e4d192 commit a75643a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/Helpers/StorageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class StorageHelper
*/
public static function canUploadFile(Account $account): bool
{
// if storage limit is 0 then unlimited storage is allowed
// therefore the function should always return true
if ($account->storage_limit_in_mb == 0) {
return true;
}
// get the file size of all the files in the account
// the size will be in bytes
$vaultIds = $account->vaults()->select('id')->get()->toArray();
Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/Helpers/StorageHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,24 @@ public function it_checks_if_we_can_upload_another_file_in_the_account(): void

$this->assertFalse(StorageHelper::canUploadFile($account));
}

/** @test */
public function it_checks_if_we_can_upload_files_with_0_storage_limit(): void
{
$account = Account::factory()->create([
'storage_limit_in_mb' => 0,
]);

$this->assertTrue(StorageHelper::canUploadFile($account));

$vault = Vault::factory()->create([
'account_id' => $account->id,
]);
File::factory()->create([
'vault_id' => $vault->id,
'size' => 1024 * 1024,
]);

$this->assertTrue(StorageHelper::canUploadFile($account));
}
}

0 comments on commit a75643a

Please sign in to comment.