Skip to content

A free open source IT asset/license management system

Got unit and browser tests working, added documentation

Chris Hartjes07585809b329
diff --git a/TESTING.md b/TESTING.md
new file mode 100644
index 0000000000..e18f6bca7d
--- /dev/null
+++ b/TESTING.md
@@ -0,0 +1,56 @@
+# Using the Test Suite
+
+This document is targeted at developers looking to make modifications to
+this application's code base and want to run the existing test suite.
+
+
+## Setup
+
+Follow the instructions for installing the application locally,
+making sure to have also run the [database migrations](link to db migrations).
+
+
+## Unit Tests
+
+The application will use values in the `.env.testing` file located
+in the root directory to override the
+default settings and/or other values that exist in your `.env` files.
+
+Make sure to modify the section in `.env.testing` that has the
+database settings. In the example below, it is connecting to the
+[MariaDB](link-to-maria-db) server that is used if you install the
+application using [Docker](https://docker.com).
+
+```dotenv
+# --------------------------------------------
+# REQUIRED: DATABASE SETTINGS
+# --------------------------------------------
+DB_CONNECTION=mysql
+DB_HOST=127.0.0.1
+DB_DATABASE=snipeit
+DB_USERNAME=root
+DB_PASSWORD=changeme1234
+```
+
+To run the entire unit test suite, use the following command from your terminal:
+
+`php artisan test --env=testing`
+
+To run individual test files, you can pass the path to the test that
+you want to run.
+
+`php artisan test --env=testing tests/Unit/AccessoryTest.php`
+
+## Browser Tests
+
+The browser tests use [Dusk](https://laravel.com/docs/8.x/dusk) to run them.
+When troubleshooting any problems, make sure that your `.env` file is configured
+correctly to run the existing application.
+
+To run the test suite use the following command from your terminal:
+
+`php artisan dusk`
+
+To run individual test files, you can pass the path to the test that you want to run.
+
+`php artisan dusk tests/Browser/LoginTest.php`
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index 4007a94998..101c15d3b5 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -26,6 +26,8 @@ services:
- .env.docker
networks:
- snipeit-backend
+ ports:
+ - "3306:3306"
redis:
image: redis:6.2.5-buster
@@ -45,4 +47,4 @@ volumes:
db: {}
networks:
- snipeit-backend: {}
\ No newline at end of file
+ snipeit-backend: {}
diff --git a/tests/Browser/LoginTest.php b/tests/Browser/LoginTest.php
index 0d54dec8f8..5ed055cda9 100644
--- a/tests/Browser/LoginTest.php
+++ b/tests/Browser/LoginTest.php
@@ -2,6 +2,7 @@
namespace Tests\Browser;
+use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
@@ -15,37 +16,31 @@ class LoginTest extends DuskTestCase
*/
public function testLoginPageLoadsAndUserCanLogin()
{
+ // Create a new user
+ $user = User::factory()->make();
+
+ // We override the existing password to use a hash of one we know
+ $user->password = '$2y$10$8o5W8fgAKJbN3Kz4taepeeRVgKsG8pkZ1L4eJfdEKrn2mgI/JgCJy';
+
+ // We want a user that is a superuser
+ $user->permissions = '{"superuser": 1}';
+
+ $user->save();
$this->browse(function (Browser $browser) {
$browser->visitRoute('login')
->assertSee(trans('auth/general.login_prompt'));
});
- $this->browse(function ($browser) {
+ $this->browse(function ($browser) use ($user) {
$browser->visitRoute('login')
- ->type('username', 'snipe')
+ ->type('username', $user->username)
->type('password', 'password')
->press(trans('auth/general.login'))
->assertPathIs('/');
$browser->screenshot('dashboard');
});
- }
-
- /**
- * Test dashboard loads
- *
- * @todo Flesh this out further to make sure the individual tables actually load with
- * content inside them.
- *
- * @return void
- */
- public function testDashboardLoadsWithSuperAdmin()
- {
- $this->browse(function ($browser) {
- $browser->assertSee(trans('general.dashboard'));
- $browser->assertSee(trans('general.loading'));
- $browser->screenshot('dashboard-2');
- });
-
+ // Delete the user afterwards
+ $user->delete();
}
}
diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php
index f3427e4412..ac750d9efc 100644
--- a/tests/DuskTestCase.php
+++ b/tests/DuskTestCase.php
@@ -41,7 +41,7 @@ abstract class DuskTestCase extends BaseTestCase
})->all());
return RemoteWebDriver::create(
- $_ENV['DUSK_DRIVER_URL'] ?? 'http://127.0.0.1:8000',
+ $_ENV['DUSK_DRIVER_URL'] ?? 'http://127.0.0.1:9515',
DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)