1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00

support integers as valid float values

This commit is contained in:
kodumbeats 2021-10-25 16:00:33 -04:00
parent fb0b83574f
commit ffbcc728bb
3 changed files with 60 additions and 34 deletions

View file

@ -38,7 +38,7 @@
"appwrite/php-clamav": "1.1.*",
"appwrite/php-runtimes": "0.6.*",
"utopia-php/framework": "0.18.*",
"utopia-php/framework": "0.19.*",
"utopia-php/abuse": "0.6.*",
"utopia-php/analytics": "0.2.*",
"utopia-php/audit": "0.6.*",

41
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e55db0e0bb8929027e77cb9a9164a215",
"content-hash": "fa378feaffc446f557a140035a1c77b6",
"packages": [
{
"name": "adhocore/jwt",
@ -613,16 +613,16 @@
},
{
"name": "guzzlehttp/promises",
"version": "1.5.0",
"version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "136a635e2b4a49b9d79e9c8fee267ffb257fdba0"
"reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/136a635e2b4a49b9d79e9c8fee267ffb257fdba0",
"reference": "136a635e2b4a49b9d79e9c8fee267ffb257fdba0",
"url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da",
"reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da",
"shasum": ""
},
"require": {
@ -677,7 +677,7 @@
],
"support": {
"issues": "https://github.com/guzzle/promises/issues",
"source": "https://github.com/guzzle/promises/tree/1.5.0"
"source": "https://github.com/guzzle/promises/tree/1.5.1"
},
"funding": [
{
@ -693,7 +693,7 @@
"type": "tidelift"
}
],
"time": "2021-10-07T13:05:22+00:00"
"time": "2021-10-22T20:56:57+00:00"
},
{
"name": "guzzlehttp/psr7",
@ -2255,16 +2255,16 @@
},
{
"name": "utopia-php/framework",
"version": "0.18.0",
"version": "0.19.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/framework.git",
"reference": "f577522a5eb8009967b893fb7ad4ee70d3f7c0db"
"reference": "c86fc078ef258f3c88d3a25233202267314df3a9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/framework/zipball/f577522a5eb8009967b893fb7ad4ee70d3f7c0db",
"reference": "f577522a5eb8009967b893fb7ad4ee70d3f7c0db",
"url": "https://api.github.com/repos/utopia-php/framework/zipball/c86fc078ef258f3c88d3a25233202267314df3a9",
"reference": "c86fc078ef258f3c88d3a25233202267314df3a9",
"shasum": ""
},
"require": {
@ -2298,9 +2298,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/framework/issues",
"source": "https://github.com/utopia-php/framework/tree/0.18.0"
"source": "https://github.com/utopia-php/framework/tree/0.19.0"
},
"time": "2021-08-19T04:58:47+00:00"
"time": "2021-10-08T11:46:20+00:00"
},
{
"name": "utopia-php/image",
@ -3064,16 +3064,16 @@
},
{
"name": "composer/semver",
"version": "3.2.5",
"version": "3.2.6",
"source": {
"type": "git",
"url": "https://github.com/composer/semver.git",
"reference": "31f3ea725711245195f62e54ffa402d8ef2fdba9"
"reference": "83e511e247de329283478496f7a1e114c9517506"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/semver/zipball/31f3ea725711245195f62e54ffa402d8ef2fdba9",
"reference": "31f3ea725711245195f62e54ffa402d8ef2fdba9",
"url": "https://api.github.com/repos/composer/semver/zipball/83e511e247de329283478496f7a1e114c9517506",
"reference": "83e511e247de329283478496f7a1e114c9517506",
"shasum": ""
},
"require": {
@ -3125,7 +3125,7 @@
"support": {
"irc": "irc://irc.freenode.org/composer",
"issues": "https://github.com/composer/semver/issues",
"source": "https://github.com/composer/semver/tree/3.2.5"
"source": "https://github.com/composer/semver/tree/3.2.6"
},
"funding": [
{
@ -3141,7 +3141,7 @@
"type": "tidelift"
}
],
"time": "2021-05-24T12:41:47+00:00"
"time": "2021-10-25T11:34:17+00:00"
},
{
"name": "composer/xdebug-handler",
@ -5423,7 +5423,6 @@
"type": "github"
}
],
"abandoned": true,
"time": "2020-09-28T06:45:17+00:00"
},
{
@ -6530,5 +6529,5 @@
"platform-overrides": {
"php": "8.0"
},
"plugin-api-version": "2.0.0"
"plugin-api-version": "2.1.0"
}

