Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -5233,7 +5233,7 @@ public function increaseDocumentAttribute(
}
}

if ($max && ($document->getAttribute($attribute) + $value > $max)) {
if (!\is_null($max) && ($document->getAttribute($attribute) + $value > $max)) {
throw new LimitException('Attribute value exceeds maximum limit: ' . $max);
}

Expand Down Expand Up @@ -5332,7 +5332,7 @@ public function decreaseDocumentAttribute(
}
}

if ($min && ($document->getAttribute($attribute) - $value < $min)) {
if (!\is_null($min) && ($document->getAttribute($attribute) - $value < $min)) {
throw new LimitException('Attribute value exceeds minimum limit: ' . $min);
}

Expand Down
28 changes: 26 additions & 2 deletions tests/e2e/Adapter/Scopes/DocumentTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Utopia\Database\Exception\Authorization as AuthorizationException;
use Utopia\Database\Exception\Conflict as ConflictException;
use Utopia\Database\Exception\Duplicate as DuplicateException;
use Utopia\Database\Exception\Limit as LimitException;
use Utopia\Database\Exception\Structure as StructureException;
use Utopia\Database\Exception\Type as TypeException;
use Utopia\Database\Helpers\ID;
Expand Down Expand Up @@ -1205,8 +1206,31 @@ public function testDecreaseLimitMin(Document $document): void
/** @var Database $database */
$database = static::getDatabase();

$this->expectException(Exception::class);
$this->assertEquals(false, $database->decreaseDocumentAttribute('increase_decrease', $document->getId(), 'decrease', 10, 99));
try {
$database->decreaseDocumentAttribute(
'increase_decrease',
$document->getId(),
'decrease',
10,
99
);
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(LimitException::class, $e);
}

try {
$database->decreaseDocumentAttribute(
'increase_decrease',
$document->getId(),
'decrease',
1000,
0
);
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(LimitException::class, $e);
}
}

/**
Expand Down