mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Add Quotes to RandomDataSeeder (#3714)
* Skip preview tests * Fixes for product test * Fixes for tests * Update README.md * Update README.md * Update README.md * Update README.md * Fixes for incorrect payment types * Refactor class nameS * Entity Notification refactor * Entity Notifications * Add Quotes to randomdataseederr
This commit is contained in:
parent
6f373efd0d
commit
659af63b5c
@ -2,6 +2,7 @@
|
||||
<img src="https://raw.githubusercontent.com/hillelcoren/invoice-ninja/master/public/images/round_logo.png" alt="Sublime's custom image"/>
|
||||
</p>
|
||||
|
||||

|
||||
[](https://travis-ci.org/invoiceninja/invoiceninja)
|
||||
[](https://codecov.io/gh/invoiceninja/invoiceninja)
|
||||
[](https://www.codacy.com/app/turbo124/invoiceninja?utm_source=github.com&utm_medium=referral&utm_content=invoiceninja/invoiceninja&utm_campaign=Badge_Grade)
|
||||
|
@ -115,7 +115,9 @@ class EmailController extends BaseController
|
||||
$entity_string = strtolower(class_basename($entity_obj));
|
||||
|
||||
$entity_obj->invitations->each(function ($invitation) use ($subject, $body, $entity_string, $entity_obj) {
|
||||
|
||||
if ($invitation->contact->send_email && $invitation->contact->email) {
|
||||
|
||||
$when = now()->addSeconds(1);
|
||||
|
||||
$invitation->contact->notify((new SendGenericNotification($invitation, $entity_string, $subject, $body))->delay($when));
|
||||
@ -123,6 +125,7 @@ class EmailController extends BaseController
|
||||
EntitySentEmail::dispatch($invitation, $entity_string, $entity_obj->user, $invitation->company);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if ($this instanceof Invoice) {
|
||||
|
@ -5,7 +5,7 @@ namespace App\Jobs\Mail;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Libraries\Google\Google;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntitySent;
|
||||
use App\Mail\Admin\EntityNotificationMailer;
|
||||
use App\Mail\Admin\EntitySentObject;
|
||||
use App\Models\SystemLog;
|
||||
use App\Models\User;
|
||||
@ -56,7 +56,7 @@ class EntitySentEmail extends BaseMailerJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//set DB
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
//if we need to set an email driver do it now
|
||||
@ -66,9 +66,8 @@ class EntitySentEmail extends BaseMailerJob implements ShouldQueue
|
||||
$mail_obj->from = $this->entity->user->present()->name();
|
||||
|
||||
//send email
|
||||
// Mail::to($this->user->email)
|
||||
Mail::to('turbo124@gmail.com') //@todo
|
||||
->send(new EntitySent($mail_obj));
|
||||
Mail::to($this->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
|
||||
//catch errors
|
||||
if (count(Mail::failures()) > 0) {
|
||||
|
@ -13,6 +13,7 @@ namespace App\Listeners\Credit;
|
||||
|
||||
use App\Factory\CreditInvitationFactory;
|
||||
use App\Factory\InvoiceInvitationFactory;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -38,7 +39,7 @@ class CreateCreditInvitation implements ShouldQueue
|
||||
$contacts = $credit->client->contacts;
|
||||
|
||||
$contacts->each(function ($contact) use ($credit) {
|
||||
$invitation = InvoiceInvitation::whereCompanyId($credit->company_id)
|
||||
$invitation = CreditInvitation::whereCompanyId($credit->company_id)
|
||||
->whereClientContactId($contact->id)
|
||||
->whereCreditId($credit->id)
|
||||
->first();
|
||||
|
58
app/Listeners/Quote/CreateQuoteInvitation.php
Normal file
58
app/Listeners/Quote/CreateQuoteInvitation.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://creditninja.com)
|
||||
*
|
||||
* @link https://github.com/creditninja/creditninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://creditninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Listeners\Quote;
|
||||
|
||||
use App\Factory\CreditInvitationFactory;
|
||||
use App\Factory\InvoiceInvitationFactory;
|
||||
use App\Factory\QuoteInvitationFactory;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Spatie\Browsershot\Browsershot;
|
||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
||||
|
||||
class CreateQuoteInvitation implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
$quote = $event->credit;
|
||||
|
||||
$contacts = $quote->client->contacts;
|
||||
|
||||
$contacts->each(function ($contact) use ($quote) {
|
||||
$invitation = QuoteInvitation::whereCompanyId($quote->company_id)
|
||||
->whereClientContactId($contact->id)
|
||||
->whereQuoteId($quote->id)
|
||||
->first();
|
||||
|
||||
if (!$invitation && $contact->send_credit) {
|
||||
$ii = QuoteInvitationFactory::create($quote->company_id, $quote->user_id);
|
||||
$ii->quote_id = $quote->id;
|
||||
$ii->client_contact_id = $contact->id;
|
||||
$ii->save();
|
||||
} elseif ($invitation && !$contact->send_credit) {
|
||||
$invitation->delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -14,10 +14,11 @@ namespace App\Mail\Admin;
|
||||
use App\Models\User;
|
||||
use Illuminate\Mail\Mailable;
|
||||
|
||||
class EntitySent extends Mailable
|
||||
class EntityNotificationMailer extends Mailable
|
||||
{
|
||||
|
||||
public $mail_obj;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
96
app/Mail/Admin/EntityPaidObject.php
Normal file
96
app/Mail/Admin/EntityPaidObject.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Mail\Admin;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Utils\Number;
|
||||
|
||||
class EntityPaidObject
|
||||
{
|
||||
public $invitation;
|
||||
|
||||
public $entity;
|
||||
|
||||
public $contact;
|
||||
|
||||
public $company;
|
||||
|
||||
public $settings;
|
||||
|
||||
public function __construct($payment)
|
||||
{
|
||||
$this->payment = $payment;
|
||||
$this->company = $payment->company;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
$mail_obj = new \stdClass;
|
||||
$mail_obj->amount = $this->getAmount();
|
||||
$mail_obj->subject = $this->getSubject();
|
||||
$mail_obj->data = $this->getData();
|
||||
$mail_obj->markdown = 'email.admin.generic';
|
||||
$mail_obj->tag = $this->company->company_key;
|
||||
|
||||
return $mail_obj;
|
||||
}
|
||||
|
||||
private function getAmount()
|
||||
{
|
||||
return Number::formatMoney($this->payment->amount, $this->payment->client);
|
||||
}
|
||||
|
||||
private function getSubject()
|
||||
{
|
||||
return
|
||||
ctrans(
|
||||
'texts.notification_payment_paid_subject',
|
||||
['client' => $this->payment->client->present()->name()]
|
||||
);
|
||||
}
|
||||
|
||||
private function getData()
|
||||
{
|
||||
|
||||
$settings = $this->payment->client->getMergedSettings();
|
||||
|
||||
$amount = Number::formatMoney($this->payment->amount, $this->payment->client);
|
||||
|
||||
$invoice_texts = ctrans('texts.invoice_number_short');
|
||||
|
||||
foreach ($this->payment->invoices as $invoice) {
|
||||
$invoice_texts .= $invoice->number . ',';
|
||||
}
|
||||
|
||||
$invoice_texts = substr($invoice_texts, 0, -1);
|
||||
|
||||
$data = [
|
||||
'title' => ctrans(
|
||||
'texts.notification_payment_paid_subject',
|
||||
['client' => $this->payment->client->present()->name()]
|
||||
),
|
||||
'message' => ctrans(
|
||||
'texts.notification_payment_paid',
|
||||
['amount' => $amount,
|
||||
'client' => $this->payment->client->present()->name(),
|
||||
'invoice' => $invoice_texts,
|
||||
]
|
||||
),
|
||||
'url' => config('ninja.app_url') . '/payments/' . $this->payment->hashed_id,
|
||||
'button' => ctrans('texts.view_payment'),
|
||||
'signature' => $settings->email_signature,
|
||||
'logo' => $this->company->present()->logo(),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -77,7 +77,6 @@ class EntitySentObject
|
||||
"texts.notification_{$this->entity_type}_sent",
|
||||
[
|
||||
'amount' => $this->getAmount(),
|
||||
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->entity->number,
|
||||
]
|
||||
|
92
app/Mail/Admin/EntityViewedObject.php
Normal file
92
app/Mail/Admin/EntityViewedObject.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Mail\Admin;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Utils\Number;
|
||||
|
||||
class EntityViewedObject
|
||||
{
|
||||
public $invitation;
|
||||
|
||||
public $entity_type;
|
||||
|
||||
public $entity;
|
||||
|
||||
public $contact;
|
||||
|
||||
public $company;
|
||||
|
||||
public $settings;
|
||||
|
||||
public function __construct($invitation, $entity_type)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->entity_type = $entity_type;
|
||||
$this->entity = $invitation->{$entity_type};
|
||||
$this->contact = $invitation->contact;
|
||||
$this->company = $invitation->company;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
$mail_obj = new \stdClass;
|
||||
$mail_obj->amount = $this->getAmount();
|
||||
$mail_obj->subject = $this->getSubject();
|
||||
$mail_obj->data = $this->getData();
|
||||
$mail_obj->markdown = 'email.admin.generic';
|
||||
$mail_obj->tag = $this->company->company_key;
|
||||
|
||||
return $mail_obj;
|
||||
}
|
||||
|
||||
private function getAmount()
|
||||
{
|
||||
return Number::formatMoney($this->entity->amount, $this->entity->client);
|
||||
}
|
||||
|
||||
private function getSubject()
|
||||
{
|
||||
return
|
||||
ctrans(
|
||||
"texts.notification_{$this->entity_type}_viewed_subject",
|
||||
[
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->entity->number,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function getData()
|
||||
{
|
||||
|
||||
$settings = $this->entity->client->getMergedSettings();
|
||||
|
||||
$data = [
|
||||
'title' => $this->getSubject(),
|
||||
'message' => ctrans(
|
||||
"texts.notification_{$this->entity_type}_viewed",
|
||||
[
|
||||
'amount' => $this->getAmount(),
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->entity->number,
|
||||
]
|
||||
),
|
||||
'url' => $this->invitation->getAdminLink(),
|
||||
'button' => ctrans("texts.view_{$this->entity_type}"),
|
||||
'signature' => $settings->email_signature,
|
||||
'logo' => $this->company->present()->logo(),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -94,6 +94,11 @@ class Payment extends BaseModel
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function contact()
|
||||
{
|
||||
return $this->belongsTo(ClientContact::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
|
@ -21,28 +21,28 @@ class PaymentType extends StaticModel
|
||||
public $timestamps = false;
|
||||
|
||||
const CREDIT = 1;
|
||||
const ACH = 5;
|
||||
const VISA = 6;
|
||||
const MASTERCARD = 7;
|
||||
const AMERICAN_EXPRESS = 8;
|
||||
const DISCOVER = 9;
|
||||
const DINERS = 10;
|
||||
const EUROCARD = 11;
|
||||
const NOVA = 12;
|
||||
const CREDIT_CARD_OTHER = 13;
|
||||
const PAYPAL = 14;
|
||||
const CARTE_BLANCHE = 17;
|
||||
const UNIONPAY = 18;
|
||||
const JCB = 19;
|
||||
const LASER = 20;
|
||||
const MAESTRO = 21;
|
||||
const SOLO = 22;
|
||||
const SWITCH = 23;
|
||||
const ALIPAY = 28;
|
||||
const SOFORT = 29;
|
||||
const SEPA = 30;
|
||||
const GOCARDLESS = 31;
|
||||
const CRYPTO = 32;
|
||||
const ACH = 4;
|
||||
const VISA = 5;
|
||||
const MASTERCARD = 6;
|
||||
const AMERICAN_EXPRESS = 7;
|
||||
const DISCOVER = 8;
|
||||
const DINERS = 9;
|
||||
const EUROCARD = 10;
|
||||
const NOVA = 11;
|
||||
const CREDIT_CARD_OTHER = 12;
|
||||
const PAYPAL = 13;
|
||||
const CARTE_BLANCHE = 16;
|
||||
const UNIONPAY = 17;
|
||||
const JCB = 18;
|
||||
const LASER = 19;
|
||||
const MAESTRO = 20;
|
||||
const SOLO = 21;
|
||||
const SWITCH = 22;
|
||||
const ALIPAY = 27;
|
||||
const SOFORT = 28;
|
||||
const SEPA = 29;
|
||||
const GOCARDLESS = 30;
|
||||
const CRYPTO = 31;
|
||||
|
||||
public static function parseCardType($cardName)
|
||||
{
|
||||
|
@ -29,7 +29,11 @@ class MarkSent
|
||||
|
||||
event(new CreditWasMarkedSent($this->credit, $this->credit->company));
|
||||
|
||||
$this->credit->service()->setStatus(Credit::STATUS_SENT)->applyNumber()->save();
|
||||
$this->credit
|
||||
->service()
|
||||
->setStatus(Credit::STATUS_SENT)
|
||||
->applyNumber()
|
||||
->save();
|
||||
|
||||
return $this->credit;
|
||||
}
|
||||
|
@ -29,7 +29,11 @@ class MarkSent
|
||||
|
||||
event(new QuoteWasMarkedSent($this->quote, $this->quote->company));
|
||||
|
||||
$this->quote->service()->setStatus(Quote::STATUS_SENT)->applyNumber()->save();
|
||||
$this->quote
|
||||
->service()
|
||||
->setStatus(Quote::STATUS_SENT)
|
||||
->applyNumber()
|
||||
->save();
|
||||
|
||||
return $this->quote;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use Faker\Generator as Faker;
|
||||
$factory->define(App\Models\Credit::class, function (Faker $faker) {
|
||||
return [
|
||||
'status_id' => App\Models\Credit::STATUS_DRAFT,
|
||||
'number' => $faker->ean13(),
|
||||
'discount' => $faker->numberBetween(1, 10),
|
||||
'is_amount_discount' => (bool)random_int(0, 1),
|
||||
'tax_name1' => 'GST',
|
||||
|
@ -7,7 +7,6 @@ use Faker\Generator as Faker;
|
||||
$factory->define(App\Models\Quote::class, function (Faker $faker) {
|
||||
return [
|
||||
'status_id' => App\Models\Quote::STATUS_DRAFT,
|
||||
'number' => '',
|
||||
'discount' => $faker->numberBetween(1, 10),
|
||||
'is_amount_discount' => $faker->boolean(),
|
||||
'tax_name1' => 'GST',
|
||||
|
@ -16,7 +16,6 @@ class AddGoogleRefreshTokenToUsersTable extends Migration
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('oauth_user_refresh_token')->nullable();
|
||||
$table->text('oauth_user_token')->change();
|
||||
});
|
||||
|
||||
DB::statement("alter table users modify column oauth_user_token text");
|
||||
|
@ -21,10 +21,12 @@ use App\Models\GroupSetting;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\Quote;
|
||||
use App\Models\User;
|
||||
use App\Models\UserAccount;
|
||||
use App\Repositories\CreditRepository;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Repositories\QuoteRepository;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@ -210,7 +212,8 @@ class RandomDataSeeder extends Seeder
|
||||
|
||||
$credit->save();
|
||||
|
||||
event(new CreateCreditInvitation($credit));
|
||||
//event(new CreateCreditInvitation($credit));
|
||||
$credit->service()->createInvitations()->markSent()->save();
|
||||
|
||||
//$invoice->markSent()->save();
|
||||
});
|
||||
@ -220,6 +223,29 @@ class RandomDataSeeder extends Seeder
|
||||
|
||||
// factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]);
|
||||
|
||||
/*Credits*/
|
||||
factory(\App\Models\Quote::class, 20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
|
||||
|
||||
$quotes = Quote::cursor();
|
||||
$quote_repo = new QuoteRepository();
|
||||
|
||||
$quotes->each(function ($quote) use ($quote_repo, $user, $company, $client) {
|
||||
$quote_calc = null;
|
||||
|
||||
if ($quote->uses_inclusive_taxes) {
|
||||
$quote_calc = new InvoiceSumInclusive($quote);
|
||||
} else {
|
||||
$quote_calc = new InvoiceSum($quote);
|
||||
}
|
||||
|
||||
$quote = $quote_calc->build()->getQuote();
|
||||
|
||||
$quote->save();
|
||||
|
||||
//event(new CreateQuoteInvitation($quote));
|
||||
$quote->service()->createInvitations()->markSent()->save();
|
||||
//$invoice->markSent()->save();
|
||||
});
|
||||
|
||||
|
||||
$clients = Client::all();
|
||||
|
@ -257,8 +257,8 @@ return [
|
||||
'notification_quote_sent_subject' => 'Quote :invoice was sent to :client',
|
||||
'notification_credit_sent_subject' => 'Credit :invoice was sent to :client',
|
||||
'notification_invoice_viewed_subject' => 'Invoice :invoice was viewed by :client',
|
||||
'notification_credit_viewed_subject' => 'Credit :credit was viewed by :client',
|
||||
'notification_quote_viewed_subject' => 'Quote :quote was viewed by :client',
|
||||
'notification_credit_viewed_subject' => 'Credit :invoice was viewed by :client',
|
||||
'notification_quote_viewed_subject' => 'Quote :invoice was viewed by :client',
|
||||
'notification_invoice_paid' => 'A payment of :amount was made by client :client towards Invoice :invoice.',
|
||||
'notification_invoice_sent' => 'The following client :client was emailed Invoice :invoice for :amount.',
|
||||
'notification_quote_sent' => 'The following client :client was emailed Quote :invoice for :amount.',
|
||||
|
@ -42,6 +42,12 @@ class PreviewTest extends TestCase
|
||||
$this->faker = \Faker\Factory::create();
|
||||
|
||||
Model::reguard();
|
||||
|
||||
|
||||
if (config('ninja.testvars.travis') !== false) {
|
||||
$this->markTestSkipped('Skip test for CI Testing');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,10 +13,11 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
|
||||
/**
|
||||
* @test
|
||||
@ -26,6 +27,7 @@ class ProductTest extends TestCase
|
||||
{
|
||||
use MakesHash;
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
@ -40,42 +42,18 @@ class ProductTest extends TestCase
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class
|
||||
);
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
}
|
||||
|
||||
public function testProductList()
|
||||
{
|
||||
|
||||
Account::all()->each(function($account) {
|
||||
$account->delete();
|
||||
});
|
||||
|
||||
|
||||
$data = [
|
||||
'first_name' => $this->faker->firstName,
|
||||
'last_name' => $this->faker->lastName,
|
||||
'name' => $this->faker->company,
|
||||
'email' => $this->faker->unique()->safeEmail,
|
||||
'password' => 'ALongAndBrilliantPassword123',
|
||||
'_token' => csrf_token(),
|
||||
'privacy_policy' => 1,
|
||||
'terms_of_service' => 1
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
])->post('/api/v1/signup?include=account', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$acc = $response->json();
|
||||
|
||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
||||
|
||||
$token = $account->default_company->tokens->first()->token;
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/products');
|
||||
|
||||
$response->assertStatus(200);
|
||||
@ -83,7 +61,7 @@ class ProductTest extends TestCase
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post(
|
||||
'/api/v1/products/',
|
||||
[
|
||||
@ -112,14 +90,14 @@ class ProductTest extends TestCase
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/products/'.$this->encodePrimaryKey($product->id), $product_update)
|
||||
->assertStatus(200);
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->delete('/api/v1/products/'.$this->encodePrimaryKey($product->id))
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@ -26,6 +27,7 @@ class RecurringInvoiceTest extends TestCase
|
||||
{
|
||||
use MakesHash;
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
@ -40,64 +42,38 @@ class RecurringInvoiceTest extends TestCase
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class
|
||||
);
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
}
|
||||
|
||||
public function testRecurringInvoiceList()
|
||||
{
|
||||
$data = [
|
||||
'first_name' => $this->faker->firstName,
|
||||
'last_name' => $this->faker->lastName,
|
||||
'name' => $this->faker->company,
|
||||
'email' => $this->faker->unique()->safeEmail,
|
||||
'password' => 'ALongAndBrilliantPassword123',
|
||||
'_token' => csrf_token(),
|
||||
'privacy_policy' => 1,
|
||||
'terms_of_service' => 1
|
||||
];
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
])->post('/api/v1/signup?include=account', $data);
|
||||
|
||||
$acc = $response->json();
|
||||
|
||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
||||
|
||||
$company_token = $account->default_company->tokens()->first();
|
||||
$token = $company_token->token;
|
||||
$company = $company_token->company;
|
||||
|
||||
$user = $company_token->user;
|
||||
|
||||
$this->assertNotNull($company_token);
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
//$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company) {
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $company->id,
|
||||
'company_id' => $this->company->id,
|
||||
'is_primary' => 1
|
||||
]);
|
||||
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $company->id
|
||||
'company_id' => $this->company->id
|
||||
]);
|
||||
});
|
||||
|
||||
$client = Client::all()->first();
|
||||
|
||||
factory(\App\Models\RecurringInvoice::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
|
||||
factory(\App\Models\RecurringInvoice::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/recurring_invoices');
|
||||
|
||||
$response->assertStatus(200);
|
||||
@ -105,69 +81,39 @@ class RecurringInvoiceTest extends TestCase
|
||||
|
||||
public function testRecurringInvoiceRESTEndPoints()
|
||||
{
|
||||
$data = [
|
||||
'first_name' => $this->faker->firstName,
|
||||
'last_name' => $this->faker->lastName,
|
||||
'name' => $this->faker->company,
|
||||
'email' => $this->faker->unique()->safeEmail,
|
||||
'password' => 'ALongAndBrilliantPassword123',
|
||||
'_token' => csrf_token(),
|
||||
'privacy_policy' => 1,
|
||||
'terms_of_service' => 1
|
||||
];
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
])->post('/api/v1/signup?include=account', $data);
|
||||
|
||||
$acc = $response->json();
|
||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
||||
|
||||
$company_token = $account->default_company->tokens()->first();
|
||||
$token = $company_token->token;
|
||||
$company = $company_token->company;
|
||||
|
||||
$user = $company_token->user;
|
||||
|
||||
$this->assertNotNull($company_token);
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
//$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company) {
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $company->id,
|
||||
'company_id' => $this->company->id,
|
||||
'is_primary' => 1
|
||||
]);
|
||||
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $company->id
|
||||
'company_id' => $this->company->id
|
||||
]);
|
||||
});
|
||||
$client = Client::all()->first();
|
||||
|
||||
factory(\App\Models\RecurringInvoice::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
|
||||
factory(\App\Models\RecurringInvoice::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
||||
|
||||
$RecurringInvoice = RecurringInvoice::where('user_id', $user->id)->first();
|
||||
$RecurringInvoice = RecurringInvoice::where('user_id', $this->user->id)->first();
|
||||
$RecurringInvoice->save();
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id));
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id).'/edit');
|
||||
|
||||
$response->assertStatus(200);
|
||||
@ -181,13 +127,13 @@ class RecurringInvoiceTest extends TestCase
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id), $RecurringInvoice_update)
|
||||
->assertStatus(200);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->delete('/api/v1/recurring_invoices/'.$this->encodePrimaryKey($RecurringInvoice->id));
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
@ -15,6 +15,7 @@ use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@ -26,6 +27,7 @@ class RecurringQuoteTest extends TestCase
|
||||
{
|
||||
use MakesHash;
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
@ -40,64 +42,20 @@ class RecurringQuoteTest extends TestCase
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class
|
||||
);
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
}
|
||||
|
||||
public function testRecurringQuoteList()
|
||||
{
|
||||
$data = [
|
||||
'first_name' => $this->faker->firstName,
|
||||
'last_name' => $this->faker->lastName,
|
||||
'name' => $this->faker->company,
|
||||
'email' => $this->faker->unique()->safeEmail,
|
||||
'password' => 'ALongAndBrilliantPassword123',
|
||||
'_token' => csrf_token(),
|
||||
'privacy_policy' => 1,
|
||||
'terms_of_service' => 1
|
||||
];
|
||||
|
||||
factory(\App\Models\RecurringQuote::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
])->post('/api/v1/signup?include=account', $data);
|
||||
|
||||
$acc = $response->json();
|
||||
|
||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
||||
|
||||
$company_token = $account->default_company->tokens()->first();
|
||||
$token = $company_token->token;
|
||||
$company = $company_token->company;
|
||||
|
||||
$user = $company_token->user;
|
||||
|
||||
$this->assertNotNull($company_token);
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
//$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company) {
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $company->id,
|
||||
'is_primary' => 1
|
||||
]);
|
||||
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $company->id
|
||||
]);
|
||||
});
|
||||
$client = Client::all()->first();
|
||||
|
||||
factory(\App\Models\RecurringQuote::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/recurring_quotes');
|
||||
|
||||
$response->assertStatus(200);
|
||||
@ -105,70 +63,24 @@ class RecurringQuoteTest extends TestCase
|
||||
|
||||
public function testRecurringQuoteRESTEndPoints()
|
||||
{
|
||||
$data = [
|
||||
'first_name' => $this->faker->firstName,
|
||||
'last_name' => $this->faker->lastName,
|
||||
'name' => $this->faker->company,
|
||||
'email' => $this->faker->unique()->safeEmail,
|
||||
'password' => 'ALongAndBrilliantPassword123',
|
||||
'_token' => csrf_token(),
|
||||
'privacy_policy' => 1,
|
||||
'terms_of_service' => 1
|
||||
];
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
])->post('/api/v1/signup?include=account', $data);
|
||||
factory(\App\Models\RecurringQuote::class, 1)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
||||
|
||||
$acc = $response->json();
|
||||
|
||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
||||
|
||||
$company_token = $account->default_company->tokens()->first();
|
||||
$token = $company_token->token;
|
||||
$company = $company_token->company;
|
||||
|
||||
$user = $company_token->user;
|
||||
|
||||
$this->assertNotNull($company_token);
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
//$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company) {
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $company->id,
|
||||
'is_primary' => 1
|
||||
]);
|
||||
|
||||
factory(\App\Models\ClientContact::class, 1)->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $c->id,
|
||||
'company_id' => $company->id
|
||||
]);
|
||||
});
|
||||
$client = Client::all()->first();
|
||||
|
||||
factory(\App\Models\RecurringQuote::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
|
||||
|
||||
$RecurringQuote = RecurringQuote::where('user_id', $user->id)->first();
|
||||
$RecurringQuote = RecurringQuote::where('user_id', $this->user->id)->first();
|
||||
$RecurringQuote->save();
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/recurring_quotes/'.$this->encodePrimaryKey($RecurringQuote->id));
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/recurring_quotes/'.$this->encodePrimaryKey($RecurringQuote->id).'/edit');
|
||||
|
||||
$response->assertStatus(200);
|
||||
@ -183,13 +95,13 @@ class RecurringQuoteTest extends TestCase
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/recurring_quotes/'.$this->encodePrimaryKey($RecurringQuote->id), $RecurringQuote_update)
|
||||
->assertStatus(200);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->delete('/api/v1/recurring_quotes/'.$this->encodePrimaryKey($RecurringQuote->id));
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
Loading…
x
Reference in New Issue
Block a user