refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
52
tests/Unit/Jobs/Dav/DeleteMultipleVCardTest.php
Normal file
52
tests/Unit/Jobs/Dav/DeleteMultipleVCardTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Jobs\Dav;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use App\Jobs\Dav\DeleteVCard;
|
||||
use Illuminate\Bus\PendingBatch;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use App\Jobs\Dav\DeleteMultipleVCard;
|
||||
use Illuminate\Bus\DatabaseBatchRepository;
|
||||
use App\Models\Account\AddressBookSubscription;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class DeleteMultipleVCardTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_delete_cards()
|
||||
{
|
||||
$fake = Bus::fake();
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$addressBookSubscription = AddressBookSubscription::factory()->create([
|
||||
'account_id' => $user->account_id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$pendingBatch = $fake->batch([
|
||||
$job = new DeleteMultipleVCard($addressBookSubscription, ['https://test/dav/uri']),
|
||||
]);
|
||||
$batch = $pendingBatch->dispatch();
|
||||
|
||||
$fake->assertBatched(function (PendingBatch $pendingBatch) {
|
||||
$this->assertCount(1, $pendingBatch->jobs);
|
||||
$this->assertInstanceOf(DeleteMultipleVCard::class, $pendingBatch->jobs->first());
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$batch = app(DatabaseBatchRepository::class)->store($pendingBatch);
|
||||
$job->withBatchId($batch->id)->handle();
|
||||
|
||||
$fake->assertDispatched(function (DeleteVCard $updateVCard) {
|
||||
$uri = $this->getPrivateValue($updateVCard, 'uri');
|
||||
$this->assertEquals('https://test/dav/uri', $uri);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
53
tests/Unit/Jobs/Dav/DeleteVCardTest.php
Normal file
53
tests/Unit/Jobs/Dav/DeleteVCardTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Jobs\Dav;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use App\Jobs\Dav\DeleteVCard;
|
||||
use Illuminate\Bus\PendingBatch;
|
||||
use Illuminate\Http\Client\Request;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Bus\DatabaseBatchRepository;
|
||||
use App\Models\Account\AddressBookSubscription;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class DeleteVCardTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_delete_card()
|
||||
{
|
||||
$fake = Bus::fake();
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$addressBookSubscription = AddressBookSubscription::factory()->create([
|
||||
'account_id' => $user->account_id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
Http::fake(function (Request $request) {
|
||||
$this->assertEquals('https://test/dav/uri', $request->url());
|
||||
$this->assertEquals('DELETE', $request->method());
|
||||
|
||||
return Http::response(null, 204);
|
||||
});
|
||||
|
||||
$pendingBatch = $fake->batch([
|
||||
$job = new DeleteVCard($addressBookSubscription, 'https://test/dav/uri'),
|
||||
]);
|
||||
$batch = $pendingBatch->dispatch();
|
||||
|
||||
$fake->assertBatched(function (PendingBatch $pendingBatch) {
|
||||
$this->assertCount(1, $pendingBatch->jobs);
|
||||
$this->assertInstanceOf(DeleteVCard::class, $pendingBatch->jobs->first());
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$batch = app(DatabaseBatchRepository::class)->store($pendingBatch);
|
||||
$job->withBatchId($batch->id)->handle();
|
||||
}
|
||||
}
|
||||
176
tests/Unit/Jobs/Dav/GetMultipleVCardTest.php
Normal file
176
tests/Unit/Jobs/Dav/GetMultipleVCardTest.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Jobs\Dav;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use Mockery\MockInterface;
|
||||
use Tests\Api\DAV\CardEtag;
|
||||
use App\Jobs\Dav\UpdateVCard;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Bus\PendingBatch;
|
||||
use App\Jobs\Dav\GetMultipleVCard;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Sabre\CardDAV\Plugin as CardDAVPlugin;
|
||||
use Illuminate\Bus\DatabaseBatchRepository;
|
||||
use App\Models\Account\AddressBookSubscription;
|
||||
use App\Services\DavClient\Utils\Dav\DavClient;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class GetMultipleVCardTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
use CardEtag;
|
||||
|
||||
/** @test */
|
||||
public function it_get_cards()
|
||||
{
|
||||
$fake = Bus::fake();
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$addressBookSubscription = AddressBookSubscription::factory()->create([
|
||||
'account_id' => $user->account_id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$contact = new Contact();
|
||||
$contact->forceFill([
|
||||
'first_name' => 'Test',
|
||||
'uuid' => 'affacde9-b2fe-4371-9acb-6612aaee6971',
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
$card = $this->getCard($contact);
|
||||
$etag = $this->getEtag($contact, true);
|
||||
|
||||
$this->mock(DavClient::class, function (MockInterface $mock) use ($card, $etag) {
|
||||
$mock->shouldReceive('setBaseUri')->once()->andReturn($mock);
|
||||
$mock->shouldReceive('setCredentials')->once()->andReturn($mock);
|
||||
$mock->shouldReceive('addressbookMultiget')
|
||||
->once()
|
||||
->withArgs(function ($properties, $contacts) {
|
||||
$this->assertEquals([
|
||||
'{DAV:}getetag',
|
||||
[
|
||||
'name' => '{'.CardDAVPlugin::NS_CARDDAV.'}address-data',
|
||||
'value' => null,
|
||||
'attributes' => [
|
||||
'content-type' => 'text/vcard',
|
||||
'version' => '4.0',
|
||||
],
|
||||
],
|
||||
], $properties);
|
||||
$this->assertEquals(['https://test/dav/uri'], $contacts);
|
||||
|
||||
return true;
|
||||
})
|
||||
->andReturn([
|
||||
'https://test/dav/uri' => [
|
||||
200 => [
|
||||
'{'.CardDAVPlugin::NS_CARDDAV.'}address-data' => $card,
|
||||
'{DAV:}getetag' => $etag,
|
||||
],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
$pendingBatch = $fake->batch([
|
||||
$job = new GetMultipleVCard($addressBookSubscription, ['https://test/dav/uri']),
|
||||
]);
|
||||
$batch = $pendingBatch->dispatch();
|
||||
|
||||
$fake->assertBatched(function (PendingBatch $pendingBatch) {
|
||||
$this->assertCount(1, $pendingBatch->jobs);
|
||||
$this->assertInstanceOf(GetMultipleVCard::class, $pendingBatch->jobs->first());
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$batch = app(DatabaseBatchRepository::class)->store($pendingBatch);
|
||||
$job->withBatchId($batch->id)->handle();
|
||||
|
||||
$fake->assertDispatched(function (UpdateVCard $updateVCard) use ($etag, $card) {
|
||||
$dto = $this->getPrivateValue($updateVCard, 'contact');
|
||||
$this->assertEquals('https://test/dav/uri', $dto->uri);
|
||||
$this->assertEquals($etag, $dto->etag);
|
||||
$this->assertEquals($card, $dto->card);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_get_cards_mock_http()
|
||||
{
|
||||
$fake = Bus::fake();
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$addressBookSubscription = AddressBookSubscription::factory()->create([
|
||||
'account_id' => $user->account_id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$contact = new Contact();
|
||||
$contact->forceFill([
|
||||
'first_name' => 'Test',
|
||||
'uuid' => 'affacde9-b2fe-4371-9acb-6612aaee6971',
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
$card = $this->getCard($contact);
|
||||
$etag = $this->getEtag($contact, true);
|
||||
|
||||
$this->mock(DavClient::class, function (MockInterface $mock) use ($card, $etag) {
|
||||
$mock->shouldReceive('setBaseUri')->once()->andReturn($mock);
|
||||
$mock->shouldReceive('setCredentials')->once()->andReturn($mock);
|
||||
$mock->shouldReceive('addressbookMultiget')
|
||||
->once()
|
||||
->withArgs(function ($properties, $contacts) {
|
||||
$this->assertEquals([
|
||||
'{DAV:}getetag',
|
||||
[
|
||||
'name' => '{'.CardDAVPlugin::NS_CARDDAV.'}address-data',
|
||||
'value' => null,
|
||||
'attributes' => [
|
||||
'content-type' => 'text/vcard',
|
||||
'version' => '4.0',
|
||||
],
|
||||
],
|
||||
], $properties);
|
||||
$this->assertEquals(['https://test/dav/uri'], $contacts);
|
||||
|
||||
return true;
|
||||
})
|
||||
->andReturn([
|
||||
'https://test/dav/uri' => [
|
||||
200 => [
|
||||
'{'.CardDAVPlugin::NS_CARDDAV.'}address-data' => $card,
|
||||
'{DAV:}getetag' => $etag,
|
||||
],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
$pendingBatch = $fake->batch([
|
||||
$job = new GetMultipleVCard($addressBookSubscription, ['https://test/dav/uri']),
|
||||
]);
|
||||
$batch = $pendingBatch->dispatch();
|
||||
|
||||
$fake->assertBatched(function (PendingBatch $pendingBatch) {
|
||||
$this->assertCount(1, $pendingBatch->jobs);
|
||||
$this->assertInstanceOf(GetMultipleVCard::class, $pendingBatch->jobs->first());
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$batch = app(DatabaseBatchRepository::class)->store($pendingBatch);
|
||||
$job->withBatchId($batch->id)->handle();
|
||||
|
||||
$fake->assertDispatched(function (UpdateVCard $updateVCard) use ($etag, $card) {
|
||||
$dto = $this->getPrivateValue($updateVCard, 'contact');
|
||||
$this->assertEquals('https://test/dav/uri', $dto->uri);
|
||||
$this->assertEquals($etag, $dto->etag);
|
||||
$this->assertEquals($card, $dto->card);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
72
tests/Unit/Jobs/Dav/GetVCardTest.php
Normal file
72
tests/Unit/Jobs/Dav/GetVCardTest.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Jobs\Dav;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use App\Jobs\Dav\GetVCard;
|
||||
use Tests\Api\DAV\CardEtag;
|
||||
use App\Jobs\Dav\UpdateVCard;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Bus\PendingBatch;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Bus\DatabaseBatchRepository;
|
||||
use App\Models\Account\AddressBookSubscription;
|
||||
use App\Services\DavClient\Utils\Model\ContactDto;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class GetVCardTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
use CardEtag;
|
||||
|
||||
/** @test */
|
||||
public function it_get_card()
|
||||
{
|
||||
$fake = Bus::fake();
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$addressBookSubscription = AddressBookSubscription::factory()->create([
|
||||
'account_id' => $user->account_id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$contact = new Contact();
|
||||
$contact->forceFill([
|
||||
'first_name' => 'Test',
|
||||
'uuid' => 'affacde9-b2fe-4371-9acb-6612aaee6971',
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
$card = $this->getCard($contact);
|
||||
$etag = $this->getEtag($contact, true);
|
||||
|
||||
Http::fake([
|
||||
'https://test/dav/uri' => Http::response($card, 200),
|
||||
]);
|
||||
|
||||
$pendingBatch = $fake->batch([
|
||||
$job = new GetVCard($addressBookSubscription, new ContactDto('https://test/dav/uri', $etag)),
|
||||
]);
|
||||
$batch = $pendingBatch->dispatch();
|
||||
|
||||
$fake->assertBatched(function (PendingBatch $pendingBatch) {
|
||||
$this->assertCount(1, $pendingBatch->jobs);
|
||||
$this->assertInstanceOf(GetVCard::class, $pendingBatch->jobs->first());
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$batch = app(DatabaseBatchRepository::class)->store($pendingBatch);
|
||||
$job->withBatchId($batch->id)->handle();
|
||||
|
||||
$fake->assertDispatched(function (UpdateVCard $updateVCard) use ($etag, $card) {
|
||||
$dto = $this->getPrivateValue($updateVCard, 'contact');
|
||||
$this->assertEquals('https://test/dav/uri', $dto->uri);
|
||||
$this->assertEquals($etag, $dto->etag);
|
||||
$this->assertEquals($card, $dto->card);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
85
tests/Unit/Jobs/Dav/PushVCardTest.php
Normal file
85
tests/Unit/Jobs/Dav/PushVCardTest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Jobs\Dav;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use App\Jobs\Dav\PushVCard;
|
||||
use Tests\Api\DAV\CardEtag;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Bus\PendingBatch;
|
||||
use Illuminate\Http\Client\Request;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Bus\DatabaseBatchRepository;
|
||||
use App\Models\Account\AddressBookSubscription;
|
||||
use App\Services\DavClient\Utils\Model\ContactPushDto;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class PushVCardTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
use CardEtag;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider modes
|
||||
*/
|
||||
public function it_push_card($mode, $ifmatch)
|
||||
{
|
||||
$fake = Bus::fake();
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$addressBookSubscription = AddressBookSubscription::factory()->create([
|
||||
'account_id' => $user->account_id,
|
||||
'user_id' => $user->id,
|
||||
'uri' => 'https://test/dav',
|
||||
]);
|
||||
|
||||
$contact = factory(Contact::class)->create([
|
||||
'account_id' => $user->account_id,
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe',
|
||||
'uuid' => 'affacde9-b2fe-4371-9acb-6612aaee6971',
|
||||
'updated_at' => '2021-09-01',
|
||||
]);
|
||||
$card = $this->getCard($contact);
|
||||
$etag = $this->getEtag($contact, true);
|
||||
|
||||
if ($ifmatch == ['etag']) {
|
||||
$ifmatch = [$etag];
|
||||
}
|
||||
|
||||
Http::fake(function (Request $request, $options) use ($card, $ifmatch) {
|
||||
$this->assertEquals('https://test/dav/uri', $request->url());
|
||||
$this->assertEquals('PUT', $request->method());
|
||||
$this->assertEquals($ifmatch, $request->header('If-Match'));
|
||||
|
||||
return Http::response($card, 200);
|
||||
});
|
||||
|
||||
$pendingBatch = $fake->batch([
|
||||
$job = new PushVCard($addressBookSubscription, new ContactPushDto('https://test/dav/uri', $etag, $card, $contact->id, $mode)),
|
||||
]);
|
||||
$batch = $pendingBatch->dispatch();
|
||||
|
||||
$fake->assertBatched(function (PendingBatch $pendingBatch) {
|
||||
$this->assertCount(1, $pendingBatch->jobs);
|
||||
$this->assertInstanceOf(PushVCard::class, $pendingBatch->jobs->first());
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$batch = app(DatabaseBatchRepository::class)->store($pendingBatch);
|
||||
$job->withBatchId($batch->id)->handle();
|
||||
}
|
||||
|
||||
public function modes(): array
|
||||
{
|
||||
return [
|
||||
[0, []],
|
||||
[1, ['etag']],
|
||||
[2, ['*']],
|
||||
];
|
||||
}
|
||||
}
|
||||
62
tests/Unit/Jobs/Dav/UpdateVCardTest.php
Normal file
62
tests/Unit/Jobs/Dav/UpdateVCardTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Jobs\Dav;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use Tests\Api\DAV\CardEtag;
|
||||
use App\Jobs\Dav\UpdateVCard;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Bus\PendingBatch;
|
||||
use App\Models\Account\AddressBook;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Bus\DatabaseBatchRepository;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use App\Services\DavClient\Utils\Model\ContactUpdateDto;
|
||||
|
||||
class UpdateVCardTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
use CardEtag;
|
||||
|
||||
/** @test */
|
||||
public function it_create_a_contact()
|
||||
{
|
||||
$fake = Bus::fake();
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
$addressBook = AddressBook::factory()->create([
|
||||
'account_id' => $user->account_id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$contact = new Contact();
|
||||
$contact->forceFill([
|
||||
'first_name' => 'Test',
|
||||
'uuid' => 'affacde9-b2fe-4371-9acb-6612aaee6971',
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
$card = $this->getCard($contact);
|
||||
$etag = $this->getEtag($contact, true);
|
||||
|
||||
$pendingBatch = $fake->batch([
|
||||
$job = new UpdateVCard($user, $addressBook->name, new ContactUpdateDto('https://test/dav/uricontact1', $etag, $card)),
|
||||
]);
|
||||
$batch = $pendingBatch->dispatch();
|
||||
|
||||
$fake->assertBatched(function (PendingBatch $pendingBatch) {
|
||||
$this->assertCount(1, $pendingBatch->jobs);
|
||||
$this->assertInstanceOf(UpdateVCard::class, $pendingBatch->jobs->first());
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$batch = app(DatabaseBatchRepository::class)->store($pendingBatch);
|
||||
$job->withBatchId($batch->id)->handle();
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'first_name' => 'Test',
|
||||
'uuid' => 'affacde9-b2fe-4371-9acb-6612aaee6971',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user