Skip to content

Commit 9ccdf46

Browse files
committed
Staring with ticket rating
1 parent dccf3bf commit 9ccdf46

File tree

13 files changed

+117
-0
lines changed

13 files changed

+117
-0
lines changed

app/Http/Controllers/RequesterTicketsController.php

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace App\Http\Controllers;
44

55
use App\Ticket;
6+
use Illuminate\Http\Response;
7+
use Illuminate\Support\Facades\Validator;
68

79
class RequesterTicketsController extends Controller
810
{
@@ -12,4 +14,14 @@ public function show($public_token)
1214

1315
return view('requester.tickets.show', ['ticket' => $ticket]);
1416
}
17+
18+
public function rate($public_token)
19+
{
20+
$ticket = Ticket::findWithPublicToken($public_token);
21+
$rated = $ticket->rate(request('rating'));
22+
if (! $rated){
23+
app()->abort(Response::HTTP_UNPROCESSABLE_ENTITY, 'Could not rate this ticket');
24+
}
25+
return view('requester.tickets.rated', ['ticket' => $ticket]);
26+
}
1527
}

app/Ticket.php

+8
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ public function updatePriority($priority)
212212
TicketEvent::make($this, 'Priority updated: '.$this->priorityName());
213213
}
214214

215+
public function rate($rating)
216+
{
217+
if (! $rating) return false;
218+
if ($rating < 0 || $rating > 5) return false;
219+
if ($this->status != Ticket::STATUS_CLOSED) return false;
220+
return $this->update(['rating' => $rating]);
221+
}
222+
215223
public function setLevel($level)
216224
{
217225
$this->update(['level' => $level]);

database/factories/TicketFactory.php

+6
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313
'public_token' => str_random(24),
1414
];
1515
});
16+
17+
$factory->state(Ticket::class, 'closed', function ($faker) {
18+
return [
19+
'status' => Ticket::STATUS_CLOSED,
20+
];
21+
});

resources/lang/ca/ticket.php

+1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@
5151
'normal' => 'Normal',
5252
'high' => 'Alta',
5353
'blocker' => 'Bloquejant',
54+
'thanksForTheRating' => 'Moltes gràcies!'
5455
];

resources/lang/de/ticket.php

+1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@
4747
'normal' => 'Normal*',
4848
'high' => 'Hoch*',
4949
'blocker' => 'Blocker*',
50+
'thanksForTheRating' => 'Moltes gràcies!*'
5051
];

resources/lang/en/ticket.php

+1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@
5151
'normal' => 'Normal',
5252
'high' => 'High',
5353
'blocker' => 'Blocker',
54+
'thanksForTheRating' => 'Thank you!'
5455
];

resources/lang/es/ticket.php

+1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@
5151
'normal' => 'Normal',
5252
'high' => 'Alta',
5353
'blocker' => 'Bloqueador',
54+
'thanksForTheRating' => '¡Muchas gracias!'
5455
];

resources/lang/fr/ticket.php

+1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@
5151
'normal' => 'Normal*',
5252
'high' => 'High*',
5353
'blocker' => 'Blocker*',
54+
'thanksForTheRating' => 'Thank you!*'
5455
];

resources/lang/nl/ticket.php

+1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@
5151
'normal' => 'Normal*',
5252
'high' => 'High*',
5353
'blocker' => 'Blocker*',
54+
'thanksForTheRating' => 'Thank you!*'
5455
];

resources/lang/ptbr/ticket.php

+1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@
4949
'normal' => 'Normal*',
5050
'high' => 'High*',
5151
'blocker' => 'Blocker*',
52+
'thanksForTheRating' => 'Moltes gràcies*'
5253
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@extends('layouts.requester')
2+
@section('content')
3+
<div class="center text-center mt4">
4+
{{ __('ticket.thanksForTheRating') }}
5+
</div>
6+
@endsection

routes/web.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Route::group(['prefix' => 'requester'], function () {
1919
Route::get('tickets/{token}', 'RequesterTicketsController@show')->name('requester.tickets.show');
2020
Route::post('tickets/{token}/comments', 'RequesterCommentsController@store')->name('requester.comments.store');
21+
Route::get('tickets/{token}/rate', 'RequesterTicketsController@rate')->name('requester.tickets.rate');
2122
});
2223

2324
Route::post('webhook/bitbucket', 'WebhookController@store');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use App\Idea;
6+
use App\Ticket;
7+
use App\User;
8+
use Illuminate\Http\Response;
9+
use Illuminate\Support\Facades\Notification;
10+
use Tests\TestCase;
11+
use Illuminate\Foundation\Testing\RefreshDatabase;
12+
13+
class TicketRatingTest extends TestCase
14+
{
15+
use RefreshDatabase;
16+
17+
/** @test */
18+
public function can_rate_a_ticket_when_close()
19+
{
20+
$ticket = factory(Ticket::class)->states(['closed'])->create(["public_token" => "TOKEN"]);
21+
$response = $this->get("requester/tickets/TOKEN/rate?rating=3");
22+
23+
$response->assertStatus(Response::HTTP_OK);
24+
$this->assertEquals(3, $ticket->fresh()->rating);
25+
}
26+
27+
/** @test */
28+
public function can_not_rate_a_ticket_without_a_rating()
29+
{
30+
$ticket = factory(Ticket::class)->states(['closed'])->create(["public_token" => "TOKEN"]);
31+
$response = $this->get("requester/tickets/TOKEN/rate");
32+
33+
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
34+
$this->assertNull($ticket->fresh()->rating);
35+
}
36+
37+
/** @test */
38+
public function can_not_rate_a_ticket_when_not_closed()
39+
{
40+
$ticket = factory(Ticket::class)->create(["status" => Ticket::STATUS_OPEN, "public_token" => "TOKEN"]);
41+
$response = $this->get("requester/tickets/TOKEN/rate?rating=2");
42+
43+
$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
44+
$this->assertNull($ticket->fresh()->rating);
45+
}
46+
47+
public function can_not_rate_a_ticket_when_already_rated(){
48+
49+
}
50+
51+
52+
53+
/** @test */
54+
public function the_rating_email_is_sent_when_order_closed_and_not_rated()
55+
{
56+
}
57+
58+
public function the_rating_email_is_not_sent_when_order_closed_not_rated(){
59+
60+
}
61+
62+
/** @test */
63+
public function the_idea_created_text_uses_the_ticket_language()
64+
{
65+
Notification::fake();
66+
$user = factory(User::class)->create();
67+
$ticket = factory(Ticket::class)->create([
68+
"status" => Ticket::STATUS_OPEN,
69+
"body" => "Aquest es un comentari en català per veure que el detector d'idioma funciona"
70+
]);
71+
72+
$response = $this->actingAs($user)->post("tickets/{$ticket->id}/idea");
73+
74+
$response->assertStatus( Response::HTTP_FOUND );
75+
$this->assertContains("Notificació | Banc d'Idees REVO", $ticket->fresh()->commentsAndNotes->first()->body);
76+
}
77+
}

0 commit comments

Comments
 (0)