View file

@ -1293,17 +1293,16 @@ trait DatabaseBase
'max' => 1.4,
]);
// TODO@kodumbeats float validator rejects 0.0 and 1.0 as floats
// $probability = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/float', array_merge([
// 'content-type' => 'application/json',
// 'x-appwrite-project' => $this->getProject()['$id'],
// 'x-appwrite-key' => $this->getProject()['apiKey']
// ]), [
// 'attributeId' => 'probability',
// 'required' => false,
// 'min' => \floatval(0.0),
// 'max' => \floatval(1.0),
// ]);
$probability = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/float', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'attributeId' => 'probability',
'required' => false,
'min' => 0,
'max' => 1,
]);
$upperBound = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/integer', array_merge([
'content-type' => 'application/json',
@ -1345,6 +1344,7 @@ trait DatabaseBase
$this->assertEquals(201, $url['headers']['status-code']);
$this->assertEquals(201, $range['headers']['status-code']);
$this->assertEquals(201, $floatRange['headers']['status-code']);
$this->assertEquals(201, $probability['headers']['status-code']);
$this->assertEquals(201, $upperBound['headers']['status-code']);
$this->assertEquals(201, $lowerBound['headers']['status-code']);
// $this->assertEquals(400, $invalidRange['headers']['status-code']);
@ -1359,7 +1359,7 @@ trait DatabaseBase
'x-appwrite-key' => $this->getProject()['apiKey'],
]), []);
$this->assertCount(8, $collection['body']['attributes']);
$this->assertCount(9, $collection['body']['attributes']);
/**
* Test for successful validation
@ -1437,6 +1437,18 @@ trait DatabaseBase
'write' => ['user:'.$this->getUser()['$id']],
]);
$goodProbability = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'documentId' => 'unique()',
'data' => [
'probability' => 0.99999,
],
'read' => ['user:'.$this->getUser()['$id']],
'write' => ['user:'.$this->getUser()['$id']],
]);
$notTooHigh = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@ -1467,6 +1479,7 @@ trait DatabaseBase
$this->assertEquals(201, $goodUrl['headers']['status-code']);
$this->assertEquals(201, $goodRange['headers']['status-code']);
$this->assertEquals(201, $goodFloatRange['headers']['status-code']);
$this->assertEquals(201, $goodProbability['headers']['status-code']);
$this->assertEquals(201, $notTooHigh['headers']['status-code']);
$this->assertEquals(201, $notTooLow['headers']['status-code']);
@ -1546,6 +1559,18 @@ trait DatabaseBase
'write' => ['user:'.$this->getUser()['$id']],
]);
$badProbability = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'documentId' => 'unique()',
'data' => [
'probability' => 1.1,
],
'read' => ['user:'.$this->getUser()['$id']],
'write' => ['user:'.$this->getUser()['$id']],
]);
$tooHigh = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@ -1576,6 +1601,7 @@ trait DatabaseBase
$this->assertEquals(400, $badUrl['headers']['status-code']);
$this->assertEquals(400, $badRange['headers']['status-code']);
$this->assertEquals(400, $badFloatRange['headers']['status-code']);
$this->assertEquals(400, $badProbability['headers']['status-code']);
$this->assertEquals(400, $tooHigh['headers']['status-code']);
$this->assertEquals(400, $tooLow['headers']['status-code']);
$this->assertEquals('Invalid document structure: Attribute "email" has invalid format. Value must be a valid email address', $badEmail['body']['message']);
@ -1584,6 +1610,7 @@ trait DatabaseBase
$this->assertEquals('Invalid document structure: Attribute "url" has invalid format. Value must be a valid URL', $badUrl['body']['message']);
$this->assertEquals('Invalid document structure: Attribute "range" has invalid format. Value must be a valid range between 1 and 10', $badRange['body']['message']);
$this->assertEquals('Invalid document structure: Attribute "floatRange" has invalid format. Value must be a valid range between 1 and 1', $badFloatRange['body']['message']);
$this->assertEquals('Invalid document structure: Attribute "probability" has invalid format. Value must be a valid range between 0 and 1', $badProbability['body']['message']);
$this->assertEquals('Invalid document structure: Attribute "upperBound" has invalid format. Value must be a valid range between -9,223,372,036,854,775,808 and 10', $tooHigh['body']['message']);
$this->assertEquals('Invalid document structure: Attribute "lowerBound" has invalid format. Value must be a valid range between 5 and 9,223,372,036,854,775,808', $tooLow['body']['message']);
}