Skip to content

Commit

Permalink
ok the clone is there to help speed this up
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed May 30, 2023
1 parent 6163382 commit cf77f02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
11 changes: 5 additions & 6 deletions app/Http/Controllers/CloneResponseTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace App\Http\Controllers;

use App\Models\Outbound;
use Illuminate\Http\Request;

class CloneResponseTypesController extends Controller
{

public function __invoke() {
public function __invoke()
{
request()->validate([
'from' => ['required'],
'to' => ['required'],
Expand All @@ -17,17 +16,17 @@ public function __invoke() {
$to = Outbound::findOrFail(request()->get('to'));
$from = Outbound::findOrFail(request()->get('from'));

foreach($from->response_types as $responseType) {
foreach ($from->response_types as $responseType) {
$new = $responseType->replicate();
$new->outbound_id = $to->id;
$new->save();
}

request()->session()->flash('flash.banner', 'Cloned 👯‍');

return to_route("outbounds." . $to->type->value .".show", [
return to_route('outbounds.'.$to->type->value.'.show', [
'outbound' => $to->id,
'project' => $to->project_id
'project' => $to->project_id,
]);
}
}
8 changes: 3 additions & 5 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ function () {
'auth:sanctum',
config('jetstream.auth_session'),
'verified',
])->group(function() {
Route::get("/projects/{project}/outbounds", function(Project $project) {
])->group(function () {
Route::get('/projects/{project}/outbounds', function (Project $project) {
return response($project->outbounds);
})->name("projects.outbounds");
})->name('projects.outbounds');
});

Route::middleware([
Expand Down Expand Up @@ -380,7 +380,6 @@ function () {
}
);


Route::post('/outbounds/clone', CloneResponseTypesController::class)
->name('outbounds.clone.response_types')
->middleware([
Expand All @@ -389,7 +388,6 @@ function () {
'verified',
]);


Route::middleware([
'auth:sanctum',
config('jetstream.auth_session'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@
use App\Models\Outbound;
use App\Models\ResponseType;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class CloneResponseTypesControllerTest extends TestCase
{

public function test_clone() {
public function test_clone()
{
$from = Outbound::factory()->chatUi()->create();
ResponseType::factory()->count(2)->create([
'outbound_id' => $from->id
'outbound_id' => $from->id,
]);

$to = Outbound::factory()->api()->create();

$user = User::factory()->create();
$this->actingAs($user)
->post(route("outbounds.clone.response_types"), [
->post(route('outbounds.clone.response_types'), [
'from' => $from->id,
'to' => $to->id
])->assertRedirectToRoute("outbounds.api.show", [
'to' => $to->id,
])->assertRedirectToRoute('outbounds.api.show', [
'outbound' => $to->id,
'project' => $to->project_id,
]);
Expand Down

0 comments on commit cf77f02

Please sign in to comment.