Created
July 1, 2019 08:41
-
-
Save nutch31/5ccaddb2db4e95267f329b8be4d11d36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Faker\Generator as Faker; | |
use App\Country; | |
use App\CampaignStatus; | |
use App\DurationCycleUnit; | |
use App\PaymentType; | |
use App\PaymentTerm; | |
use App\LandingPageLanguage; | |
use App\Currency; | |
use App\ClientType; | |
use App\User; | |
use App\Opportunity; | |
$factory->define(App\Campaign::class, function (Faker $faker) { | |
if (!Opportunity::count()) { | |
factory(Opportunity::class, config('seeder.opportunity'))->create(); | |
} | |
if (!Country::count()) { | |
factory(Country::class, config('seeder.country'))->create(); | |
} | |
if (!CampaignStatus::count()) { | |
factory(CampaignStatus::class, config('seeder.campaign_status'))->create(); | |
} | |
if (!DurationCycleUnit::count()) { | |
factory(DurationCycleUnit::class, config('seeder.duration_cycle_unit'))->create(); | |
} | |
if (!PaymentTerm::count()) { | |
factory(PaymentTerm::class, config('seeder.payment_term'))->create(); | |
} | |
if (!PaymentType::count()) { | |
factory(PaymentType::class, config('seeder.payment_type'))->create(); | |
} | |
if (!LandingPageLanguage::count()) { | |
factory(LandingPageLanguage::class, config('seeder.landing_page_language'))->create(); | |
} | |
if (!ClientType::count()) { | |
factory(ClientType::class, config('seeder.client_type'))->create(); | |
} | |
// Random datetime | |
$startingDate = $faker->dateTimeBetween('-6 months'); | |
// Random datetime *after* `$startingDate` | |
$endingDate = $faker->dateTimeBetween($startingDate, strtotime('+10 months')); | |
$landingPageLanguage1 = LandingPageLanguage::all(['_id'])->random(); | |
do { | |
$landingPageLanguage2 = LandingPageLanguage::all(['_id'])->random(); | |
} while ($landingPageLanguage1->_id == $landingPageLanguage2->_id); | |
$influencerUserGroup = \App\Group::firstOrCreate(['name' => 'Influencer']); | |
$usersInGroup = $influencerUserGroup->users()->get(); | |
if ($usersInGroup->count() == 0) {// Group don't have user. | |
// Create new user and assign to group. | |
$user = factory(User::class)->create(); | |
$influencerUserGroup->users()->attach([$user->_id]); | |
$usersInGroup = $influencerUserGroup->users()->get(); | |
} | |
$opportunity = Opportunity::all()->random(); | |
return [ | |
'_id' => strtoupper($faker->lexify('0018F000??????????')), | |
'name' => $faker->name(), | |
'opportunity_id' => $opportunity->_id, | |
'campaign_status_id' => CampaignStatus::all(['_id'])->random(), | |
'monthly_budget' => $faker->randomFloat(2, 5000, 10000), | |
'one_time_setup_fee' => $faker->randomFloat(2, 5000, 10000), | |
'management_fee' => $opportunity->management_fee, | |
'management_fee_type' => $opportunity->management_fee_type, | |
'bonus' => $faker->randomFloat(2, 5000, 10000), | |
'expected_monthly_budget' => $faker->randomFloat(2, 5000, 10000), | |
'duration' => $faker->randomNumber(), | |
'duration_cycle_number' => $faker->randomDigit(), | |
'duration_cycle_unit_id' => DurationCycleUnit::all(['_id'])->random(), | |
'payment_type_id' => PaymentType::all(['_id'])->random(), | |
'landing_page_language_id' => LandingPageLanguage::all(['_id'])->random(), | |
'account_id' => null, | |
'account_manager_id' => null, | |
'owner_id' => null, | |
'uniqued_selling_point' => $faker->text(), | |
'service_focus' => $faker->randomFloat(2, 5000, 10000), | |
'keyword_ideas' => 'coffee', | |
'country_id' => Country::all(['_id'])->random(), | |
'creator_id' => null, | |
'total_budget' => $faker->randomFloat(2, 5000, 10000), | |
'start' => $startingDate, | |
'end' => $endingDate, | |
'customer_kpi' => $faker->text(), | |
'payment_term_id' => PaymentTerm::all(['_id'])->random(), | |
'name_of_finance_contact' => $faker->name, | |
'phone_of_finance_contact' => $faker->phoneNumber(), | |
'email_of_finance_contact' => $faker->email(), | |
'finance_process' => $faker->text(), | |
'stage_name' => $faker->sentence(), | |
'type' => $faker->randomElement(['TYPE1', 'TYPE2']), | |
'churn_date' => $faker->dateTime(), | |
'churn_explanation' => $faker->sentence(), | |
'churn_reason' => $faker->sentence(), | |
'industry' => $faker->sentence(), | |
'is_closed' => $faker->boolean, | |
'is_won' => $faker->boolean, | |
'sales_approval' => $faker->boolean, | |
'special_approval_for_management_fee' => $faker->boolean, | |
'special_approval_for_payment_terms' => $faker->boolean, | |
'total_amount_due' => $faker->randomFloat(2, 5000, 10000), | |
'total_amount_invoiced' => $faker->randomFloat(2, 5000, 10000), | |
'total_amount_overdue' => $faker->randomFloat(2, 5000, 10000), | |
'total_amount_paid' => $faker->randomFloat(2, 5000, 10000), | |
'description' => $faker->text(), | |
'google_account_id' => $faker->randomNumber(7), | |
'facebook_account_id' => $faker->randomNumber(7), | |
'currency_id' => Currency::all(['_id'])->random(), | |
'days_to_eoc' => $faker->dateTime(), | |
'close_date' => $faker->dateTime(), | |
'customer_paid_or_payment_terms_granted'=> $faker->boolean(), | |
'renewal_flag' => $faker->boolean(), | |
'actual_campaign_start_date' => $startingDate, | |
'actual_campaign_end_date' => $endingDate, | |
'upsell_potential' => $faker->boolean(), | |
'business_type_id' => null, | |
'email_lead' => null, | |
'target_url' => null, | |
'expire_date' => null, | |
'forward_number' => null, | |
'did_phone' => null, | |
'package_selling' => null, | |
'report_system_id' => null, | |
'ad_scheduling_start' => now()->startOfDay()->format("H:i"), | |
'ad_scheduling_end' => now()->endOfDay()->format("H:i"), | |
'ad_language_ids' => [], | |
'target_audience_geo_focus' => null, | |
'target_audience' => null, | |
'target_audience_level_ids' => null, | |
'client_website' => null, | |
'landing_page_type_id' => null, | |
'media_plan' => null, | |
'additional_information' => null, | |
"contact_tel" => $faker->text(50), | |
"contact_person" => $faker->text(50), | |
"contact_email" => $faker->safeEmail, | |
"send_proposal" => \Carbon\Carbon::now(), | |
"influencer_details" => $faker->text(50), | |
"influencer_validation" => $faker->text(50), | |
"proposal" => null, | |
"client_type_id" => ClientType::all(['_id'])->random(), | |
"gross_profit" => $faker->numberBetween(1000, 10000), | |
"client_paid" => $faker->numberBetween(1100, 11000), | |
"influencer_ongoing" => $usersInGroup->random(), | |
'last_modified_date' => now(), | |
'sf_last_modified_date' => now(), | |
'owner_count' => 0, | |
'seed' => true, | |
]; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests; | |
use App\Campaign; | |
use Illuminate\Foundation\Testing\RefreshDatabase; | |
class CampaignApiTest extends TestCase | |
{ | |
use RefreshDatabase; | |
public function test_can_get_information_by_social_account_ids() | |
{ | |
$params = ["googleIds" => [], "facebookIds" => []]; | |
// Create data. | |
$campaign1 = factory(Campaign::class)->create([ | |
"google_account_id" => "167-098-3415", | |
"facebook_account_id" => "1272451272900490", | |
]); | |
$campaign2 = factory(Campaign::class)->create([ | |
"google_account_id" => "179-837-2109", | |
"facebook_account_id" => null, | |
]); | |
$opportunityIds = []; | |
foreach ([$campaign1, $campaign2] as $campaign) { | |
if (!empty($campaign->google_account_id)) { | |
array_push($params["googleIds"], $campaign->google_account_id); | |
} | |
if (!empty($campaign->facebook_account_id)) { | |
array_push($params["facebookIds"], $campaign->facebook_account_id); | |
} | |
// Get list opportunity id. | |
array_push($opportunityIds, $campaign->opportunity_id); | |
} | |
// Test return status. | |
$headers = ['secretKey' => env('APP_ANALYTIC_SERVICE_SECRECT_KEY')]; | |
$response = $this->post(route('campaign.get-information-by-social-account-ids'), $params, $headers)->assertStatus(200); | |
$responseData = $response->getData()->data; | |
// Test return data from DB. | |
$this->assertEquals(2, count($responseData)); | |
$this->assertTrue(in_array($responseData[0]->opportunity_id, $opportunityIds)); | |
$this->assertTrue(in_array($responseData[1]->opportunity_id, $opportunityIds)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment