Skip to content

Commit

Permalink
Merge pull request #9 from roberts/drewroberts/feature/6-lead-businesses
Browse files Browse the repository at this point in the history
Rename Lead Business #6
  • Loading branch information
drewroberts authored Mar 18, 2021
2 parents 3972372 + 0811715 commit c1daae4
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@

namespace Roberts\Leads\Database\Factories;

use Roberts\Leads\Models\WcBusiness;
use Roberts\Leads\Models\LeadBusiness;
use Illuminate\Database\Eloquent\Factories\Factory;

class WcBusinessFactory extends Factory
class LeadBusinessFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = WcBusiness::class;
protected $model = LeadBusiness::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
Expand Down
16 changes: 3 additions & 13 deletions database/factories/LeadFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,18 @@
namespace Roberts\Leads\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Roberts\Leads\Models\WcBusiness;
use Roberts\Leads\Models\LeadBusiness;
use Roberts\Leads\Models\Lead;

class LeadFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Lead::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'email' => $this->faker->email,
'wc_business_id' => WcBusiness::factory(),
'lead_business_id' => LeadBusiness::factory(),
];
}

Expand All @@ -39,7 +29,7 @@ public function withNullableFields()
'current_plan_under_cancellation' => $this->faker->boolean,
'current_plan_expires_at' => $this->faker->date,
'past_comp_claims' => $this->faker->paragraph,
'wc_business_id' => WcBusiness::factory(),
'lead_business_id' => LeadBusiness::factory(),
];
});
}
Expand Down
6 changes: 3 additions & 3 deletions database/migrations/2021_01_01_100000_create_leads_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Roberts\Leads\Models\WcBusiness;
use Roberts\Leads\Models\LeadBusiness;

