diff --git a/app/Http/Controllers/Common/Notifications.php b/app/Http/Controllers/Common/Notifications.php index de8b44e17..b283dba9e 100644 --- a/app/Http/Controllers/Common/Notifications.php +++ b/app/Http/Controllers/Common/Notifications.php @@ -68,19 +68,24 @@ class Notifications extends Controller $notifications = $this->getNotifications($path); - foreach ($notifications as $notification) { - if ($notification->id == $id) { - setting()->set('notifications.'. $path . '.' . $id . '.name', $notification->name); - setting()->set('notifications.'. $path . '.' . $id . '.message', $notification->message); - setting()->set('notifications.'. $path . '.' . $id . '.date', Date::now()); - setting()->set('notifications.'. $path . '.' . $id . '.status', '0'); + if ($notifications) { + foreach ($notifications as $notification) { + if ($notification->id == $id) { + setting()->set('notifications.'. $path . '.' . $id . '.name', $notification->name); + setting()->set('notifications.'. $path . '.' . $id . '.message', $notification->message); + setting()->set('notifications.'. $path . '.' . $id . '.date', Date::now()); + setting()->set('notifications.'. $path . '.' . $id . '.status', '0'); - setting()->save(); - break; + setting()->save(); + break; + } } } return response()->json([ + 'message' => trans('messages.success.disabled', [ + 'type' => Str::lower(trans_choice('general.notifications', 2)) + ]), 'success' => true, 'error' => false, 'data' => null, diff --git a/tests/Feature/Common/DashboardsTest.php b/tests/Feature/Common/DashboardsTest.php index d75b4141e..6d19bbcd9 100644 --- a/tests/Feature/Common/DashboardsTest.php +++ b/tests/Feature/Common/DashboardsTest.php @@ -17,150 +17,150 @@ class DashboardsTest extends FeatureTestCase ->assertSeeText(trans_choice('general.dashboards', 1)); } - public function testItShouldSeeDashboardListPage() - { - $this->loginAs() - ->get(route('dashboards.index')) - ->assertOk() - ->assertSeeText(trans_choice('general.dashboards', 2)); - } + public function testItShouldSeeDashboardListPage() + { + $this->loginAs() + ->get(route('dashboards.index')) + ->assertOk() + ->assertSeeText(trans_choice('general.dashboards', 2)); + } - public function testItShouldSeeDashboardCreatePage() - { - $this->loginAs() - ->get(route('dashboards.create')) - ->assertOk() - ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.dashboards', 1)])); - } + public function testItShouldSeeDashboardCreatePage() + { + $this->loginAs() + ->get(route('dashboards.create')) + ->assertOk() + ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.dashboards', 1)])); + } - public function testItShouldCreateDashboard() - { - $request = $this->getRequest(); + public function testItShouldCreateDashboard() + { + $request = $this->getRequest(); - $this->loginAs() - ->post(route('dashboards.store'), $request) - ->assertOk(); + $this->loginAs() + ->post(route('dashboards.store'), $request) + ->assertOk(); - $this->assertFlashLevel('success'); + $this->assertFlashLevel('success'); - $this->assertDatabaseHas('dashboards', $this->getAssertRequest($request)); - } + $this->assertDatabaseHas('dashboards', $this->getAssertRequest($request)); + } - public function testItShouldSeeDashboardUpdatePage() - { - $request = $this->getRequest(); + public function testItShouldSeeDashboardUpdatePage() + { + $request = $this->getRequest(); $dashboard = $this->dispatch(new CreateDashboard($request)); - $this->loginAs() - ->get(route('dashboards.edit', $dashboard->id)) - ->assertOk() - ->assertSee($dashboard->name); - } + $this->loginAs() + ->get(route('dashboards.edit', $dashboard->id)) + ->assertOk() + ->assertSee($dashboard->name); + } - public function testItShouldUpdateDashboard() - { - $request = $this->getRequest(); + public function testItShouldUpdateDashboard() + { + $request = $this->getRequest(); - $dashboard = $this->dispatch(new CreateDashboard($request)); + $dashboard = $this->dispatch(new CreateDashboard($request)); - $request['name'] = $this->faker->text(15); + $request['name'] = $this->faker->text(15); - $this->loginAs() - ->patch(route('dashboards.update', $dashboard->id), $request) - ->assertOk() - ->assertSee($request['name']); + $this->loginAs() + ->patch(route('dashboards.update', $dashboard->id), $request) + ->assertOk() + ->assertSee($request['name']); - $this->assertFlashLevel('success'); + $this->assertFlashLevel('success'); - $this->assertDatabaseHas('dashboards', $this->getAssertRequest($request)); - } + $this->assertDatabaseHas('dashboards', $this->getAssertRequest($request)); + } - public function testItShouldDeleteDashboard() - { - $request = $this->getRequest(); + public function testItShouldDeleteDashboard() + { + $request = $this->getRequest(); - $tmp = $this->dispatch(new CreateDashboard($this->getRequest())); - $dashboard = $this->dispatch(new CreateDashboard($request)); + $tmp = $this->dispatch(new CreateDashboard($this->getRequest())); + $dashboard = $this->dispatch(new CreateDashboard($request)); - $this->loginAs() - ->delete(route('dashboards.destroy', $dashboard->id)) - ->assertOk(); + $this->loginAs() + ->delete(route('dashboards.destroy', $dashboard->id)) + ->assertOk(); - $this->assertFlashLevel('success'); + $this->assertFlashLevel('success'); - $this->assertSoftDeleted('dashboards', $this->getAssertRequest($request)); - } + $this->assertSoftDeleted('dashboards', $this->getAssertRequest($request)); + } - public function testItShouldSeeWidgetCreate() - { - $classes = Widget::factory()->classes; - $class = $classes[rand(0, 9)]; + public function testItShouldSeeWidgetCreate() + { + $classes = Widget::factory()->classes; + $class = $classes[rand(0, 9)]; - $this->loginAs() - ->get(route('widgets.index')) - ->assertOk() - ->assertSeeText((new $class())->getDefaultName()); - } + $this->loginAs() + ->get(route('widgets.index')) + ->assertOk() + ->assertSeeText((new $class())->getDefaultName()); + } - public function testItShouldSeeWidgetEdit() - { - $widget = Widget::create($this->getWidget()); + public function testItShouldSeeWidgetEdit() + { + $widget = Widget::create($this->getWidget()); - $this->loginAs() - ->get(route('widgets.edit', $widget->id)) - ->assertOk() - ->assertSee($widget->name); - } + $this->loginAs() + ->get(route('widgets.edit', $widget->id)) + ->assertOk() + ->assertSee($widget->name); + } - public function testItShouldCreateWidget() - { - $request = $this->getWidget(); + public function testItShouldCreateWidget() + { + $request = $this->getWidget(); - $this->loginAs() - ->post(route('widgets.store'), $request) - ->assertOk(); + $this->loginAs() + ->post(route('widgets.store'), $request) + ->assertOk(); - $this->assertDatabaseHas('widgets', $this->getAssertRequest($request)); - } + $this->assertDatabaseHas('widgets', $this->getAssertRequest($request)); + } - public function testItShouldUpdateWidget() - { - $request = $this->getWidget(); + public function testItShouldUpdateWidget() + { + $request = $this->getWidget(); - $widget = Widget::create($request); + $widget = Widget::create($request); - $request['name'] = $this->faker->name; + $request['name'] = $this->faker->name; - $this->loginAs() - ->patch(route('widgets.update', $widget->id), $request) - ->assertOk(); + $this->loginAs() + ->patch(route('widgets.update', $widget->id), $request) + ->assertOk(); - $this->assertDatabaseHas('widgets', $this->getAssertRequest($request)); - } + $this->assertDatabaseHas('widgets', $this->getAssertRequest($request)); + } - public function testItShouldDeleteWidget() - { - $request = $this->getWidget(); + public function testItShouldDeleteWidget() + { + $request = $this->getWidget(); - $widget = Widget::create($request); + $widget = Widget::create($request); - $this->loginAs() - ->delete(route('widgets.destroy', $widget->id)) - ->assertOk(); + $this->loginAs() + ->delete(route('widgets.destroy', $widget->id)) + ->assertOk(); - $this->assertSoftDeleted('widgets', $this->getAssertRequest($request)); - } + $this->assertSoftDeleted('widgets', $this->getAssertRequest($request)); + } public function getRequest() { return Dashboard::factory()->enabled()->users()->raw(); } - public function getWidget() - { - return Widget::factory()->raw(); - } + public function getWidget() + { + return Widget::factory()->raw(); + } public function getAssertRequest($request) { diff --git a/tests/Feature/Common/NotificationsTest.php b/tests/Feature/Common/NotificationsTest.php new file mode 100644 index 000000000..2f3a4f2b1 --- /dev/null +++ b/tests/Feature/Common/NotificationsTest.php @@ -0,0 +1,67 @@ +loginAs() + ->get(route('notifications.index')) + ->assertStatus(200) + ->assertSeeText(trans_choice('general.items', 2)); + } + + public function testItShouldSeeReadAllAction() + { + $this->loginAs() + ->get(route('notifications.read-all')) + ->assertStatus(302); + + $this->assertFlashLevel('success'); + } + + public function testItShouldSeeDisableAction() + { + $this->loginAs() + ->post(route('notifications.disable'), ['path' => 'double-entry', 'id' => 1]) + ->assertOk() + ->assertSeeText(trans('messages.success.disabled', [ + 'type' => Str::lower(trans_choice('general.notifications', 2)) + ])); + } + + public function testItShouldSeeNewApps() + { + $notificatinos = $this->getNewApps(); + + $this->loginAs() + ->get(route('notifications.index')) + ->assertOk() + ->assertSeeText('Double-Entry'); + } + + protected function getNewApps() + { + $new_apps[] = (object) [ + "name" => "Double-Entry", + "alias" => "double-entry", + "message" => "Double-Entry<\/a> app is published. You can check it out!", + "path" =>"new-apps", + "started_at" => "2021-06-26 00:00:00", + "ended_at" => "2021-07-11 00:00:00", + "status" => 2, + ]; + + $key = 'apps.notifications'; + + Cache::put($key, ['new-apps' => $new_apps], Date::now()->addHour(6)); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 527c35a04..7e06fd16e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,6 +3,7 @@ namespace Tests; use App\Traits\Jobs; +use Illuminate\Support\Facades\Queue; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\TestCase as BaseTestCase;