mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 16:44:36 -04:00
Tests for events
This commit is contained in:
parent
6eb9f0f6a6
commit
5c13e1681b
@ -12,6 +12,7 @@
|
|||||||
namespace App\Events\Quote;
|
namespace App\Events\Quote;
|
||||||
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\Quote;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class QuoteWasArchived
|
class QuoteWasArchived
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Events\Quote;
|
namespace App\Events\Quote;
|
||||||
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\Quote;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Events\Quote;
|
namespace App\Events\Quote;
|
||||||
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\Quote;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Events\Quote;
|
namespace App\Events\Quote;
|
||||||
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\Quote;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Events\Quote\QuoteWasCreated;
|
||||||
|
use App\Events\Quote\QuoteWasUpdated;
|
||||||
use App\Factory\CloneInvoiceFactory;
|
use App\Factory\CloneInvoiceFactory;
|
||||||
use App\Factory\CloneInvoiceToQuoteFactory;
|
use App\Factory\CloneInvoiceToQuoteFactory;
|
||||||
use App\Factory\CloneQuoteFactory;
|
use App\Factory\CloneQuoteFactory;
|
||||||
@ -31,6 +33,7 @@ use App\Models\Quote;
|
|||||||
use App\Repositories\QuoteRepository;
|
use App\Repositories\QuoteRepository;
|
||||||
use App\Transformers\InvoiceTransformer;
|
use App\Transformers\InvoiceTransformer;
|
||||||
use App\Transformers\QuoteTransformer;
|
use App\Transformers\QuoteTransformer;
|
||||||
|
use App\Utils\Ninja;
|
||||||
use App\Utils\TempFile;
|
use App\Utils\TempFile;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@ -204,6 +207,8 @@ class QuoteController extends BaseController
|
|||||||
|
|
||||||
$quote = $this->quote_repo->save($request->all(), QuoteFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
$quote = $this->quote_repo->save($request->all(), QuoteFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||||
|
|
||||||
|
event(new QuoteWasCreated($quote, $quote->company, Ninja::eventVars()));
|
||||||
|
|
||||||
return $this->itemResponse($quote);
|
return $this->itemResponse($quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,6 +383,8 @@ class QuoteController extends BaseController
|
|||||||
|
|
||||||
$quote = $this->quote_repo->save($request->all(), $quote);
|
$quote = $this->quote_repo->save($request->all(), $quote);
|
||||||
|
|
||||||
|
event(new QuoteWasUpdated($quote, $quote->company, Ninja::eventVars()));
|
||||||
|
|
||||||
return $this->itemResponse($quote);
|
return $this->itemResponse($quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -658,15 +665,26 @@ class QuoteController extends BaseController
|
|||||||
}, basename($quote->pdf_file_path()));
|
}, basename($quote->pdf_file_path()));
|
||||||
//return response()->download(TempFile::path($quote->pdf_file_path()), basename($quote->pdf_file_path()));
|
//return response()->download(TempFile::path($quote->pdf_file_path()), basename($quote->pdf_file_path()));
|
||||||
break;
|
break;
|
||||||
|
case 'restore':
|
||||||
|
$this->quote_repo->restore($quote);
|
||||||
|
|
||||||
|
if (!$bulk)
|
||||||
|
return $this->listResponse($quote);
|
||||||
|
|
||||||
|
break;
|
||||||
case 'archive':
|
case 'archive':
|
||||||
$this->quote_repo->archive($quote);
|
$this->quote_repo->archive($quote);
|
||||||
|
|
||||||
return $this->listResponse($quote);
|
if (!$bulk)
|
||||||
|
return $this->listResponse($quote);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'delete':
|
case 'delete':
|
||||||
$this->quote_repo->delete($quote);
|
$this->quote_repo->delete($quote);
|
||||||
|
|
||||||
return $this->listResponse($quote);
|
if (!$bulk)
|
||||||
|
return $this->listResponse($quote);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'email':
|
case 'email':
|
||||||
$quote->service()->sendEmail();
|
$quote->service()->sendEmail();
|
||||||
@ -679,6 +697,7 @@ class QuoteController extends BaseController
|
|||||||
if (! $bulk) {
|
if (! $bulk) {
|
||||||
return $this->itemResponse($quote);
|
return $this->itemResponse($quote);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
// no break
|
// no break
|
||||||
default:
|
default:
|
||||||
return response()->json(['message' => "The requested action `{$action}` is not available."], 400);
|
return response()->json(['message' => "The requested action `{$action}` is not available."], 400);
|
||||||
|
@ -27,6 +27,11 @@ use App\Events\Payment\PaymentWasCreated;
|
|||||||
use App\Events\Payment\PaymentWasDeleted;
|
use App\Events\Payment\PaymentWasDeleted;
|
||||||
use App\Events\Payment\PaymentWasRestored;
|
use App\Events\Payment\PaymentWasRestored;
|
||||||
use App\Events\Payment\PaymentWasUpdated;
|
use App\Events\Payment\PaymentWasUpdated;
|
||||||
|
use App\Events\Quote\QuoteWasArchived;
|
||||||
|
use App\Events\Quote\QuoteWasCreated;
|
||||||
|
use App\Events\Quote\QuoteWasDeleted;
|
||||||
|
use App\Events\Quote\QuoteWasRestored;
|
||||||
|
use App\Events\Quote\QuoteWasUpdated;
|
||||||
use App\Models\Credit;
|
use App\Models\Credit;
|
||||||
use App\Models\Design;
|
use App\Models\Design;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
@ -59,6 +64,69 @@ class EventTest extends TestCase
|
|||||||
$this->makeTestData();
|
$this->makeTestData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testQuoteEvents()
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Test fire new invoice */
|
||||||
|
$data = [
|
||||||
|
'client_id' => $this->client->hashed_id,
|
||||||
|
'number' => 'dude',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->expectsEvents([
|
||||||
|
QuoteWasCreated::class,
|
||||||
|
QuoteWasUpdated::class,
|
||||||
|
QuoteWasArchived::class,
|
||||||
|
QuoteWasRestored::class,
|
||||||
|
QuoteWasDeleted::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/quotes/', $data)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'client_id' => $this->client->hashed_id,
|
||||||
|
'number' => 'dude2',
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->put('/api/v1/quotes/' . $arr['data']['id'], $data)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'ids' => [$arr['data']['id']],
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/quotes/bulk?action=archive', $data)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/quotes/bulk?action=restore', $data)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/quotes/bulk?action=delete', $data)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//@TODO paymentwasvoided
|
//@TODO paymentwasvoided
|
||||||
//@TODO paymentwasrefunded
|
//@TODO paymentwasrefunded
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user