class CreateLeadsTable extends Migration
{
Expand All @@ -13,13 +13,13 @@ public function up()
$table->id();
$table->string('lead_number')->index()->unique(); // Generated by system. This is identifier used to communicate about the quote request & for additional form pages.
$table->string('email');
$table->foreignIdFor(WcBusiness::class);
$table->foreignIdFor(LeadBusiness::class);
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('position')->nullable();
$table->string('phone_number')->nullable(); // Will be replaced later with relationship to Phone model in tipoff/addresses

// Move these 3 fields to WcBusiness table
// Move these 3 fields to LeadBusiness table
$table->boolean('current_plan_under_cancellation')->nullable();
$table->date('current_plan_expires_at')->nullable();
$table->text('past_comp_claims')->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateWcBusinessesTable extends Migration
class CreateLeadBusinessesTable extends Migration
{
public function up()
{
Schema::create('wc_businesses', function (Blueprint $table) {
Schema::create('lead_businesses', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('nature')->nullable();
Expand Down
6 changes: 3 additions & 3 deletions src/Livewire/OnboardingForm/Presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Roberts\Leads\Enums\OnboardingFormStep;
use Roberts\Leads\Models\Lead;
use Roberts\Leads\Models\WcBusiness;
use Roberts\Leads\Models\LeadBusiness;

class Presentation extends OnboardingFormStepComponent
{
Expand All @@ -22,11 +22,11 @@ public function render()

public function processLead(array $data)
{
$business = WcBusiness::create($data['business']);
$business = LeadBusiness::create($data['business']);

return Lead::create([
'email' => $data['email'],
'wc_business_id' => $business->id,
'lead_business_id' => $business->id,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Lead.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function generateLeadNumber(): string

public function business()
{
return $this->belongsTo(WcBusiness::class, 'wc_business_id');
return $this->belongsTo(LeadBusiness::class, 'lead_business_id');
}

public function payrollClassifications()
Expand Down
4 changes: 1 addition & 3 deletions src/Models/WcBusiness.php → src/Models/LeadBusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use Tipoff\Support\Models\BaseModel;
use Tipoff\Support\Traits\HasPackageFactory;

class WcBusiness extends BaseModel
class LeadBusiness extends BaseModel
{
use HasPackageFactory;

protected $guarded = [];
}
10 changes: 5 additions & 5 deletions tests/Feature/LivewireComponents/BusinessDetailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Livewire\Livewire;
use Roberts\Leads\Livewire\OnboardingForm\BusinessDetails;
use Roberts\Leads\Models\Lead;
use Roberts\Leads\Models\WcBusiness;
use Roberts\Leads\Models\LeadBusiness;
use Roberts\Leads\Tests\TestCase;

class BusinessDetailsTest extends TestCase
Expand All @@ -16,10 +16,10 @@ class BusinessDetailsTest extends TestCase
/** @test */
public function a_user_can_add_business_details()
{
$business = WcBusiness::factory()->create();
$lead = Lead::factory()->create(['wc_business_id' => $business->id]);
$business = LeadBusiness::factory()->create();
$lead = Lead::factory()->create(['lead_business_id' => $business->id]);

$attributes = WcBusiness::factory()
$attributes = LeadBusiness::factory()
->withNullableFields()
->raw(['name' => $business->name]);

Expand All @@ -31,7 +31,7 @@ public function a_user_can_add_business_details()
->set('attributes.year_of_establishment', $attributes['year_of_establishment'])
->call('submit');

$this->assertDatabaseHas('wc_businesses', $attributes);
$this->assertDatabaseHas('lead_businesses', $attributes);
}

/** @test */
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/LivewireComponents/PresentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public function a_user_can_create_a_lead()
->set('attributes.business.name', $attributes['business_name'])
->call('submit');

$this->assertDatabaseHas('wc_businesses', [
$this->assertDatabaseHas('lead_businesses', [
'name' => $attributes['business_name'],
]);

$this->assertDatabaseHas('leads', [
'email' => $attributes['email'],
'wc_business_id' => 1,
'lead_business_id' => 1,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Roberts\Leads\Models\WcBusiness;
use Roberts\Leads\Models\LeadBusiness;
use Roberts\Leads\Tests\TestCase;

class WcBusinessTest extends TestCase
class LeadBusinessTest extends TestCase
{
use RefreshDatabase;
use WithFaker;
Expand All @@ -16,7 +16,7 @@ class WcBusinessTest extends TestCase
public function it_has_a_name()
{
$name = $this->faker->company;
$business = WcBusiness::factory()->create(['name' => $name]);
$business = LeadBusiness::factory()->create(['name' => $name]);

$this->assertEquals($name, $business->name);
}
Expand All @@ -25,7 +25,7 @@ public function it_has_a_name()
public function it_has_a_nature()
{
$nature = $this->faker->word;
$business = WcBusiness::factory()->create(['nature' => $nature]);
$business = LeadBusiness::factory()->create(['nature' => $nature]);

$this->assertEquals($nature, $business->nature);
}
Expand All @@ -34,7 +34,7 @@ public function it_has_a_nature()
public function it_has_a_fein()
{
$fein = $this->faker->uuid;
$business = WcBusiness::factory()->create(['fein' => $fein]);
$business = LeadBusiness::factory()->create(['fein' => $fein]);

$this->assertEquals($fein, $business->fein);
}
Expand All @@ -43,7 +43,7 @@ public function it_has_a_fein()
public function it_has_the_year_of_establishment()
{
$year = $this->faker->numberBetween(1900, 2010);
$business = WcBusiness::factory()->create(['year_of_establishment' => $year]);
$business = LeadBusiness::factory()->create(['year_of_establishment' => $year]);

$this->assertEquals($year, $business->year_of_establishment);
}
Expand All @@ -52,7 +52,7 @@ public function it_has_the_year_of_establishment()
public function it_has_a_legal_entity_type()
{
$type = $this->faker->word;
$business = WcBusiness::factory()->create(['legal_entity_type' => $type]);
$business = LeadBusiness::factory()->create(['legal_entity_type' => $type]);

$this->assertEquals($type, $business->legal_entity_type);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Models/LeadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Carbon;
use Roberts\Leads\Models\Lead;
use Roberts\Leads\Models\WcBusiness;
use Roberts\Leads\Models\LeadBusiness;
use Roberts\Leads\Models\WcPayrollClassification;
use Roberts\Leads\Tests\TestCase;

Expand Down Expand Up @@ -91,7 +91,7 @@ public function it_is_associated_with_a_business()
{
$lead = Lead::factory()->create();

$this->assertInstanceOf(WcBusiness::class, $lead->business);
$this->assertInstanceOf(LeadBusiness::class, $lead->business);
}

/** @test */
Expand Down

0 comments on commit c1daae4

Please sign in to comment.