Skip to content

Commit 9629178

Browse files
authored
Disable the routes by default (#336)
* Disable the routes by default * Write the required tests * Fix the style of codes * Fix the style of codes * Remove extra space
1 parent 609a8a1 commit 9629178

File tree

7 files changed

+73
-1
lines changed

7 files changed

+73
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Create a Chat application for your multiple Models
2020
- [Installation](#installation)
2121
- [Usage](#usage)
2222
- [Adding the ability to participate to a Model](#Adding-the-ability-to-participate-to-a-Model)
23+
- [Enable the routes](#enable-the-routes)
2324
- [Get participant details](#get-participant-details)
2425
- [Creating a conversation](#creating-a-conversation)
2526
- [Get a conversation by Id](#get-a-conversation-by-id)
@@ -101,6 +102,10 @@ class Bot extends Model
101102
}
102103
```
103104

105+
#### Enable the routes
106+
107+
The package includes routes for conversations, conversation participants, and messaging. These routes are hidden by default. To enable them, change `should_load_routes` to `true`, but make sure to configure the middleware correctly.
108+
104109
#### Get participant details
105110

106111
Since we allow Models with data that differ in structure to chat, we may want a uniform way to

config/musonza_chat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/*
2727
* Whether to load the package routes file in your application.
2828
*/
29-
'should_load_routes' => true,
29+
'should_load_routes' => false,
3030

3131
/*
3232
* Routes configuration

tests/Feature/ConversationControllerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313

1414
class ConversationControllerTest extends TestCase
1515
{
16+
public function setUp()
17+
{
18+
parent::setUp();
19+
20+
$this->app['config']->set('musonza_chat.should_load_routes', true);
21+
}
22+
1623
public function testStore()
1724
{
1825
$this->withoutExceptionHandling();

tests/Feature/ConversationMessageControllerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111

1212
class ConversationMessageControllerTest extends TestCase
1313
{
14+
public function setUp()
15+
{
16+
parent::setUp();
17+
18+
$this->app['config']->set('musonza_chat.should_load_routes', true);
19+
}
20+
1421
public function testStore()
1522
{
1623
$conversation = factory(Conversation::class)->create();

tests/Feature/ConversationParticipationControllerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111

1212
class ConversationParticipationControllerTest extends TestCase
1313
{
14+
public function setUp()
15+
{
16+
parent::setUp();
17+
18+
$this->app['config']->set('musonza_chat.should_load_routes', true);
19+
}
20+
1421
public function testStore()
1522
{
1623
$conversation = factory(Conversation::class)->create();

tests/Feature/DataTransformersTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
class DataTransformersTest extends TestCase
1010
{
11+
public function setUp()
12+
{
13+
parent::setUp();
14+
15+
$this->app['config']->set('musonza_chat.should_load_routes', true);
16+
}
17+
1118
public function testConversationWithoutTransformer()
1219
{
1320
$conversation = factory(Conversation::class)->create();

tests/Unit/RouteTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Musonza\Chat\Tests;
4+
5+
use Illuminate\Support\Facades\Route;
6+
7+
class RouteTest extends TestCase
8+
{
9+
protected function setUp(): void
10+
{
11+
parent::setUp();
12+
13+
// Disable route caching and refresh routes
14+
Route::flushMiddlewareGroups();
15+
Route::clearResolvedInstances();
16+
}
17+
18+
/** @test */
19+
public function it_can_disable_routes()
20+
{
21+
// Disable route loading
22+
$this->app['config']->set('musonza_chat.should_load_routes', false);
23+
$this->refreshApplication();
24+
25+
$response = $this->get('/conversations');
26+
$response->assertStatus(404);
27+
}
28+
29+
/** @test */
30+
public function it_can_enable_routes()
31+
{
32+
// Enable route loading
33+
$this->app['config']->set('musonza_chat.should_load_routes', true);
34+
$this->refreshApplication();
35+
36+
$response = $this->get('/conversations');
37+
$response->assertStatus(200);
38+
}
39+
}

0 commit comments

Comments
 (0)