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:
250
tests/Unit/Services/Contact/Call/CreateCallTest.php
Normal file
250
tests/Unit/Services/Contact/Call/CreateCallTest.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Contact\Call;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Contact\Call;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Instance\Emotion\Emotion;
|
||||
use App\Services\Contact\Call\CreateCall;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class CreateCallTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_stores_a_call()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
];
|
||||
|
||||
$call = app(CreateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('calls', [
|
||||
'id' => $call->id,
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'content' => 'this is the content',
|
||||
'contact_called' => 0,
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Call::class,
|
||||
$call
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_stores_a_call_and_who_called_information()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
'contact_called' => true,
|
||||
];
|
||||
|
||||
$call = app(CreateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('calls', [
|
||||
'id' => $call->id,
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'content' => 'this is the content',
|
||||
'contact_called' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_adds_emotions()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
$emotion = factory(Emotion::class)->create([]);
|
||||
$emotion2 = factory(Emotion::class)->create([]);
|
||||
|
||||
$emotionArray = [];
|
||||
$emotionArray[] = $emotion->id;
|
||||
$emotionArray[] = $emotion2->id;
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
'contact_called' => true,
|
||||
'emotions' => $emotionArray,
|
||||
];
|
||||
|
||||
$call = app(CreateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('calls', [
|
||||
'id' => $call->id,
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'content' => 'this is the content',
|
||||
'contact_called' => 1,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('emotion_call', [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('emotion_call', [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion2->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_adding_emotions_when_emotion_is_unknown()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
$emotionArray = [];
|
||||
$emotionArray[] = 1111111;
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
'contact_called' => true,
|
||||
'emotions' => $emotionArray,
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
|
||||
app(CreateCall::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_stores_a_call_without_the_content()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'called_at' => now(),
|
||||
];
|
||||
|
||||
$call = app(CreateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('calls', [
|
||||
'id' => $call->id,
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'content' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_the_last_call_info()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([
|
||||
'last_talked_to' => '1900-01-01 00:00:00',
|
||||
]);
|
||||
|
||||
$date = now();
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'called_at' => $date,
|
||||
];
|
||||
|
||||
app(CreateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'id' => $contact->id,
|
||||
'last_talked_to' => $date->toDateString(),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_doesnt_update_the_last_call_info()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([
|
||||
'last_talked_to' => '2200-01-01 00:00:00',
|
||||
]);
|
||||
|
||||
$date = now();
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'called_at' => $date,
|
||||
];
|
||||
|
||||
app(CreateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'id' => $contact->id,
|
||||
'last_talked_to' => '2200-01-01',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'called_at' => now(),
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(CreateCall::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_contact_is_archived()
|
||||
{
|
||||
$contact = factory(Contact::class)->state('archived')->create([]);
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $contact->account_id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(CreateCall::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_contact_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create();
|
||||
$contact = factory(Contact::class)->create();
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'account_id' => $account->id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(CreateCall::class)->execute($request);
|
||||
}
|
||||
}
|
||||
148
tests/Unit/Services/Contact/Call/DestroyCallTest.php
Normal file
148
tests/Unit/Services/Contact/Call/DestroyCallTest.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Contact\Call;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Contact\Call;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Instance\Emotion\Emotion;
|
||||
use App\Services\Contact\Call\DestroyCall;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class DestroyCallTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_destroys_a_call()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact->id,
|
||||
'called_at' => '2008-01-01',
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
];
|
||||
|
||||
$this->assertDatabaseHas('calls', [
|
||||
'id' => $call->id,
|
||||
]);
|
||||
|
||||
app(DestroyCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('calls', [
|
||||
'id' => $call->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_removes_emotions()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact->id,
|
||||
]);
|
||||
|
||||
$emotion = factory(Emotion::class)->create([]);
|
||||
|
||||
DB::table('emotion_call')->insert([
|
||||
'account_id' => $call->account_id,
|
||||
'contact_id' => $call->contact_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion->id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
];
|
||||
|
||||
app(DestroyCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseMissing('emotion_call', [
|
||||
'contact_id' => $call->contact_id,
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_the_last_talked_to_information()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([
|
||||
'last_talked_to' => '2008-01-01',
|
||||
]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact->id,
|
||||
'called_at' => '2008-01-01',
|
||||
]);
|
||||
$call2 = factory(Call::class)->create([
|
||||
'contact_id' => $contact->id,
|
||||
'called_at' => '1990-01-01',
|
||||
]);
|
||||
$call3 = factory(Call::class)->create([
|
||||
'contact_id' => $contact->id,
|
||||
'called_at' => '1980-01-01',
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
];
|
||||
|
||||
app(DestroyCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'id' => $contact->id,
|
||||
'last_talked_to' => '1990-01-01',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_doesnt_update_the_last_talked_to_information()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([
|
||||
'last_talked_to' => '2008-01-01',
|
||||
]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact->id,
|
||||
'called_at' => '2008-01-01',
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
];
|
||||
|
||||
app(DestroyCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'id' => $contact->id,
|
||||
'last_talked_to' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_contact_is_archived()
|
||||
{
|
||||
$contact = factory(Contact::class)->state('archived')->create([]);
|
||||
$call = factory(Call::class)->create([
|
||||
'account_id' => $contact->account_id,
|
||||
'contact_id' => $contact->id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(DestroyCall::class)->execute($request);
|
||||
}
|
||||
}
|
||||
333
tests/Unit/Services/Contact/Call/UpdateCallTest.php
Normal file
333
tests/Unit/Services/Contact/Call/UpdateCallTest.php
Normal file
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Contact\Call;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Contact\Call;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Instance\Emotion\Emotion;
|
||||
use App\Services\Contact\Call\UpdateCall;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class UpdateCallTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_call()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact,
|
||||
'account_id' => $contact->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
];
|
||||
|
||||
$call = app(UpdateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('calls', [
|
||||
'id' => $call->id,
|
||||
'contact_id' => $call->contact_id,
|
||||
'account_id' => $call->contact->account_id,
|
||||
'content' => 'this is the content',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Call::class,
|
||||
$call
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_call_and_who_called_info()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact,
|
||||
'account_id' => $contact->account_id,
|
||||
'contact_called' => 0,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
'contact_called' => 1,
|
||||
];
|
||||
|
||||
$call = app(UpdateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('calls', [
|
||||
'id' => $call->id,
|
||||
'contact_id' => $call->contact_id,
|
||||
'account_id' => $call->contact->account_id,
|
||||
'content' => 'this is the content',
|
||||
'contact_called' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_a_call_without_the_content()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact,
|
||||
'account_id' => $contact->account_id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'called_at' => now(),
|
||||
];
|
||||
|
||||
$call = app(UpdateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('calls', [
|
||||
'id' => $call->id,
|
||||
'contact_id' => $call->contact_id,
|
||||
'account_id' => $call->contact->account_id,
|
||||
'content' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that it adds new emotions.
|
||||
*/
|
||||
|
||||
/** @test */
|
||||
public function it_updates_emotions()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact->id,
|
||||
]);
|
||||
$emotion = factory(Emotion::class)->create([]);
|
||||
$emotion2 = factory(Emotion::class)->create([]);
|
||||
|
||||
DB::table('emotion_call')->insert([
|
||||
'account_id' => $call->account_id,
|
||||
'contact_id' => $call->contact_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion->id,
|
||||
]);
|
||||
|
||||
$emotionArray = [];
|
||||
$emotionArray[] = $emotion->id;
|
||||
$emotionArray[] = $emotion2->id;
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
'contact_called' => 1,
|
||||
'emotions' => $emotionArray,
|
||||
];
|
||||
|
||||
$call = app(UpdateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('emotion_call', [
|
||||
'contact_id' => $call->contact_id,
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('emotion_call', [
|
||||
'contact_id' => $call->contact_id,
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion2->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that it removes old emotion and add new emotions.
|
||||
*/
|
||||
|
||||
/** @test */
|
||||
public function it_deletes_and_updates_emotions()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact->id,
|
||||
]);
|
||||
$emotion = factory(Emotion::class)->create([]);
|
||||
$emotion2 = factory(Emotion::class)->create([]);
|
||||
|
||||
DB::table('emotion_call')->insert([
|
||||
'account_id' => $call->account_id,
|
||||
'contact_id' => $call->contact_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion->id,
|
||||
]);
|
||||
|
||||
DB::table('emotion_call')->insert([
|
||||
'account_id' => $call->account_id,
|
||||
'contact_id' => $call->contact_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion2->id,
|
||||
]);
|
||||
|
||||
$emotion3 = factory(Emotion::class)->create([]);
|
||||
$emotion4 = factory(Emotion::class)->create([]);
|
||||
$emotionArray = [];
|
||||
$emotionArray[] = $emotion3->id;
|
||||
$emotionArray[] = $emotion4->id;
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
'contact_called' => 1,
|
||||
'emotions' => $emotionArray,
|
||||
];
|
||||
|
||||
$call = app(UpdateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('emotion_call', [
|
||||
'contact_id' => $call->contact_id,
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion3->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('emotion_call', [
|
||||
'contact_id' => $call->contact_id,
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion4->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('emotion_call', [
|
||||
'contact_id' => $call->contact_id,
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('emotion_call', [
|
||||
'contact_id' => $call->contact_id,
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'emotion_id' => $emotion2->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_the_last_call_info()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([
|
||||
'last_talked_to' => '1900-01-01 00:00:00',
|
||||
]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact,
|
||||
'account_id' => $contact->account_id,
|
||||
]);
|
||||
|
||||
$date = now();
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'called_at' => now(),
|
||||
];
|
||||
|
||||
app(UpdateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'id' => $contact->id,
|
||||
'last_talked_to' => $date->toDateString(),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_doesnt_update_the_last_call_info()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([
|
||||
'last_talked_to' => '2200-01-01 00:00:00',
|
||||
]);
|
||||
$call = factory(Call::class)->create([
|
||||
'contact_id' => $contact,
|
||||
'account_id' => $contact->account_id,
|
||||
]);
|
||||
|
||||
$date = now();
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'called_at' => now(),
|
||||
];
|
||||
|
||||
app(UpdateCall::class)->execute($request);
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'id' => $contact->id,
|
||||
'last_talked_to' => '2200-01-01',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_wrong_parameters_are_given()
|
||||
{
|
||||
$contact = factory(Contact::class)->create([]);
|
||||
|
||||
$request = [
|
||||
'contact_id' => $contact->id,
|
||||
'called_at' => now(),
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(UpdateCall::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_call_is_not_linked_to_account()
|
||||
{
|
||||
$account = factory(Account::class)->create();
|
||||
$call = factory(Call::class)->create();
|
||||
|
||||
$request = [
|
||||
'account_id' => $account->id,
|
||||
'call_id' => $call->id,
|
||||
'called_at' => now(),
|
||||
];
|
||||
|
||||
$this->expectException(ModelNotFoundException::class);
|
||||
app(UpdateCall::class)->execute($request);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_if_contact_is_archived()
|
||||
{
|
||||
$contact = factory(Contact::class)->state('archived')->create([]);
|
||||
$call = factory(Call::class)->create([
|
||||
'account_id' => $contact->account_id,
|
||||
'contact_id' => $contact->id,
|
||||
]);
|
||||
|
||||
$request = [
|
||||
'account_id' => $call->account_id,
|
||||
'call_id' => $call->id,
|
||||
'called_at' => now(),
|
||||
'content' => 'this is the content',
|
||||
];
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(UpdateCall::class)->execute($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user