Skip to content

Commit 1de263c

Browse files
author
angel cruz
committed
I transformed a bug into a feature. Once you learn how, you'll never forget it
1 parent 042870e commit 1de263c

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

database/factories/NoteFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Database\Eloquent\Factories\Factory;
66

77

8-
class LeadFactory extends Factory
8+
class NoteFactory extends Factory
99
{
1010
protected $model = \Tepuilabs\SimpleCrm\Models\Note::class;
1111

database/factories/UserFactory.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Tepuilabs\SimpleCrm\Database\Factories;
4+
5+
use Illuminate\Support\Str;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
8+
class UserFactory extends Factory
9+
{
10+
/**
11+
* The name of the factory's corresponding model.
12+
*
13+
* @var string
14+
*/
15+
protected $model = \Tepuilabs\SimpleCrm\Tests\Models\User::class;
16+
17+
/**
18+
* Define the model's default state.
19+
*
20+
* @return array
21+
*/
22+
public function definition()
23+
{
24+
return [
25+
'name' => $this->faker->name,
26+
'email' => $this->faker->unique()->safeEmail,
27+
'email_verified_at' => now(),
28+
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
29+
'remember_token' => Str::random(10),
30+
];
31+
}
32+
}

tests/Unit/NoteTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
class NoteTest extends TestCase
88
{
99
/** @test */
10-
public function test_it_has_an_author_type()
10+
public function test_it_user_can_create_a_note()
1111
{
12-
$article = Note::factory()->create(['author_type' => 'Fake\User']);
12+
$user = \Tepuilabs\SimpleCrm\Tests\Models\User::factory()->create();
13+
$lead = \Tepuilabs\SimpleCrm\Models\Lead::factory()->create();
1314

14-
$this->assertEquals('Fake\User', $article->author_type);
15+
$note = $user->notes()->create([
16+
'priority' => 'Low',
17+
'title' => 'Some title',
18+
'body' => 'Some body',
19+
'lead_id' => $lead->id,
20+
]);
21+
22+
$this->assertInstanceOf(Note::class, $note);
1523
}
1624
}

0 commit comments

Comments
 (0)