Working on messaging tests with worker

This commit is contained in:
wess 2023-08-28 16:27:55 -04:00
parent 1d6276eb9f
commit c2c70d68e9
5 changed files with 75 additions and 54 deletions

View file

@ -79,11 +79,25 @@ class MessagingV1 extends Worker
public function run(): void
{
$providerId = $this->args['providerId'];
$providerRecord =
$this
->getConsoleDB()
->getDocument('providers', $providerId);
$messageId = $this->args['messageId'];
$messageRecord =
$this
->getConsoleDB()
->getDocument('messages', $messageId);
$providerId = $messageRecord['providerId'];
$providerRecord =
$this
->getConsoleDB()
->getDocument('providers', $providerId);
$message = match ($providerRecord->getAttribute('type')) {
'sms' => $this->buildSMSMessage($messageRecord->getArrayCopy()),
'push' => $this->buildPushMessage($messageRecord->getArrayCopy()),
'email' => $this->buildEmailMessage($messageRecord->getArrayCopy()),
default => null
};
$provider = match ($providerRecord->getAttribute('type')) {//stubbbbbbed.
'sms' => $this->sms($providerRecord),
@ -92,25 +106,21 @@ class MessagingV1 extends Worker
default => null
};
var_dump($provider);
die;
// Query for the provider
// switch on provider name
// call function passing needed credentials returns required provider.
$messageId = $this->args['messageId'];
$messageRecord =
$this
->getConsoleDB()
->getDocument('messages', $messageId);
$message = match ($providerRecord->getAttribute('type')) {
'sms' => $this->buildSMSMessage($messageRecord->getArrayCopy()),
'push' => $this->buildPushMessage($messageRecord->getArrayCopy()),
'email' => $this->buildEmailMessage($messageRecord->getArrayCopy()),
default => null
};
$provider->send($message);
try {
$provider->send($message);
} catch (\Exception $error) {
throw new Exception('Error sending message: ' . $error->getMessage(), 500);
}
}
public function shutdown(): void

56
composer.lock generated
View file

@ -1183,16 +1183,16 @@
},
{
"name": "symfony/polyfill-php80",
"version": "v1.27.0",
"version": "v1.28.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
"reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936"
"reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936",
"reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5",
"reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5",
"shasum": ""
},
"require": {
@ -1201,7 +1201,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
"dev-main": "1.28-dev"
},
"thanks": {
"name": "symfony/polyfill",
@ -1246,7 +1246,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.27.0"
"source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0"
},
"funding": [
{
@ -1262,7 +1262,7 @@
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
"time": "2023-01-26T09:26:14+00:00"
},
{
"name": "utopia-php/abuse",
@ -5024,16 +5024,16 @@
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.27.0",
"version": "v1.28.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a"
"reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb",
"reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb",
"shasum": ""
},
"require": {
@ -5048,7 +5048,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
"dev-main": "1.28-dev"
},
"thanks": {
"name": "symfony/polyfill",
@ -5086,7 +5086,7 @@
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0"
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0"
},
"funding": [
{
@ -5102,20 +5102,20 @@
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
"time": "2023-01-26T09:26:14+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.27.0",
"version": "v1.28.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534"
"reference": "42292d99c55abe617799667f454222c54c60e229"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534",
"reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229",
"reference": "42292d99c55abe617799667f454222c54c60e229",
"shasum": ""
},
"require": {
@ -5130,7 +5130,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
"dev-main": "1.28-dev"
},
"thanks": {
"name": "symfony/polyfill",
@ -5169,7 +5169,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0"
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0"
},
"funding": [
{
@ -5185,7 +5185,7 @@
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
"time": "2023-07-28T09:04:16+00:00"
},
{
"name": "textalk/websocket",
@ -5288,16 +5288,16 @@
},
{
"name": "twig/twig",
"version": "v3.7.0",
"version": "v3.7.1",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "5cf942bbab3df42afa918caeba947f1b690af64b"
"reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/5cf942bbab3df42afa918caeba947f1b690af64b",
"reference": "5cf942bbab3df42afa918caeba947f1b690af64b",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/a0ce373a0ca3bf6c64b9e3e2124aca502ba39554",
"reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554",
"shasum": ""
},
"require": {
@ -5307,7 +5307,7 @@
},
"require-dev": {
"psr/container": "^1.0|^2.0",
"symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0"
"symfony/phpunit-bridge": "^5.4.9|^6.3"
},
"type": "library",
"autoload": {
@ -5343,7 +5343,7 @@
],
"support": {
"issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v3.7.0"
"source": "https://github.com/twigphp/Twig/tree/v3.7.1"
},
"funding": [
{
@ -5355,7 +5355,7 @@
"type": "tidelift"
}
],
"time": "2023-07-26T07:16:09+00:00"
"time": "2023-08-28T11:09:02+00:00"
}
],
"aliases": [

View file

@ -732,13 +732,13 @@ services:
- _APP_CONNECTIONS_QUEUE
- _APP_REGION
appwrite-assistant:
container_name: appwrite-assistant
image: appwrite/assistant:0.1.0
networks:
- appwrite
environment:
- OPENAI_API_KEY
# appwrite-assistant:
# container_name: appwrite-assistant
# image: appwrite/assistant:0.1.0
# networks:
# - appwrite
# environment:
# - OPENAI_API_KEY
openruntimes-executor:
container_name: openruntimes-executor

View file

@ -6,7 +6,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
stopOnFailure="true"
>
<extensions>
<extension class="Appwrite\Tests\TestHook" />

View file

@ -12,6 +12,7 @@ use Tests\E2E\Scopes\SideClient;
use Utopia\Database\DateTime;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Validator\Datetime as DatetimeValidator;
use Utopia\Messaging\Adapters\SMS\Mock as MockProvider;
use function sleep;
@ -767,6 +768,16 @@ class AccountCustomClientTest extends Scope
}
public function testCreateMockSMS(): MockProvider
{
$smsMockProvider = new MockProvider('blah', 'blah');
$this->assertNotEquals(null, $smsMockProvider);
return $smsMockProvider;
}
public function testCreatePhone(): array
{
$number = '+123456789';