diff --git a/.chipperci.yml b/.chipperci.yml index 0c1ad8ba15..0c18b253c9 100644 --- a/.chipperci.yml +++ b/.chipperci.yml @@ -20,10 +20,8 @@ on: pipeline: - name: Setup cmd: | - cp -v .env.example .env -# This is simply to allow passing the guard in TestCase@setUp() -# https://chipperci.com/docs/builds/env - touch .env.testing + cp -v .env.testing.example .env + cp -v .env.testing.example .env.testing composer install --no-interaction --prefer-dist --optimize-autoloader - name: Generate Key @@ -36,15 +34,15 @@ pipeline: - name: Run Migrations cmd: | - # php artisan migrate --force + php artisan migrate --force - name: PHPUnit Unit Tests cmd: | - # php artisan test --testsuite Unit + php artisan test --testsuite Unit - name: PHPUnit Feature Tests cmd: | - # php artisan test --testsuite Feature + php artisan test --testsuite Feature # - name: Browser Tests # cmd: | diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index 136a81f62e..c72de8cb72 100755 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -262,6 +262,10 @@ class LdapSync extends Command if($ldap_result_dept != null){ $user->department_id = $department->id; } + if($ldap_result_location != null){ + $user->location_id = $location ? $location->id : null; + } + if($ldap_result_manager != null){ if($item['manager'] != null) { // Check Cache first diff --git a/app/Http/Controllers/Accessories/AccessoriesController.php b/app/Http/Controllers/Accessories/AccessoriesController.php index 111cbb3c8b..8221868f73 100755 --- a/app/Http/Controllers/Accessories/AccessoriesController.php +++ b/app/Http/Controllers/Accessories/AccessoriesController.php @@ -131,7 +131,8 @@ class AccessoriesController extends Controller // Check if the asset exists if (is_null($accessory_to_clone = Accessory::find($accessoryId))) { // Redirect to the asset management page - return redirect()->route('accessory.index')->with('error', trans('admin/accessories/message.does_not_exist')); + return redirect()->route('accessories.index') + ->with('error', trans('admin/accessories/message.does_not_exist', ['id' => $accessoryId])); } $accessory = clone $accessory_to_clone; diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 0f078326c9..c9a88ea0f1 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -590,7 +590,7 @@ class ReportsController extends Controller $executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']; \Log::debug('Added headers: '.$executionTime); - $assets = \App\Models\Company::scopeCompanyables(Asset::select('assets.*'))->with( + $assets = Asset::select('assets.*')->with( 'location', 'assetstatus', 'company', 'defaultLoc', 'assignedTo', 'model.category', 'model.manufacturer', 'supplier'); diff --git a/app/Http/Livewire/CategoryEditForm.php b/app/Http/Livewire/CategoryEditForm.php new file mode 100644 index 0000000000..05a1fe9d45 --- /dev/null +++ b/app/Http/Livewire/CategoryEditForm.php @@ -0,0 +1,67 @@ +originalSendCheckInEmailValue = $this->sendCheckInEmail; + + if ($this->eulaText || $this->useDefaultEula) { + $this->sendCheckInEmail = 1; + } + } + + public function render() + { + return view('livewire.category-edit-form'); + } + + public function updated($property, $value) + { + if (! in_array($property, ['eulaText', 'useDefaultEula'])) { + return; + } + + $this->sendCheckInEmail = $this->eulaText || $this->useDefaultEula ? 1 : $this->originalSendCheckInEmailValue; + } + + public function getShouldDisplayEmailMessageProperty(): bool + { + return $this->eulaText || $this->useDefaultEula; + } + + public function getEmailMessageProperty(): string + { + if ($this->useDefaultEula) { + return trans('admin/categories/general.email_will_be_sent_due_to_global_eula'); + } + + return trans('admin/categories/general.email_will_be_sent_due_to_category_eula'); + } + + public function getEulaTextDisabledProperty() + { + return (bool)$this->useDefaultEula; + } + + public function getSendCheckInEmailDisabledProperty() + { + return $this->eulaText || $this->useDefaultEula; + } +} diff --git a/app/Http/Livewire/Importer.php b/app/Http/Livewire/Importer.php index 2e1137bcd2..7899182a60 100644 --- a/app/Http/Livewire/Importer.php +++ b/app/Http/Livewire/Importer.php @@ -215,6 +215,7 @@ class Importer extends Component 'manufacturer' => trans('general.manufacturer'), 'order_number' => trans('general.order_number'), 'image' => trans('general.importer.image_filename'), + 'asset_eol_date' => trans('admin/hardware/form.eol_date'), /** * Checkout fields: * Assets can be checked out to other assets, people, or locations, but we currently diff --git a/config/services.php b/config/services.php index de8c4ed71a..21acb6778a 100644 --- a/config/services.php +++ b/config/services.php @@ -25,6 +25,7 @@ return [ 'mailgun' => [ 'domain' => env('MAILGUN_DOMAIN'), 'secret' => env('MAILGUN_SECRET'), + 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), ], 'mandrill' => [ diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 2445a351f3..db13224616 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -432,4 +432,13 @@ class UserFactory extends Factory ]; }); } + + public function canViewReports() + { + return $this->state(function () { + return [ + 'permissions' => '{"reports.view":"1"}', + ]; + }); + } } diff --git a/database/migrations/2023_08_01_174150_change_webhook_settings_variable_type.php b/database/migrations/2023_08_01_174150_change_webhook_settings_variable_type.php new file mode 100644 index 0000000000..59c9728e2e --- /dev/null +++ b/database/migrations/2023_08_01_174150_change_webhook_settings_variable_type.php @@ -0,0 +1,33 @@ +text('webhook_endpoint')->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('settings', function (Blueprint $table) { + $table->varchar('webhook_endpoint')->change(); + }); + + } +} diff --git a/package-lock.json b/package-lock.json index 2c334fd025..649581f940 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1565,9 +1565,9 @@ } }, "@types/eslint": { - "version": "8.44.0", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.0.tgz", - "integrity": "sha512-gsF+c/0XOguWgaOgvFs+xnnRqt9GwgTvIks36WpE6ueeI4KCEHHd8K/CKHqhOqrJKsYH8m27kRzQEvWXAwXUTw==", + "version": "8.44.2", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.2.tgz", + "integrity": "sha512-sdPRb9K6iL5XZOmBubg8yiFp5yS/JdUDQsq5e6h95km91MCYMuvp7mh1fjPEYUhvHepKpZOjnEaMBR4PxjWDzg==", "requires": { "@types/estree": "*", "@types/json-schema": "*" @@ -15962,9 +15962,9 @@ } }, "jspdf-autotable": { - "version": "3.5.25", - "resolved": "https://registry.npmjs.org/jspdf-autotable/-/jspdf-autotable-3.5.25.tgz", - "integrity": "sha512-BIbDd/cilRbVm5PmR+ZonolSqRtm0AvZDpTz+rrWed7BnFj5mqF7x7lkxDAMzPudLapktHUk6cxipcvUzal8cg==" + "version": "3.5.31", + "resolved": "https://registry.npmjs.org/jspdf-autotable/-/jspdf-autotable-3.5.31.tgz", + "integrity": "sha512-Lc1KuLGDQWW/5t57Z/+c2E94XQV3jV2QVU3xMRiwvcm/nMx79aCkpPCsxLzJZVFneZvz4XoA8+egQR1QajYiWw==" }, "junk": { "version": "3.1.0", @@ -19705,9 +19705,9 @@ } }, "webpack": { - "version": "5.88.1", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.88.1.tgz", - "integrity": "sha512-FROX3TxQnC/ox4N+3xQoWZzvGXSuscxR32rbzjpXgEzWudJFEJBpdlkkob2ylrv5yzzufD1zph1OoFsLtm6stQ==", + "version": "5.88.2", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.88.2.tgz", + "integrity": "sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ==", "requires": { "@types/eslint-scope": "^3.7.3", "@types/estree": "^1.0.0", @@ -19736,22 +19736,22 @@ }, "dependencies": { "@jridgewell/resolve-uri": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", - "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==" + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==" }, "@jridgewell/sourcemap-codec": { - "version": "1.4.14", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", - "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==" + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" }, "@jridgewell/trace-mapping": { - "version": "0.3.18", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.18.tgz", - "integrity": "sha512-w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA==", + "version": "0.3.19", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz", + "integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==", "requires": { - "@jridgewell/resolve-uri": "3.1.0", - "@jridgewell/sourcemap-codec": "1.4.14" + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" } }, "@types/json-schema": { @@ -19788,9 +19788,9 @@ } }, "terser": { - "version": "5.18.2", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.18.2.tgz", - "integrity": "sha512-Ah19JS86ypbJzTzvUCX7KOsEIhDaRONungA4aYBjEP3JZRf4ocuDzTg4QWZnPn9DEMiMYGJPiSOy7aykoCc70w==", + "version": "5.19.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.19.2.tgz", + "integrity": "sha512-qC5+dmecKJA4cpYxRa5aVkKehYsQKc+AHeKl0Oe62aYjBL8ZA33tTljktDHJSaxxMnbI5ZYw+o/S2DxxLu8OfA==", "requires": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.8.2", diff --git a/package.json b/package.json index 0752f284e7..67b5988541 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "jquery-ui": "^1.13.2", "jquery-ui-bundle": "^1.12.1", "jquery.iframe-transport": "^1.0.0", - "jspdf-autotable": "^3.5.24", + "jspdf-autotable": "^3.5.30", "less": "^4.1.2", "less-loader": "^5.0", "list.js": "^1.5.0", @@ -54,6 +54,6 @@ "tableexport.jquery.plugin": "1.28.0", "tether": "^1.4.0", "vue-resource": "^1.5.2", - "webpack": "^5.87.0" + "webpack": "^5.88.2" } } diff --git a/public/css/dist/all.css b/public/css/dist/all.css index 3313bdac45..6a556a42bf 100644 Binary files a/public/css/dist/all.css and b/public/css/dist/all.css differ diff --git a/public/css/dist/bootstrap-table.css b/public/css/dist/bootstrap-table.css index c8749ad4b4..301c592a5d 100644 Binary files a/public/css/dist/bootstrap-table.css and b/public/css/dist/bootstrap-table.css differ diff --git a/public/js/dist/bootstrap-table.js b/public/js/dist/bootstrap-table.js index 53d6e2d52d..c01fba3e19 100644 Binary files a/public/js/dist/bootstrap-table.js and b/public/js/dist/bootstrap-table.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 957e6e556e..b1c491bc26 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -18,7 +18,7 @@ "/css/dist/skins/skin-green.css": "/css/dist/skins/skin-green.css?id=0a82a6ae6bb4e58fe62d162c4fb50397", "/css/dist/skins/skin-contrast.css": "/css/dist/skins/skin-contrast.css?id=da6c7997d9de2f8329142399f0ce50da", "/css/dist/skins/skin-red.css": "/css/dist/skins/skin-red.css?id=44bf834f2110504a793dadec132a5898", - "/css/dist/all.css": "/css/dist/all.css?id=ae5d0ce9886bbe4ad4b021c6be19ec36", + "/css/dist/all.css": "/css/dist/all.css?id=8b29a53b11e372ceb332b1a2f7026632", "/css/dist/signature-pad.css": "/css/dist/signature-pad.css?id=6a89d3cd901305e66ced1cf5f13147f7", "/css/dist/signature-pad.min.css": "/css/dist/signature-pad.min.css?id=6a89d3cd901305e66ced1cf5f13147f7", "/css/webfonts/fa-brands-400.ttf": "/css/webfonts/fa-brands-400.ttf?id=e2e2b1797606a266ed55549f5bb5a179", @@ -29,9 +29,9 @@ "/css/webfonts/fa-solid-900.woff2": "/css/webfonts/fa-solid-900.woff2?id=eea38615e7b5dbbaf88c263f2230cc32", "/css/webfonts/fa-v4compatibility.ttf": "/css/webfonts/fa-v4compatibility.ttf?id=6ebbf5afc34f54463abc2b81ca637364", "/css/webfonts/fa-v4compatibility.woff2": "/css/webfonts/fa-v4compatibility.woff2?id=67b8a78b7e80e805cfa4ee0421895ba4", - "/css/dist/bootstrap-table.css": "/css/dist/bootstrap-table.css?id=f5935cf8eaf9c1f71da0c9245d730471", + "/css/dist/bootstrap-table.css": "/css/dist/bootstrap-table.css?id=281bcfe26549412d128f695234961081", "/js/build/vendor.js": "/js/build/vendor.js?id=3592e07ae9a6d1805a4ea3bd3c034aef", - "/js/dist/bootstrap-table.js": "/js/dist/bootstrap-table.js?id=40e2dc8b5b29e244bb545f78e2a3242b", + "/js/dist/bootstrap-table.js": "/js/dist/bootstrap-table.js?id=df78f0c4cc93c29c02a41144590f6350", "/js/dist/all.js": "/js/dist/all.js?id=ba07d399f23b294f7c4983030b757423", "/css/dist/skins/skin-green.min.css": "/css/dist/skins/skin-green.min.css?id=0a82a6ae6bb4e58fe62d162c4fb50397", "/css/dist/skins/skin-green-dark.min.css": "/css/dist/skins/skin-green-dark.min.css?id=e36e83c2aa3c3afdbb8ebe2c0309e91d", diff --git a/resources/lang/en/admin/categories/general.php b/resources/lang/en/admin/categories/general.php index 52e936d0b6..2fe448b44e 100644 --- a/resources/lang/en/admin/categories/general.php +++ b/resources/lang/en/admin/categories/general.php @@ -8,6 +8,8 @@ return array( 'clone' => 'Clone Category', 'create' => 'Create Category', 'edit' => 'Edit Category', + 'email_will_be_sent_due_to_global_eula' => 'An email will be sent to the user because the global EULA is being used.', + 'email_will_be_sent_due_to_category_eula' => 'An email will be sent to the user because a EULA is set for this category.', 'eula_text' => 'Category EULA', 'eula_text_help' => 'This field allows you to customize your EULAs for specific types of assets. If you only have one EULA for all of your assets, you can check the box below to use the primary default.', 'name' => 'Category Name', diff --git a/resources/views/categories/edit.blade.php b/resources/views/categories/edit.blade.php index 813e8463e9..1ef3b7aa6a 100755 --- a/resources/views/categories/edit.blade.php +++ b/resources/views/categories/edit.blade.php @@ -23,59 +23,13 @@ - - - -
- -
- {{ Form::textarea('eula_text', old('eula_text', $item->eula_text), array('class' => 'form-control', 'aria-label'=>'eula_text')) }} -

{!! trans('admin/categories/general.eula_text_help') !!}

-

{!! trans('admin/settings/general.eula_markdown') !!}

- - {!! $errors->first('eula_text', '') !!} -
-
- - -
-
- @if ($snipeSettings->default_eula_text!='') - - @else - - @endif -
-
- - - -
-
- -
-
- - - -
-
- -
-
- + @include ('partials.forms.edit.image-upload', ['image_path' => app('categories_upload_path')]) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index d11d3c541f..4363584972 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -973,7 +973,12 @@ $(function () { - $('[data-tooltip="true"]').tooltip(); + // Invoke Bootstrap 3's tooltip + $('[data-tooltip="true"]').tooltip({ + container: 'body', + animation: true, + }); + $('[data-toggle="popover"]').popover(); $('.select2 span').addClass('needsclick'); $('.select2 span').removeAttr('title'); diff --git a/resources/views/livewire/category-edit-form.blade.php b/resources/views/livewire/category-edit-form.blade.php new file mode 100644 index 0000000000..33b41b71e9 --- /dev/null +++ b/resources/views/livewire/category-edit-form.blade.php @@ -0,0 +1,61 @@ +
+ +
+ +
+ {{ Form::textarea('eula_text', null, ['wire:model' => 'eulaText', 'class' => 'form-control', 'aria-label'=>'eula_text', 'disabled' => $this->eulaTextDisabled]) }} +

{!! trans('admin/categories/general.eula_text_help') !!}

+

{!! trans('admin/settings/general.eula_markdown') !!}

+ {!! $errors->first('eula_text', '') !!} +
+ @if ($this->eulaTextDisabled) + + @endif +
+ + +
+
+ @if ($defaultEulaText!='') + + @else + + @endif +
+
+ + +
+
+ +
+
+ + +
+
+ + @if ($this->shouldDisplayEmailMessage) +
+ + {{ $this->emailMessage }} +
+ @endif + @if ($this->sendCheckInEmailDisabled) + + @endif +
+
+
diff --git a/resources/views/models/custom_fields_form.blade.php b/resources/views/models/custom_fields_form.blade.php index 011ad4ca9b..bae98373e4 100644 --- a/resources/views/models/custom_fields_form.blade.php +++ b/resources/views/models/custom_fields_form.blade.php @@ -85,3 +85,12 @@ @endforeach @endif + + + diff --git a/resources/views/reports/asset_maintenances.blade.php b/resources/views/reports/asset_maintenances.blade.php index 9845553363..ea12df34d1 100644 --- a/resources/views/reports/asset_maintenances.blade.php +++ b/resources/views/reports/asset_maintenances.blade.php @@ -48,7 +48,7 @@ {{ trans('admin/asset_maintenances/form.cost') }} {{ trans('general.location') }} {{ trans('admin/hardware/form.default_location') }} - {{ trans('admin/asset_maintenances/table.is_warranty') }} + {{ trans('admin/asset_maintenances/table.is_warranty') }} {{ trans('general.admin') }} {{ trans('admin/asset_maintenances/form.notes') }} diff --git a/tests/Feature/Livewire/CategoryEditFormTest.php b/tests/Feature/Livewire/CategoryEditFormTest.php new file mode 100644 index 0000000000..26719e4041 --- /dev/null +++ b/tests/Feature/Livewire/CategoryEditFormTest.php @@ -0,0 +1,105 @@ +assertStatus(200); + } + + public function testSendEmailCheckboxIsCheckedOnLoadWhenSendEmailIsExistingSetting() + { + Livewire::test(CategoryEditForm::class, [ + 'sendCheckInEmail' => true, + 'eulaText' => '', + 'useDefaultEula' => false, + ])->assertSet('sendCheckInEmail', true); + } + + public function testSendEmailCheckboxIsCheckedOnLoadWhenCategoryEulaSet() + { + Livewire::test(CategoryEditForm::class, [ + 'sendCheckInEmail' => false, + 'eulaText' => 'Some Content', + 'useDefaultEula' => false, + ])->assertSet('sendCheckInEmail', true); + } + + public function testSendEmailCheckboxIsCheckedOnLoadWhenUsingDefaultEula() + { + Livewire::test(CategoryEditForm::class, [ + 'sendCheckInEmail' => false, + 'eulaText' => '', + 'useDefaultEula' => true, + ])->assertSet('sendCheckInEmail', true); + } + + public function testSendEmailCheckBoxIsUncheckedOnLoadWhenSendEmailIsFalseNoCategoryEulaSetAndNotUsingDefaultEula() + { + Livewire::test(CategoryEditForm::class, [ + 'sendCheckInEmail' => false, + 'eulaText' => '', + 'useDefaultEula' => false, + ])->assertSet('sendCheckInEmail', false); + } + + public function testSendEmailCheckboxIsCheckedWhenCategoryEulaEntered() + { + Livewire::test(CategoryEditForm::class, [ + 'sendCheckInEmail' => false, + 'useDefaultEula' => false, + ])->assertSet('sendCheckInEmail', false) + ->set('eulaText', 'Some Content') + ->assertSet('sendCheckInEmail', true); + } + + public function testSendEmailCheckboxCheckedAndDisabledAndEulaTextDisabledWhenUseDefaultEulaSelected() + { + Livewire::test(CategoryEditForm::class, [ + 'sendCheckInEmail' => false, + 'useDefaultEula' => false, + ])->assertSet('sendCheckInEmail', false) + ->set('useDefaultEula', true) + ->assertSet('sendCheckInEmail', true) + ->assertSet('eulaTextDisabled', true) + ->assertSet('sendCheckInEmailDisabled', true); + } + + public function testSendEmailCheckboxEnabledAndSetToOriginalValueWhenNoCategoryEulaAndNotUsingGlobalEula() + { + Livewire::test(CategoryEditForm::class, [ + 'eulaText' => 'Some Content', + 'sendCheckInEmail' => false, + 'useDefaultEula' => true, + ]) + ->set('useDefaultEula', false) + ->set('eulaText', '') + ->assertSet('sendCheckInEmail', false) + ->assertSet('sendCheckInEmailDisabled', false); + + Livewire::test(CategoryEditForm::class, [ + 'eulaText' => 'Some Content', + 'sendCheckInEmail' => true, + 'useDefaultEula' => true, + ]) + ->set('useDefaultEula', false) + ->set('eulaText', '') + ->assertSet('sendCheckInEmail', true) + ->assertSet('sendCheckInEmailDisabled', false); + } + + public function testEulaFieldEnabledOnLoadWhenNotUsingDefaultEula() + { + Livewire::test(CategoryEditForm::class, [ + 'sendCheckInEmail' => false, + 'eulaText' => '', + 'useDefaultEula' => false, + ])->assertSet('eulaTextDisabled', false); + } +} diff --git a/tests/Feature/Reports/CustomReportTest.php b/tests/Feature/Reports/CustomReportTest.php new file mode 100644 index 0000000000..b27ebc27ef --- /dev/null +++ b/tests/Feature/Reports/CustomReportTest.php @@ -0,0 +1,110 @@ +streamedContent())->getRecords()) + ->pluck(0) + ->contains($needle) + ); + + return $this; + } + ); + + TestResponse::macro( + 'assertDontSeeTextInStreamedResponse', + function (string $needle) { + Assert::assertFalse( + collect(Reader::createFromString($this->streamedContent())->getRecords()) + ->pluck(0) + ->contains($needle) + ); + + return $this; + } + ); + } + + public function testCustomAssetReport() + { + Asset::factory()->create(['name' => 'Asset A']); + Asset::factory()->create(['name' => 'Asset B']); + + $this->actingAs(User::factory()->canViewReports()->create()) + ->post('reports/custom', [ + 'asset_name' => '1', + 'asset_tag' => '1', + 'serial' => '1', + ])->assertOk() + ->assertHeader('content-type', 'text/csv; charset=UTF-8') + ->assertSeeTextInStreamedResponse('Asset A') + ->assertSeeTextInStreamedResponse('Asset B'); + } + + public function testCustomAssetReportAdheresToCompanyScoping() + { + [$companyA, $companyB] = Company::factory()->count(2)->create(); + + Asset::factory()->for($companyA)->create(['name' => 'Asset A']); + Asset::factory()->for($companyB)->create(['name' => 'Asset B']); + + $superUser = $companyA->users()->save(User::factory()->superuser()->make()); + $userInCompanyA = $companyA->users()->save(User::factory()->canViewReports()->make()); + $userInCompanyB = $companyB->users()->save(User::factory()->canViewReports()->make()); + + $this->settings->disableMultipleFullCompanySupport(); + + $this->actingAs($superUser) + ->post('reports/custom', ['asset_name' => '1', 'asset_tag' => '1', 'serial' => '1']) + ->assertSeeTextInStreamedResponse('Asset A') + ->assertSeeTextInStreamedResponse('Asset B'); + + $this->actingAs($userInCompanyA) + ->post('reports/custom', ['asset_name' => '1', 'asset_tag' => '1', 'serial' => '1']) + ->assertSeeTextInStreamedResponse('Asset A') + ->assertSeeTextInStreamedResponse('Asset B'); + + $this->actingAs($userInCompanyB) + ->post('reports/custom', ['asset_name' => '1', 'asset_tag' => '1', 'serial' => '1']) + ->assertSeeTextInStreamedResponse('Asset A') + ->assertSeeTextInStreamedResponse('Asset B'); + + $this->settings->enableMultipleFullCompanySupport(); + + $this->actingAs($superUser) + ->post('reports/custom', ['asset_name' => '1', 'asset_tag' => '1', 'serial' => '1']) + ->assertSeeTextInStreamedResponse('Asset A') + ->assertSeeTextInStreamedResponse('Asset B'); + + $this->actingAs($userInCompanyA) + ->post('reports/custom', ['asset_name' => '1', 'asset_tag' => '1', 'serial' => '1']) + ->assertSeeTextInStreamedResponse('Asset A') + ->assertDontSeeTextInStreamedResponse('Asset B'); + + $this->actingAs($userInCompanyB) + ->post('reports/custom', ['asset_name' => '1', 'asset_tag' => '1', 'serial' => '1']) + ->assertDontSeeTextInStreamedResponse('Asset A') + ->assertSeeTextInStreamedResponse('Asset B'); + } +} diff --git a/tests/Support/CustomTestMacros.php b/tests/Support/CustomTestMacros.php index 0a30d7c243..4242b28653 100644 --- a/tests/Support/CustomTestMacros.php +++ b/tests/Support/CustomTestMacros.php @@ -24,7 +24,10 @@ trait CustomTestMacros function (Model $model, string $property = 'name') use ($guardAgainstNullProperty) { $guardAgainstNullProperty($model, $property); - Assert::assertTrue(collect($this['rows'])->pluck($property)->contains($model->{$property})); + Assert::assertTrue( + collect($this['rows'])->pluck($property)->contains(e($model->{$property})), + "Response did not contain the expected value: {$model->{$property}}" + ); return $this; } @@ -35,7 +38,10 @@ trait CustomTestMacros function (Model $model, string $property = 'name') use ($guardAgainstNullProperty) { $guardAgainstNullProperty($model, $property); - Assert::assertFalse(collect($this['rows'])->pluck($property)->contains($model->{$property})); + Assert::assertFalse( + collect($this['rows'])->pluck($property)->contains(e($model->{$property})), + "Response contained unexpected value: {$model->{$property}}" + ); return $this; } @@ -46,7 +52,10 @@ trait CustomTestMacros function (Model $model, string $property = 'id') use ($guardAgainstNullProperty) { $guardAgainstNullProperty($model, $property); - Assert::assertTrue(collect($this->json('results'))->pluck('id')->contains($model->{$property})); + Assert::assertTrue( + collect($this->json('results'))->pluck('id')->contains(e($model->{$property})), + "Response did not contain the expected value: {$model->{$property}}" + ); return $this; } @@ -57,7 +66,10 @@ trait CustomTestMacros function (Model $model, string $property = 'id') use ($guardAgainstNullProperty) { $guardAgainstNullProperty($model, $property); - Assert::assertFalse(collect($this->json('results'))->pluck('id')->contains($model->{$property})); + Assert::assertFalse( + collect($this->json('results'))->pluck('id')->contains(e($model->{$property})), + "Response contained unexpected value: {$model->{$property}}" + ); return $this; } diff --git a/tests/Unit/_bootstrap.php b/tests/Unit/_bootstrap.php deleted file mode 100644 index 62817a53c4..0000000000 --- a/tests/Unit/_bootstrap.php +++ /dev/null @@ -1,3 +0,0 @@ -loadSessionSnapshot('login')) return; - - // logging in - $I->amOnPage('/login'); - $I->fillField('username', 'snipe'); - $I->fillField('password', 'password'); - $I->click('Login'); - //$I->saveSessionSnapshot('login'); - } -} diff --git a/tests/_support/ApiTester.php b/tests/_support/ApiTester.php deleted file mode 100644 index f76364bc19..0000000000 --- a/tests/_support/ApiTester.php +++ /dev/null @@ -1,58 +0,0 @@ -createPersonalAccessClient($user->id, 'Codeception API Test Client', - 'http://localhost/'); - - \Illuminate\Support\Facades\DB::table('oauth_personal_access_clients')->insert([ - 'client_id' => $client->id, - 'created_at' => new DateTime, - 'updated_at' => new DateTime, - ]); - - $user->permissions = json_encode(['superuser' => true]); - $user->save(); - - $token = $user->createToken('CodeceptionAPItestToken')->accessToken; - - return $token; - } - - /** - * Remove Timestamps from transformed array - * This fixes false negatives when comparing json due to timestamp second rounding issues - * @param array $array Array returned from the transformer - * @return array Transformed item striped of created_at and updated_at - */ - public function removeTimeStamps($array) - { - unset($array['created_at']); - unset($array['updated_at']); - - return $array; - } -} diff --git a/tests/_support/FunctionalTester.php b/tests/_support/FunctionalTester.php deleted file mode 100644 index 7eabf4cf4b..0000000000 --- a/tests/_support/FunctionalTester.php +++ /dev/null @@ -1,151 +0,0 @@ - first()->id; - } - - public function getCategoryId() - { - return Category::inRandomOrder()->first()->id; - } - - public function getManufacturerId() - { - return Manufacturer::inRandomOrder()->first()->id; - } - - public function getLocationId() - { - return Location::inRandomOrder()->first()->id; - } - - /** - * @return mixed Random Accessory Id - */ - public function getAccessoryId() - { - return Accessory::inRandomOrder()->first()->id; - } - - /** - * @return mixed Random Asset Model Id; - */ - public function getModelId() - { - return AssetModel::inRandomOrder()->first()->id; - } - - /** - * @return mixed Id of Empty Asset Model - */ - public function getEmptyModelId() - { - return AssetModel::doesntHave('assets')->first()->id; - } - - /** - * @return mixed Id of random status - */ - public function getStatusId() - { - return StatusLabel::inRandomOrder()->first()->id; - } - - /** - * Id of random user - * @return mixed - */ - public function getUserId() - { - return User::inRandomOrder()->first()->id; - } - - /** - * @return mixed Id of random supplier - */ - public function getSupplierId() - { - return Supplier::inRandomOrder()->first()->id; - } - - /** - * @return mixed Id of Random Asset - */ - public function getAssetId() - { - return Asset::inRandomOrder()->first()->id; - } - - /** - * An Empty category - * @return mixed Id of Empty Category - */ - public function getEmptyCategoryId() - { - return Category::where('category_type', 'asset')->doesntHave('models')->first()->id; - } - - /** - * A random component id for testing - * @return mixed Id of random component - */ - public function getComponentId() - { - return Component::inRandomOrder()->first()->id; - } - - /** - * A random consumable Id for testing - * @return mixed - */ - public function getConsumableId() - { - return Consumable::inRandomOrder()->first()->id; - } - - /** - * Return a random depreciation id for tests. - * @return mixed - */ - public function getDepreciationId() - { - return Depreciation::inRandomOrder()->first()->id; - } -} diff --git a/tests/_support/Helper/Acceptance.php b/tests/_support/Helper/Acceptance.php deleted file mode 100644 index 2dd1562b13..0000000000 --- a/tests/_support/Helper/Acceptance.php +++ /dev/null @@ -1,10 +0,0 @@ -validateHTML(); - * - * Validate the HTML of the current page, but ignore errors containing the string "Ignoreit": - * $I->validateHTML(["Ignoreme"]); - * - * - * - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @author Tobias Hößl - */ - -namespace Helper; - -use Codeception\TestCase; - -class HTMLValidator extends \Codeception\Module -{ - /** - * @param string $html - * @return array - * @throws \Exception - */ - private function validateByVNU($html) - { - $javaPath = $this->_getConfig('javaPath'); - if (! $javaPath) { - $javaPath = 'java'; - } - $vnuPath = $this->_getConfig('vnuPath'); - if (! $vnuPath) { - $vnuPath = '/usr/local/bin/vnu.jar'; - } - - $filename = DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.uniqid('html-validate').'.html'; - file_put_contents($filename, $html); - exec($javaPath.' -Xss1024k -jar '.$vnuPath.' --format json '.$filename.' 2>&1', $return); - $data = json_decode($return[0], true); - if (! $data || ! isset($data['messages']) || ! is_array($data['messages'])) { - throw new \Exception('Invalid data returned from validation service: '.$return); - } - - return $data['messages']; - } - - /** - * @return string - * @throws \Codeception\Exception\ModuleException - * @throws \Exception - */ - private function getPageSource() - { - if (! $this->hasModule('WebDriver')) { - throw new \Exception('This validator needs WebDriver to work'); - } - - /** @var \Codeception\Module\WebDriver $webdriver */ - $webdriver = $this->getModule('WebDriver'); - - return $webdriver->webDriver->getPageSource(); - } - - /** - * @param string[] $ignoreMessages - */ - public function validateHTML($ignoreMessages = []) - { - $source = $this->getPageSource(); - try { - $messages = $this->validateByVNU($source); - } catch (\Exception $e) { - $this->fail($e->getMessage()); - - return; - } - $failMessages = []; - $lines = explode("\n", $source); - foreach ($messages as $message) { - if ($message['type'] == 'error') { - $formattedMsg = '- Line '.$message['lastLine'].', column '.$message['lastColumn'].': '. - $message['message']."\n > ".$lines[$message['lastLine'] - 1]; - $ignoring = false; - foreach ($ignoreMessages as $ignoreMessage) { - if (mb_stripos($formattedMsg, $ignoreMessage) !== false) { - $ignoring = true; - } - } - if (! $ignoring) { - $failMessages[] = $formattedMsg; - } - } - } - if (count($failMessages) > 0) { - \PHPUnit_Framework_Assert::fail('Invalid HTML: '."\n".implode("\n", $failMessages)); - } - } -} diff --git a/tests/_support/Helper/Unit.php b/tests/_support/Helper/Unit.php deleted file mode 100644 index 4d27aa3599..0000000000 --- a/tests/_support/Helper/Unit.php +++ /dev/null @@ -1,10 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that the accessories listing page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/accessories'); -$I->waitForElement('.table', 5); // secs -$I->seeNumberOfElements('table[name="accessories"] tr', [5, 30]); -$I->seeInTitle('Accessories'); -$I->see('Accessories'); -$I->seeInPageSource('accessories/create'); -$I->dontSee('Accessories', '.page-header'); -$I->see('Accessories', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure that the create accessories form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->click(['link' => 'Create New']); -$I->amOnPage('/accessories/create'); -$I->dontSee('Create Accessory', '.page-header'); -$I->see('Create Accessory', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/AssetsCept.php b/tests/acceptance/AssetsCept.php deleted file mode 100644 index 6cc39e028c..0000000000 --- a/tests/acceptance/AssetsCept.php +++ /dev/null @@ -1,24 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that assets page loads without errors'); -$I->amGoingTo('go to the assets listing page'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/hardware'); -$I->waitForElement('.table', 5); // secs -$I->seeNumberOfElements('table[name="assets"] tr', [5, 50]); -$I->seeInTitle('Assets'); -$I->see('Assets'); -$I->seeInPageSource('hardware/create'); -$I->dontSee('Assets', '.page-header'); -$I->see('Assets', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure that the create assets form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/hardware/create'); -$I->dontSee('Create Asset', '.page-header'); -$I->see('Create Asset', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/AssetsCest.php b/tests/acceptance/AssetsCest.php deleted file mode 100644 index 51011ce830..0000000000 --- a/tests/acceptance/AssetsCest.php +++ /dev/null @@ -1,33 +0,0 @@ -am('logged in user'); - $I->wantTo('ensure that assets page loads without errors'); - $I->amGoingTo('go to the assets listing page'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage('/hardware'); - $I->waitForElement('.table', 20); // secs - $I->seeNumberOfElements('table[name="assets"] tr', [5, 50]); - $I->seeInTitle(trans('general.assets')); - $I->see(trans('general.assets')); - $I->seeInPageSource('hardware/create'); - $I->see(trans('general.assets'), 'h1.pull-left'); - } - - public function createAsset(AcceptanceTester $I) - { - $I->wantTo('ensure that the create assets form loads without errors'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage('/hardware/create'); - $I->dontSee('Create Asset', '.page-header'); - $I->see('Create Asset', 'h1.pull-left'); - } -} diff --git a/tests/acceptance/CategoriesCept.php b/tests/acceptance/CategoriesCept.php deleted file mode 100644 index 75a6d2be11..0000000000 --- a/tests/acceptance/CategoriesCept.php +++ /dev/null @@ -1,24 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that the categories listing page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/categories'); -$I->waitForElement('.table', 5); // secs -$I->seeNumberOfElements('table[name="categories"] tr', [5, 30]); -$I->seeInTitle('Categories'); -$I->see('Categories'); -$I->seeInPageSource('/categories/create'); -$I->dontSee('Categories', '.page-header'); -$I->see('Categories', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure that the create category form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->click(['link' => 'Create New']); -$I->amOnPage('/categories/create'); -$I->dontSee('Create Category', '.page-header'); -$I->see('Create Category', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/CompaniesCept.php b/tests/acceptance/CompaniesCept.php deleted file mode 100644 index 98a06a6bfb..0000000000 --- a/tests/acceptance/CompaniesCept.php +++ /dev/null @@ -1,25 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that the company listing page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/companies'); -$I->waitForElement('.table', 5); // secs -$I->seeNumberOfElements('table[name="companies"] tr', [5, 30]); -$I->seeInTitle('Companies'); -$I->see('Companies'); -$I->seeInPageSource('companies/create'); -$I->dontSee('Companies', '.page-header'); -$I->see('Companies', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure that the create company form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->click(['link' => 'Create New']); -$I->amOnPage('/companies/create'); -$I->dontSee('Create Company', '.page-header'); -$I->see('Create Company', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/ConsumablesCept.php b/tests/acceptance/ConsumablesCept.php deleted file mode 100644 index 9461c232c3..0000000000 --- a/tests/acceptance/ConsumablesCept.php +++ /dev/null @@ -1,24 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that the consumables listing page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/consumables'); -$I->waitForElement('.table', 5); // secs -$I->seeNumberOfElements('table[name="consumables"] tr', [5, 30]); -$I->seeInTitle('Consumables'); -$I->see('Consumables'); -$I->seeInPageSource('/consumables/create'); -$I->dontSee('Consumables', '.page-header'); -$I->see('Consumables', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure that the create consumables form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->click(['link' => 'Create New']); -$I->amOnPage('/consumables/create'); -$I->dontSee('Create Consumable', '.page-header'); -$I->see('Create Consumable', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/CustomfieldsCept.php b/tests/acceptance/CustomfieldsCept.php deleted file mode 100644 index 9526316999..0000000000 --- a/tests/acceptance/CustomfieldsCept.php +++ /dev/null @@ -1,14 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that the custom fields page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/fields'); -$I->seeInTitle('Custom Fields'); -$I->see('Custom Fields'); -$I->seeInPageSource('/fields/create'); -$I->dontSee('Custom Fields', '.page-header'); -$I->dontSee('Fieldsets', '.page-header'); -$I->see('Manage Custom Fields', 'h1.pull-left'); diff --git a/tests/acceptance/DepartmentsCept.php b/tests/acceptance/DepartmentsCept.php deleted file mode 100644 index e9f6fd6b9c..0000000000 --- a/tests/acceptance/DepartmentsCept.php +++ /dev/null @@ -1,25 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that the department listing page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/departments'); -$I->waitForElement('.table', 5); // secs -$I->seeNumberOfElements('table[name="departments"] tr', [5, 30]); -$I->seeInTitle('Departments'); -$I->see('Departments'); -$I->seeInPageSource('departments/create'); -$I->dontSee('Departments', '.page-header'); -$I->see('Departments', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure that the create department form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->click(['link' => 'Create New']); -$I->amOnPage('/department/create'); -$I->dontSee('Create Department', '.page-header'); -$I->see('Create Department', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/DepreciationsCept.php b/tests/acceptance/DepreciationsCept.php deleted file mode 100644 index d0f43ad4e5..0000000000 --- a/tests/acceptance/DepreciationsCept.php +++ /dev/null @@ -1,25 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that depreciations page loads without errors'); -$I->amGoingTo('go to the depreciations listing page'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/depreciations'); -$I->seeInTitle('Depreciations'); -$I->waitForElement('.table', 5); // secs -$I->seeNumberOfElements('table[name="depreciations"] tbody tr', [1, 5]); -$I->seeInPageSource('/depreciations/create'); -$I->dontSee('Depreciations', '.page-header'); -$I->see('Depreciations', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure that the create depreciation form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->click(['link' => 'Create New']); -$I->amOnPage('/depreciations/create'); -$I->seeInTitle('Create Depreciation'); -$I->dontSee('Create Depreciation', '.page-header'); -$I->see('Create Depreciation', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/LocationsCept.php b/tests/acceptance/LocationsCept.php deleted file mode 100644 index 600b5c2822..0000000000 --- a/tests/acceptance/LocationsCept.php +++ /dev/null @@ -1,24 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that the locations listing page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/locations'); -$I->waitForElement('.table', 5); // secs -$I->seeNumberOfElements('tr', [5, 30]); -$I->seeInTitle('Locations'); -$I->see('Locations'); -$I->seeInPageSource('/locations/create'); -$I->dontSee('Locations', '.page-header'); -$I->see('Locations', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure that the create location form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->click(['link' => 'Create New']); -$I->amOnPage('/locations/create'); -$I->dontSee('Create Location', '.page-header'); -$I->see('Create Location', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/LoginCest.php b/tests/acceptance/LoginCest.php deleted file mode 100644 index 97fdbf5921..0000000000 --- a/tests/acceptance/LoginCest.php +++ /dev/null @@ -1,18 +0,0 @@ -wantTo('sign in'); - $I->amOnPage('/login'); - $I->see(trans('auth/general.login_prompt')); - $I->seeElement('input[type=text]'); - $I->seeElement('input[type=password]'); - } -} diff --git a/tests/acceptance/ManufacturersCept.php b/tests/acceptance/ManufacturersCept.php deleted file mode 100644 index 69d0c0e6da..0000000000 --- a/tests/acceptance/ManufacturersCept.php +++ /dev/null @@ -1,23 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that the manufacturers listing page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/manufacturers'); -$I->seeNumberOfElements('table[name="manufacturers"] tr', [5, 30]); -$I->see('Manufacturers'); -$I->seeInTitle('Manufacturers'); -$I->seeInPageSource('manufacturers/create'); -$I->dontSee('Manufacturers', '.page-header'); -$I->see('Manufacturers', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure that the create manufacturer form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->click(['link' => 'Create New']); -$I->amOnPage('/manufacturers/create'); -$I->dontSee('Create Manufacturer', '.page-header'); -$I->see('Create Manufacturer', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/StatuslabelsCept.php b/tests/acceptance/StatuslabelsCept.php deleted file mode 100644 index 224a713250..0000000000 --- a/tests/acceptance/StatuslabelsCept.php +++ /dev/null @@ -1,24 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure the status labels listing page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/statuslabels'); -$I->waitForElement('.table', 5); // secs -$I->seeNumberOfElements('tr', [1, 30]); -$I->seeInTitle('Status Labels'); -$I->see('Status Labels'); -$I->seeInPageSource('statuslabels/create'); -$I->dontSee('Status Labels', '.page-header'); -$I->see('Status Labels', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure the create status labels form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->click(['link' => 'Create New']); -$I->amOnPage('/statuslabels/create'); -$I->dontSee('Create Status Label', '.page-header'); -$I->see('Create Status Label', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/SuppliersCept.php b/tests/acceptance/SuppliersCept.php deleted file mode 100644 index 59840dfd9d..0000000000 --- a/tests/acceptance/SuppliersCept.php +++ /dev/null @@ -1,24 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that the suppliers listing page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/suppliers'); -$I->waitForElement('.table', 5); // secs -$I->seeNumberOfElements('table[name="suppliers"] tr', [5, 25]); -$I->seeInTitle('Suppliers'); -$I->see('Suppliers'); -$I->seeInPageSource('suppliers/create'); -$I->dontSee('Suppliers', '.page-header'); -$I->see('Suppliers', 'h1.pull-left'); - -/* Create Form */ -$I->wantTo('ensure the create supplier form loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->click(['link' => 'Create New']); -$I->amOnPage('/suppliers/create'); -$I->dontSee('Create Supplier', '.page-header'); -$I->see('Create Supplier', 'h1.pull-left'); -$I->dontSee('<span class="'); diff --git a/tests/acceptance/UsersCept.php b/tests/acceptance/UsersCept.php deleted file mode 100644 index ddad283ef1..0000000000 --- a/tests/acceptance/UsersCept.php +++ /dev/null @@ -1,63 +0,0 @@ -am('logged in user'); -$I->wantTo('ensure that the users listing page loads without errors'); -$I->lookForwardTo('seeing it load without errors'); -$I->amOnPage('/users'); -//$I->waitForJS("return $.active == 0;", 60); -$I->waitForElement('.table', 5); // secs -//$I->seeNumberOfElements('tr', [1,10]); -$I->seeInTitle('Users'); -$I->see('Users'); -$I->seeInPageSource('users/create'); -$I->dontSee('Users', '.page-header'); -$I->see('Users', 'h1.pull-left'); -$I->seeLink('Create New'); // matches Logout - -/* Create form */ -$I->am('logged in admin'); -$I->wantTo('ensure that you get errors when you submit an incomplete form'); -$I->lookForwardTo('seeing errors display'); -$I->click(['link' => 'Create New']); -$I->amOnPage('users/create'); -$I->dontSee('Create User', '.page-header'); -$I->see('Create User', 'h1.pull-left'); - -/* Submit form and expect errors */ -$I->click(['name' => 'email']); -$I->submitForm('#userForm', [ - 'email' => 'me@example.com', -]); -$I->seeElement('.alert-danger'); -$I->dontSeeInSource('<br><'); - -/* Submit form and expect errors */ -$I->click(['name' => 'email']); -$I->click(['name' => 'username']); -$I->submitForm('#userForm', [ - 'email' => Helper::generateRandomString(15).'@example.com', - 'first_name' => 'Joe', - 'last_name' => 'Smith', - 'username' => Helper::generateRandomString(15), -]); - -$I->seeElement('.alert-danger'); -$I->dontSeeInSource('<br><'); - -/* Submit form and expect success */ -$I->wantTo('submit the form successfully'); -$I->click(['name' => 'email']); -$I->fillField(['name' => 'email'], Helper::generateRandomString(15).'@example.com'); -$I->fillField(['name' => 'first_name'], 'Joe'); -$I->fillField(['name' => 'last_name'], 'Smith'); -$I->click(['name' => 'username']); -$I->fillField(['name' => 'username'], Helper::generateRandomString(15)); -$I->click(['name' => 'password']); -$I->fillField(['name' => 'password'], 'password'); -$I->click(['name' => 'password_confirmation']); -$I->fillField(['name' => 'password_confirmation'], 'password'); -$I->click('Save'); -$I->seeElement('.alert-success'); -$I->dontSeeInSource('<br><'); diff --git a/tests/acceptance/_bootstrap.php b/tests/acceptance/_bootstrap.php deleted file mode 100644 index 62817a53c4..0000000000 --- a/tests/acceptance/_bootstrap.php +++ /dev/null @@ -1,3 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexAccessories(ApiTester $I) - { - $I->wantTo('Get a list of accessories'); - - // call - $I->sendGET('/accessories?limit=10'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - // sample verify - $accessory = App\Models\Accessory::orderByDesc('created_at')->take(10)->get()->shuffle()->first(); - $I->seeResponseContainsJson($I->removeTimestamps((new AccessoriesTransformer)->transformAccessory($accessory))); - } - - /** @test */ - public function createAccessory(ApiTester $I, $scenario) - { - $I->wantTo('Create a new accessory'); - - $temp_accessory = \App\Models\Accessory::factory()->appleBtKeyboard()->make([ - 'name' => 'Test Accessory Name', - 'company_id' => 2, - ]); - - // setup - $data = [ - 'category_id' => $temp_accessory->category_id, - 'company_id' => $temp_accessory->company->id, - 'location_id' => $temp_accessory->location_id, - 'name' => $temp_accessory->name, - 'order_number' => $temp_accessory->order_number, - 'purchase_cost' => $temp_accessory->purchase_cost, - 'purchase_date' => $temp_accessory->purchase_date, - 'model_number' => $temp_accessory->model_number, - 'manufacturer_id' => $temp_accessory->manufacturer_id, - 'supplier_id' => $temp_accessory->supplier_id, - 'qty' => $temp_accessory->qty, - ]; - - // create - $I->sendPOST('/accessories', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateAccessoryWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an accessory with PATCH'); - - // create - $accessory = \App\Models\Accessory::factory()->appleBtKeyboard()->create([ - 'name' => 'Original Accessory Name', - 'company_id' => 2, - 'location_id' => 3, - ]); - $I->assertInstanceOf(\App\Models\Accessory::class, $accessory); - - $temp_accessory = \App\Models\Accessory::factory()->microsoftMouse()->make([ - 'company_id' => 3, - 'name' => 'updated accessory name', - 'location_id' => 1, - ]); - - $data = [ - 'category_id' => $temp_accessory->category_id, - 'company_id' => $temp_accessory->company->id, - 'location_id' => $temp_accessory->location_id, - 'name' => $temp_accessory->name, - 'order_number' => $temp_accessory->order_number, - 'purchase_cost' => $temp_accessory->purchase_cost, - 'purchase_date' => $temp_accessory->purchase_date, - 'model_number' => $temp_accessory->model_number, - 'manufacturer_id' => $temp_accessory->manufacturer_id, - 'supplier_id' => $temp_accessory->supplier_id, - 'image' => $temp_accessory->image, - 'qty' => $temp_accessory->qty, - ]; - - $I->assertNotEquals($accessory->name, $data['name']); - - // update - $I->sendPATCH('/accessories/'.$accessory->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/accessories/message.update.success'), $response->messages); - $I->assertEquals($accessory->id, $response->payload->id); // accessory id does not change - $I->assertEquals($temp_accessory->company_id, $response->payload->company_id); // company_id updated - $I->assertEquals($temp_accessory->name, $response->payload->name); // accessory name updated - $I->assertEquals($temp_accessory->location_id, $response->payload->location_id); // accessory location_id updated - $temp_accessory->created_at = Carbon::parse($response->payload->created_at); - $temp_accessory->updated_at = Carbon::parse($response->payload->updated_at); - $temp_accessory->id = $accessory->id; - // verify - $I->sendGET('/accessories/'.$accessory->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new AccessoriesTransformer)->transformAccessory($temp_accessory)); - } - - /** @test */ - public function deleteAccessoryTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an accessory'); - - // create - $accessory = \App\Models\Accessory::factory()->appleBtKeyboard()->create([ - 'name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\Accessory::class, $accessory); - - // delete - $I->sendDELETE('/accessories/'.$accessory->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/accessories/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/accessories/'.$accessory->id); - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } -} diff --git a/tests/api/ApiAssetsCest.php b/tests/api/ApiAssetsCest.php deleted file mode 100644 index 554d4c4230..0000000000 --- a/tests/api/ApiAssetsCest.php +++ /dev/null @@ -1,168 +0,0 @@ -faker = \Faker\Factory::create(); - $this->user = \App\Models\User::find(1); - Setting::getSettings()->time_display_format = 'H:i'; - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexAssets(ApiTester $I) - { - $I->wantTo('Get a list of assets'); - - // call - $I->sendGET('/hardware?limit=20&sort=id&order=desc'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - // FIXME: This is disabled because the statuslabel join is doing something weird in Api/AssetsController@index - // However, it's hiding other real test errors in other parts of the code, so disabling this for now until we can fix. -// $response = json_decode($I->grabResponse(), true); - - // sample verify -// $asset = Asset::orderByDesc('id')->take(20)->get()->first(); - - // -// $I->seeResponseContainsJson($I->removeTimestamps((new AssetsTransformer)->transformAsset($asset))); - } - - /** @test */ - public function createAsset(ApiTester $I, $scenario) - { - $I->wantTo('Create a new asset'); - - $temp_asset = \App\Models\Asset::factory()->laptopMbp()->make([ - 'asset_tag' => 'Test Asset Tag', - 'company_id' => 2, - ]); - - // setup - $data = [ - 'asset_tag' => $temp_asset->asset_tag, - 'assigned_to' => $temp_asset->assigned_to, - 'company_id' => $temp_asset->company->id, - 'image' => $temp_asset->image, - 'model_id' => $temp_asset->model_id, - 'name' => $temp_asset->name, - 'notes' => $temp_asset->notes, - 'purchase_cost' => $temp_asset->purchase_cost, - 'purchase_date' => $temp_asset->purchase_date, - 'rtd_location_id' => $temp_asset->rtd_location_id, - 'serial' => $temp_asset->serial, - 'status_id' => $temp_asset->status_id, - 'supplier_id' => $temp_asset->supplier_id, - 'warranty_months' => $temp_asset->warranty_months, - ]; - - // create - $I->sendPOST('/hardware', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - /** @test */ - public function updateAssetWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an asset with PATCH'); - - // create - $asset = \App\Models\Asset::factory()->laptopMbp()->create([ - 'company_id' => 2, - 'rtd_location_id' => 3, - ]); - $I->assertInstanceOf(\App\Models\Asset::class, $asset); - - $temp_asset = \App\Models\Asset::factory()->laptopAir()->make([ - 'company_id' => 3, - 'name' => 'updated asset name', - 'rtd_location_id' => 1, - ]); - - $data = [ - 'asset_tag' => $temp_asset->asset_tag, - 'assigned_to' => $temp_asset->assigned_to, - 'company_id' => $temp_asset->company->id, - 'image' => $temp_asset->image, - 'model_id' => $temp_asset->model_id, - 'name' => $temp_asset->name, - 'notes' => $temp_asset->notes, - 'order_number' => $temp_asset->order_number, - 'purchase_cost' => $temp_asset->purchase_cost, - 'purchase_date' => $temp_asset->purchase_date->format('Y-m-d'), - 'rtd_location_id' => $temp_asset->rtd_location_id, - 'serial' => $temp_asset->serial, - 'status_id' => $temp_asset->status_id, - 'supplier_id' => $temp_asset->supplier_id, - 'warranty_months' => $temp_asset->warranty_months, - ]; - - $I->assertNotEquals($asset->name, $data['name']); - - // update - $I->sendPATCH('/hardware/'.$asset->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - // dd($response); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/hardware/message.update.success'), $response->messages); - $I->assertEquals($asset->id, $response->payload->id); // asset id does not change - $I->assertEquals($temp_asset->asset_tag, $response->payload->asset_tag); // asset tag updated - $I->assertEquals($temp_asset->name, $response->payload->name); // asset name updated - $I->assertEquals($temp_asset->rtd_location_id, $response->payload->rtd_location_id); // asset rtd_location_id updated - $temp_asset->created_at = Carbon::parse($response->payload->created_at); - $temp_asset->updated_at = Carbon::parse($response->payload->updated_at); - $temp_asset->id = $asset->id; - $temp_asset->location_id = $response->payload->rtd_location_id; - - // verify - $I->sendGET('/hardware/'.$asset->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new AssetsTransformer)->transformAsset($temp_asset)); - } - - /** @test */ - public function deleteAssetTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an asset'); - - // create - $asset = \App\Models\Asset::factory()->laptopMbp()->create(); - $I->assertInstanceOf(\App\Models\Asset::class, $asset); - - // delete - $I->sendDELETE('/hardware/'.$asset->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/hardware/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/hardware/'.$asset->id); - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - - // Make sure we're soft deleted. - $response = json_decode($I->grabResponse()); - $I->assertNotNull($response->deleted_at); - } -} diff --git a/tests/api/ApiCategoriesCest.php b/tests/api/ApiCategoriesCest.php deleted file mode 100644 index 7605872a17..0000000000 --- a/tests/api/ApiCategoriesCest.php +++ /dev/null @@ -1,141 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexCategorys(ApiTester $I) - { - $I->wantTo('Get a list of categories'); - - // call - $I->sendGET('/categories?order_by=id&limit=10'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - // sample verify - $category = App\Models\Category::withCount('assets as assets_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count') - ->orderByDesc('created_at')->take(10)->get()->shuffle()->first(); - $I->seeResponseContainsJson($I->removeTimestamps((new CategoriesTransformer)->transformCategory($category))); - } - - /** @test */ - public function createCategory(ApiTester $I, $scenario) - { - $I->wantTo('Create a new category'); - - $temp_category = \App\Models\Category::factory()->assetLaptopCategory()->make([ - 'name' => 'Test Category Tag', - ]); - - // setup - $data = [ - 'category_type' => $temp_category->category_type, - 'checkin_email' => $temp_category->checkin_email, - 'eula_text' => $temp_category->eula_text, - 'name' => $temp_category->name, - 'require_acceptance' => $temp_category->require_acceptance, - 'use_default_eula' => $temp_category->use_default_eula, - ]; - - // create - $I->sendPOST('/categories', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateCategoryWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an category with PATCH'); - - // create - $category = \App\Models\Category::factory()->assetLaptopCategory() - ->create([ - 'name' => 'Original Category Name', - ]); - $I->assertInstanceOf(\App\Models\Category::class, $category); - - $temp_category = \App\Models\Category::factory()->accessoryMouseCategory()->make([ - 'name' => 'updated category name', - ]); - - $data = [ - 'category_type' => $temp_category->category_type, - 'checkin_email' => $temp_category->checkin_email, - 'eula_text' => $temp_category->eula_text, - 'name' => $temp_category->name, - 'require_acceptance' => $temp_category->require_acceptance, - 'use_default_eula' => $temp_category->use_default_eula, - ]; - - $I->assertNotEquals($category->name, $data['name']); - - // update - $I->sendPATCH('/categories/'.$category->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/categories/message.update.success'), $response->messages); - $I->assertEquals($category->id, $response->payload->id); // category id does not change - $I->assertEquals($temp_category->name, $response->payload->name); // category name updated - // Some manual copying to compare against - $temp_category->created_at = Carbon::parse($response->payload->created_at); - $temp_category->updated_at = Carbon::parse($response->payload->updated_at); - $temp_category->id = $category->id; - - // verify - $I->sendGET('/categories/'.$category->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new CategoriesTransformer)->transformCategory($temp_category)); - } - - /** @test */ - public function deleteCategoryTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an category'); - - // create - $category = \App\Models\Category::factory()->assetLaptopCategory()->create([ - 'name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\Category::class, $category); - - // delete - $I->sendDELETE('/categories/'.$category->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/categories/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/categories/'.$category->id); - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } -} diff --git a/tests/api/ApiCheckoutAssetsCest.php b/tests/api/ApiCheckoutAssetsCest.php deleted file mode 100644 index 48b4bd2335..0000000000 --- a/tests/api/ApiCheckoutAssetsCest.php +++ /dev/null @@ -1,147 +0,0 @@ -user = \App\Models\User::find(1); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function checkoutAssetToUser(ApiTester $I) - { - $I->wantTo('Check out an asset to a user'); - //Grab an asset from the database that isn't checked out. - $asset = Asset::whereNull('assigned_to')->first(); - $targetUser = \App\Models\User::factory()->create(); - $data = [ - 'assigned_user' => $targetUser->id, - 'note' => 'This is a test checkout note', - 'expected_checkin' => '2018-05-24', - 'name' => 'Updated Asset Name', - 'checkout_to_type' => 'user', - ]; - $I->sendPOST("/hardware/{$asset->id}/checkout", $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/hardware/message.checkout.success'), $response->messages); - - // Confirm results. - $I->sendGET("/hardware/{$asset->id}"); - $I->seeResponseContainsJson([ - 'assigned_to' => [ - 'id' => $targetUser->id, - 'type' => 'user', - ], - 'name' => 'Updated Asset Name', - 'expected_checkin' => Helper::getFormattedDateObject('2018-05-24', 'date'), - ]); - } - - /** @test */ - public function checkoutAssetToAsset(ApiTester $I) - { - $I->wantTo('Check out an asset to an asset'); - //Grab an asset from the database that isn't checked out. - $asset = Asset::whereNull('assigned_to') - ->where('model_id', 8) - ->where('status_id', Statuslabel::deployable()->first()->id) - ->first(); // We need to make sure that this is an asset/model that doesn't require acceptance - $targetAsset = \App\Models\Asset::factory()->desktopMacpro()->create([ - 'name' => 'Test Asset For Checkout to', - ]); - $data = [ - 'assigned_asset' => $targetAsset->id, - 'checkout_to_type' => 'asset', - ]; - $I->sendPOST("/hardware/{$asset->id}/checkout", $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/hardware/message.checkout.success'), $response->messages); - - // Confirm results. - $I->sendGET("/hardware/{$asset->id}"); - $I->seeResponseContainsJson([ - 'assigned_to' => [ - 'id' => $targetAsset->id, - 'type' => 'asset', - ], - ]); - } - - /** @test */ - public function checkoutAssetToLocation(ApiTester $I) - { - $I->wantTo('Check out an asset to an asset'); - //Grab an asset from the database that isn't checked out. - $asset = Asset::whereNull('assigned_to') - ->where('model_id', 8) - ->where('status_id', Statuslabel::deployable()->first()->id) - ->first(); // We need to make sure that this is an asset/model that doesn't require acceptance - $targetLocation = \App\Models\Location::factory()->create([ - 'name' => 'Test Location for Checkout', - ]); - $data = [ - 'assigned_location' => $targetLocation->id, - 'checkout_to_type' => 'location', - ]; - $I->sendPOST("/hardware/{$asset->id}/checkout", $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/hardware/message.checkout.success'), $response->messages); - - // Confirm results. - $I->sendGET("/hardware/{$asset->id}"); - $I->seeResponseContainsJson([ - 'assigned_to' => [ - 'id' => $targetLocation->id, - 'type' => 'location', - ], - ]); - } - - /** @test */ - public function checkinAsset(ApiTester $I) - { - $I->wantTo('Checkin an asset that is currently checked out'); - - $asset = Asset::whereNotNull('assigned_to')->first(); - - $I->sendPOST("/hardware/{$asset->id}/checkin", [ - 'note' => 'Checkin Note', - ]); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/hardware/message.checkin.success'), $response->messages); - - // Verify - $I->sendGET("/hardware/{$asset->id}"); - $I->seeResponseContainsJson([ - 'assigned_to' => null, - ]); - } -} diff --git a/tests/api/ApiCompaniesCest.php b/tests/api/ApiCompaniesCest.php deleted file mode 100644 index 55fa5bc218..0000000000 --- a/tests/api/ApiCompaniesCest.php +++ /dev/null @@ -1,132 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexCompanys(ApiTester $I) - { - $I->wantTo('Get a list of companies'); - - // call - $I->sendGET('/companies?order_by=id&limit=10'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - // dd($response); - // sample verify - $company = App\Models\Company::withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'users as users_count') - ->orderByDesc('created_at')->take(10)->get()->shuffle()->first(); - - $I->seeResponseContainsJson($I->removeTimestamps((new CompaniesTransformer)->transformCompany($company))); - } - - /** @test */ - public function createCompany(ApiTester $I, $scenario) - { - $I->wantTo('Create a new company'); - - $temp_company = \App\Models\Company::factory()->make([ - 'name' => 'Test Company Tag', - ]); - - // setup - $data = [ - 'name' => $temp_company->name, - ]; - - // create - $I->sendPOST('/companies', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateCompanyWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an company with PATCH'); - - // create - $company = \App\Models\Company::factory()->create([ - 'name' => 'Original Company Name', - ]); - $I->assertInstanceOf(\App\Models\Company::class, $company); - - $temp_company = \App\Models\Company::factory()->make([ - 'name' => 'updated company name', - ]); - - $data = [ - 'name' => $temp_company->name, - ]; - - $I->assertNotEquals($company->name, $data['name']); - - // update - $I->sendPATCH('/companies/'.$company->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/companies/message.update.success'), $response->messages); - $I->assertEquals($company->id, $response->payload->id); // company id does not change - $I->assertEquals($temp_company->name, $response->payload->name); // company name updated - // Some manual copying to compare against - $temp_company->created_at = Carbon::parse($response->payload->created_at->datetime); - $temp_company->updated_at = Carbon::parse($response->payload->updated_at->datetime); - $temp_company->id = $company->id; - - // verify - $I->sendGET('/companies/'.$company->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new CompaniesTransformer)->transformCompany($temp_company)); - } - - /** @test */ - public function deleteCompanyTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an company'); - - // create - $company = \App\Models\Company::factory()->create([ - 'name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\Company::class, $company); - - // delete - $I->sendDELETE('/companies/'.$company->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/companies/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/companies/'.$company->id); - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } -} diff --git a/tests/api/ApiComponentsAssetsCest.php b/tests/api/ApiComponentsAssetsCest.php deleted file mode 100644 index c7e2e043b9..0000000000 --- a/tests/api/ApiComponentsAssetsCest.php +++ /dev/null @@ -1,80 +0,0 @@ -faker = \Faker\Factory::create(); - // $this->user = \App\Models\User::find(1); - - // $I->amBearerAuthenticated($I->getToken($this->user)); - // } - - // // /** @test */ - // // public function indexComponentsAssets(ApiTester $I) - // // { - // // $I->wantTo('Get a list of assets related to a component'); - - // // // generate component - // // $component = factory(\App\Models\Component::class) - // // ->create(['user_id' => $this->user->id, 'qty' => 20]); - - // // // generate assets and associate component - // // $assets = factory(\App\Models\Asset::class, 2) - // // ->create(['user_id' => $this->user->id]) - // // ->each(function ($asset) use ($component) { - // // $component->assets()->attach($component->id, [ - // // 'component_id' => $component->id, - // // 'user_id' => $this->user->id, - // // 'created_at' => date('Y-m-d H:i:s'), - // // 'assigned_qty' => 2, - // // 'asset_id' => $asset->id - // // ]); - // // }); - - // // // verify - // // $I->sendGET('/components/' . $component->id . '/assets/'); - // // $I->seeResponseIsJson(); - // // $I->seeResponseCodeIs(200); - - // // $response = json_decode($I->grabResponse()); - // // $I->assertEquals(2, $response->total); - - // // $I->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $assets); - - // // $I->seeResponseContainsJson(['rows' => [ - // // 0 => [ - // // 'name' => $assets[0]->name, - // // 'id' => $assets[0]->id, - // // 'created_at' => $assets[0]->created_at->format('Y-m-d'), - // // ], - // // 1 => [ - // // 'name' => $assets[1]->name, - // // 'id' => $assets[1]->id, - // // 'created_at' => $assets[1]->created_at->format('Y-m-d'), - // // ], - // // ] - // // ]); - // // } - - // // /** @test */ - // // public function expectEmptyResponseWithoutAssociatedAssets(ApiTester $I, $scenario) - // // { - // // $I->wantTo('See an empty response when there are no associated assets to a component'); - - // // $component = factory(\App\Models\Component::class) - // // ->create(['user_id' => $this->user->id, 'qty' => 20]); - - // // $I->sendGET('/components/' . $component->id . '/assets'); - // // $I->seeResponseCodeIs(200); - // // $I->seeResponseIsJson(); - - // // $response = json_decode($I->grabResponse()); - // // $I->assertEquals(0, $response->total); - // // $I->assertEquals([], $response->rows); - // // $I->seeResponseContainsJson(['total' => 0, 'rows' => []]); - // // } -} diff --git a/tests/api/ApiComponentsCest.php b/tests/api/ApiComponentsCest.php deleted file mode 100644 index dea9ece186..0000000000 --- a/tests/api/ApiComponentsCest.php +++ /dev/null @@ -1,156 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexComponents(ApiTester $I) - { - $I->wantTo('Get a list of components'); - - // call - $I->sendGET('/components?limit=10'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - // sample verify - $component = App\Models\Component::orderByDesc('created_at')->take(10)->get()->shuffle()->first(); - - $I->seeResponseContainsJson($I->removeTimestamps((new ComponentsTransformer)->transformComponent($component))); - } - - /** @test */ - public function createComponent(ApiTester $I, $scenario) - { - $I->wantTo('Create a new component'); - - $temp_component = \App\Models\Component::factory()->ramCrucial4()->make([ - 'name' => 'Test Component Name', - 'company_id' => 2, - ]); - - // setup - $data = [ - 'category_id' => $temp_component->category_id, - 'company_id' => $temp_component->company->id, - 'location_id' => $temp_component->location_id, - 'manufacturer_id' => $temp_component->manufacturer_id, - 'model_number' => $temp_component->model_number, - 'name' => $temp_component->name, - 'order_number' => $temp_component->order_number, - 'purchase_cost' => $temp_component->purchase_cost, - 'purchase_date' => $temp_component->purchase_date, - 'qty' => $temp_component->qty, - 'serial' => $temp_component->serial, - ]; - - // create - $I->sendPOST('/components', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateComponentWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an component with PATCH'); - - // create - $component = \App\Models\Component::factory()->ramCrucial4()->create([ - 'name' => 'Original Component Name', - 'company_id' => 2, - 'location_id' => 3, - ]); - $I->assertInstanceOf(\App\Models\Component::class, $component); - - $temp_component = \App\Models\Component::factory()->ssdCrucial240()->make([ - 'company_id' => 3, - 'name' => 'updated component name', - 'location_id' => 1, - ]); - - $data = [ - 'category_id' => $temp_component->category_id, - 'company_id' => $temp_component->company->id, - 'location_id' => $temp_component->location_id, - 'min_amt' => $temp_component->min_amt, - 'name' => $temp_component->name, - 'order_number' => $temp_component->order_number, - 'purchase_cost' => $temp_component->purchase_cost, - 'purchase_date' => $temp_component->purchase_date, - 'qty' => $temp_component->qty, - 'serial' => $temp_component->serial, - ]; - - $I->assertNotEquals($component->name, $data['name']); - - // update - $I->sendPATCH('/components/'.$component->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/components/message.update.success'), $response->messages); - $I->assertEquals($component->id, $response->payload->id); // component id does not change - $I->assertEquals($temp_component->company_id, $response->payload->company_id); // company_id updated - $I->assertEquals($temp_component->name, $response->payload->name); // component name updated - $I->assertEquals($temp_component->location_id, $response->payload->location_id); // component location_id updated - $temp_component->created_at = Carbon::parse($response->payload->created_at); - $temp_component->updated_at = Carbon::parse($response->payload->updated_at); - $temp_component->id = $component->id; - // verify - $I->sendGET('/components/'.$component->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new ComponentsTransformer)->transformComponent($temp_component)); - } - - /** @test */ - public function deleteComponentTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an component'); - - // create - $component = \App\Models\Component::factory()->ramCrucial4()->create([ - 'name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\Component::class, $component); - - // delete - $I->sendDELETE('/components/'.$component->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - // dd($response); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/components/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/components/'.$component->id); - - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } -} diff --git a/tests/api/ApiConsumablesCest.php b/tests/api/ApiConsumablesCest.php deleted file mode 100644 index 8490c3a56e..0000000000 --- a/tests/api/ApiConsumablesCest.php +++ /dev/null @@ -1,155 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexConsumables(ApiTester $I) - { - $I->wantTo('Get a list of consumables'); - - // call - $I->sendGET('/consumables?limit=10'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - // sample verify - $consumable = App\Models\Consumable::orderByDesc('created_at')->take(10)->get()->shuffle()->first(); - - $I->seeResponseContainsJson($I->removeTimestamps((new ConsumablesTransformer)->transformConsumable($consumable))); - } - - /** @test */ - public function createConsumable(ApiTester $I, $scenario) - { - $I->wantTo('Create a new consumable'); - - $temp_consumable = \App\Models\Consumable::factory()->ink()->make([ - 'name' => 'Test Consumable Name', - 'company_id' => 2, - ]); - - // setup - $data = [ - 'category_id' => $temp_consumable->category_id, - 'company_id' => $temp_consumable->company->id, - 'location_id' => $temp_consumable->location_id, - 'manufacturer_id' => $temp_consumable->manufacturer_id, - 'name' => $temp_consumable->name, - 'order_number' => $temp_consumable->order_number, - 'purchase_cost' => $temp_consumable->purchase_cost, - 'purchase_date' => $temp_consumable->purchase_date, - 'qty' => $temp_consumable->qty, - 'model_number' => $temp_consumable->model_number, - ]; - - // create - $I->sendPOST('/consumables', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateConsumableWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an consumable with PATCH'); - - // create - $consumable = \App\Models\Consumable::factory()->ink()->create([ - 'name' => 'Original Consumable Name', - 'company_id' => 2, - 'location_id' => 3, - ]); - $I->assertInstanceOf(\App\Models\Consumable::class, $consumable); - - $temp_consumable = \App\Models\Consumable::factory()->cardstock()->make([ - 'company_id' => 3, - 'name' => 'updated consumable name', - 'location_id' => 1, - ]); - - $data = [ - 'category_id' => $temp_consumable->category_id, - 'company_id' => $temp_consumable->company->id, - 'item_no' => $temp_consumable->item_no, - 'location_id' => $temp_consumable->location_id, - 'name' => $temp_consumable->name, - 'order_number' => $temp_consumable->order_number, - 'purchase_cost' => $temp_consumable->purchase_cost, - 'purchase_date' => $temp_consumable->purchase_date, - 'model_number' => $temp_consumable->model_number, - 'manufacturer_id' => $temp_consumable->manufacturer_id, - 'supplier_id' => $temp_consumable->supplier_id, - 'qty' => $temp_consumable->qty, - ]; - - $I->assertNotEquals($consumable->name, $data['name']); - - // update - $I->sendPATCH('/consumables/'.$consumable->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/consumables/message.update.success'), $response->messages); - $I->assertEquals($consumable->id, $response->payload->id); // consumable id does not change - $I->assertEquals($temp_consumable->company_id, $response->payload->company_id); // company_id updated - $I->assertEquals($temp_consumable->name, $response->payload->name); // consumable name updated - $I->assertEquals($temp_consumable->location_id, $response->payload->location_id); // consumable location_id updated - $temp_consumable->created_at = Carbon::parse($response->payload->created_at); - $temp_consumable->updated_at = Carbon::parse($response->payload->updated_at); - $temp_consumable->id = $consumable->id; - // verify - $I->sendGET('/consumables/'.$consumable->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new ConsumablesTransformer)->transformConsumable($temp_consumable)); - } - - /** @test */ - public function deleteConsumableTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an consumable'); - - // create - $consumable = \App\Models\Consumable::factory()->ink()->create([ - 'name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\Consumable::class, $consumable); - - // delete - $I->sendDELETE('/consumables/'.$consumable->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/consumables/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/consumables/'.$consumable->id); - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } -} diff --git a/tests/api/ApiLicenseSeatsCest.php b/tests/api/ApiLicenseSeatsCest.php deleted file mode 100644 index 664915bb4c..0000000000 --- a/tests/api/ApiLicenseSeatsCest.php +++ /dev/null @@ -1,185 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexLicenseSeats(ApiTester $I) - { - $I->wantTo('Get a list of license seats for a specific license'); - - // call - $I->sendGET('/licenses/1/seats?limit=10&order=desc'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - // sample verify - $licenseSeats = App\Models\LicenseSeat::where('license_id', 1) - ->orderBy('id', 'desc')->take(10)->get(); - // pick a random seat - $licenseSeat = $licenseSeats->random(); - // need the index in the original list so that the "name" field is determined correctly - $licenseSeatNumber = 0; - foreach ($licenseSeats as $index=>$seat) { - if ($licenseSeat === $seat) { - $licenseSeatNumber = $index + 1; - } - } - $I->seeResponseContainsJson($I->removeTimestamps((new LicenseSeatsTransformer)->transformLicenseSeat($licenseSeat, $licenseSeatNumber))); - } - - /** @test */ - public function showLicenseSeat(ApiTester $I) - { - $I->wantTo('Get a license seat'); - - // call - $I->sendGET('/licenses/1/seats/10'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - // sample verify - $licenseSeat = App\Models\LicenseSeat::findOrFail(10); - $I->seeResponseContainsJson($I->removeTimestamps((new LicenseSeatsTransformer)->transformLicenseSeat($licenseSeat))); - } - - /** @test */ - public function checkoutLicenseSeatToUser(ApiTester $I) - { - $I->wantTo('Checkout a license seat to a user'); - - $user = App\Models\User::all()->random(); - $licenseSeat = App\Models\LicenseSeat::all()->random(); - $endpoint = '/licenses/'.$licenseSeat->license_id.'/seats/'.$licenseSeat->id; - - $data = [ - 'assigned_to' => $user->id, - 'note' => 'Test Checkout to User via API', - ]; - - // update - $I->sendPATCH($endpoint, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/licenses/message.update.success'), $response->messages); - $I->assertEquals($licenseSeat->license_id, $response->payload->license_id); // license id does not change - $I->assertEquals($licenseSeat->id, $response->payload->id); // license seat id does not change - - // verify - $licenseSeat = $licenseSeat->fresh(); - $I->sendGET($endpoint); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson($I->removeTimestamps((new LicenseSeatsTransformer)->transformLicenseSeat($licenseSeat))); - - // verify that the last logged action is a checkout - $I->sendGET('/reports/activity?item_type=license&limit=1&item_id='.$licenseSeat->license_id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson([ - 'action_type' => 'checkout', - ]); - } - - /** @test */ - public function checkoutLicenseSeatToAsset(ApiTester $I) - { - $I->wantTo('Checkout a license seat to an asset'); - - $asset = App\Models\Asset::all()->random(); - $licenseSeat = App\Models\LicenseSeat::all()->random(); - $endpoint = '/licenses/'.$licenseSeat->license_id.'/seats/'.$licenseSeat->id; - - $data = [ - 'asset_id' => $asset->id, - 'note' => 'Test Checkout to Asset via API', - ]; - - // update - $I->sendPATCH($endpoint, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/licenses/message.update.success'), $response->messages); - $I->assertEquals($licenseSeat->license_id, $response->payload->license_id); // license id does not change - $I->assertEquals($licenseSeat->id, $response->payload->id); // license seat id does not change - - // verify - $licenseSeat = $licenseSeat->fresh(); - $I->sendGET($endpoint); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson($I->removeTimestamps((new LicenseSeatsTransformer)->transformLicenseSeat($licenseSeat))); - - // verify that the last logged action is a checkout - $I->sendGET('/reports/activity?item_type=license&limit=1&item_id='.$licenseSeat->license_id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson([ - 'action_type' => 'checkout', - ]); - } - - /** @test */ - public function checkoutLicenseSeatToUserAndAsset(ApiTester $I) - { - $I->wantTo('Checkout a license seat to a user AND an asset'); - - $asset = App\Models\Asset::all()->random(); - $user = App\Models\User::all()->random(); - $licenseSeat = App\Models\LicenseSeat::all()->random(); - $endpoint = '/licenses/'.$licenseSeat->license_id.'/seats/'.$licenseSeat->id; - - $data = [ - 'asset_id' => $asset->id, - 'assigned_to' => $user->id, - 'note' => 'Test Checkout to User and Asset via API', - ]; - - // update - $I->sendPATCH($endpoint, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/licenses/message.update.success'), $response->messages); - $I->assertEquals($licenseSeat->license_id, $response->payload->license_id); // license id does not change - $I->assertEquals($licenseSeat->id, $response->payload->id); // license seat id does not change - - // verify - $licenseSeat = $licenseSeat->fresh(); - $I->sendGET($endpoint); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson($I->removeTimestamps((new LicenseSeatsTransformer)->transformLicenseSeat($licenseSeat))); - - // verify that the last logged action is a checkout - $I->sendGET('/reports/activity?item_type=license&limit=1&item_id='.$licenseSeat->license_id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson([ - 'action_type' => 'checkout', - ]); - } -} diff --git a/tests/api/ApiLicensesCest.php b/tests/api/ApiLicensesCest.php deleted file mode 100644 index 0668e87628..0000000000 --- a/tests/api/ApiLicensesCest.php +++ /dev/null @@ -1,194 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexLicenses(ApiTester $I) - { - $I->wantTo('Get a list of licenses'); - - // call - $I->sendGET('/licenses?limit=10&sort=created_at'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - // sample verify - $license = App\Models\License::orderByDesc('created_at') - ->withCount('freeSeats as free_seats_count') - ->take(10)->get()->shuffle()->first(); - $I->seeResponseContainsJson($I->removeTimestamps((new LicensesTransformer)->transformLicense($license))); - } - - /** @test */ - public function createLicense(ApiTester $I, $scenario) - { - $I->wantTo('Create a new license'); - - $temp_license = \App\Models\License::factory()->acrobat()->make([ - 'name' => 'Test License Name', - 'depreciation_id' => 3, - 'company_id' => 2, - ]); - - // setup - $data = [ - 'company_id' => $temp_license->company_id, - 'depreciation_id' => $temp_license->depreciation_id, - 'expiration_date' => $temp_license->expiration_date, - 'license_email' => $temp_license->license_email, - 'license_name' => $temp_license->license_name, - 'maintained' => $temp_license->maintained, - 'manufacturer_id' => $temp_license->manufacturer_id, - 'name' => $temp_license->name, - 'notes' => $temp_license->notes, - 'order_number' => $temp_license->order_number, - 'purchase_cost' => $temp_license->purchase_cost, - 'purchase_date' => $temp_license->purchase_date, - 'purchase_order' => $temp_license->purchase_order, - 'reassignable' => $temp_license->reassignable, - 'seats' => $temp_license->seats, - 'serial' => $temp_license->serial, - 'supplier_id' => $temp_license->supplier_id, - 'termination_date' => $temp_license->termination_date, - ]; - - // create - $I->sendPOST('/licenses', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateLicenseWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update a license with PATCH'); - - // create - $license = \App\Models\License::factory()->acrobat()->create([ - 'name' => 'Original License Name', - 'depreciation_id' => 3, - 'company_id' => 2, - ]); - $I->assertInstanceOf(\App\Models\License::class, $license); - - $temp_license = \App\Models\License::factory()->office()->make([ - 'company_id' => 3, - 'depreciation_id' => 2, - ]); - - $data = [ - 'company_id' => $temp_license->company_id, - 'depreciation_id' => $temp_license->depreciation_id, - 'expiration_date' => $temp_license->expiration_date, - 'license_email' => $temp_license->license_email, - 'license_name' => $temp_license->license_name, - 'maintained' => $temp_license->maintained, - 'manufacturer_id' => $temp_license->manufacturer_id, - 'name' => $temp_license->name, - 'notes' => $temp_license->notes, - 'order_number' => $temp_license->order_number, - 'purchase_cost' => $temp_license->purchase_cost, - 'purchase_date' => $temp_license->purchase_date, - 'purchase_order' => $temp_license->purchase_order, - 'reassignable' => $temp_license->reassignable, - 'seats' => $temp_license->seats, - 'serial' => $temp_license->serial, - 'supplier_id' => $temp_license->supplier_id, - 'category_id' => $temp_license->category_id, - 'termination_date' => $temp_license->termination_date, - ]; - // We aren't checking anyhting out in this test, so this fakes the withCount() that happens on a normal db fetch. - $temp_license->free_seats_count = $temp_license->seats; - $I->assertNotEquals($license->name, $data['name']); - - // update - $I->sendPATCH('/licenses/'.$license->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/licenses/message.update.success'), $response->messages); - $I->assertEquals($license->id, $response->payload->id); // license id does not change - $I->assertEquals($temp_license->name, $response->payload->name); // license name - $temp_license->created_at = Carbon::parse($response->payload->created_at); - $temp_license->updated_at = Carbon::parse($response->payload->updated_at); - $temp_license->id = $license->id; - // verify - $I->sendGET('/licenses/'.$license->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new LicensesTransformer)->transformLicense($temp_license)); - } - - /** @test */ - public function deleteLicenseWithUsersTest(ApiTester $I, $scenario) - { - $I->wantTo('Ensure a license with seats checked out cannot be deleted'); - - // create - $license = \App\Models\License::factory()->acrobat()->create([ - 'name' => 'Soon to be deleted', - ]); - $licenseSeat = $license->freeSeat(); - $licenseSeat->assigned_to = $this->user->id; - $licenseSeat->save(); - $I->assertInstanceOf(\App\Models\License::class, $license); - - // delete - $I->sendDELETE('/licenses/'.$license->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('error', $response->status); - $I->assertEquals(trans('admin/licenses/message.assoc_users'), $response->messages); - } - - /** @test */ - public function deleteLicenseTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an license'); - - // create - $license = \App\Models\License::factory()->acrobat()->create([ - 'name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\License::class, $license); - - // delete - $I->sendDELETE('/licenses/'.$license->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/licenses/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/licenses/'.$license->id); - - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } -} diff --git a/tests/api/ApiLocationsCest.php b/tests/api/ApiLocationsCest.php deleted file mode 100644 index 536830f00d..0000000000 --- a/tests/api/ApiLocationsCest.php +++ /dev/null @@ -1,154 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexLocations(ApiTester $I) - { - $I->wantTo('Get a list of locations'); - - // call - $I->sendGET('/locations?limit=10'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - // sample verify - $location = App\Models\Location::orderByDesc('created_at') - ->withCount('assignedAssets as assigned_assets_count', 'assets as assets_count', 'users as users_count') - ->take(10)->get()->shuffle()->first(); - $I->seeResponseContainsJson($I->removeTimestamps((new LocationsTransformer)->transformLocation($location))); - } - - /** @test */ - public function createLocation(ApiTester $I, $scenario) - { - $I->wantTo('Create a new location'); - - $temp_location = \App\Models\Location::factory()->make([ - 'name' => 'Test Location Tag', - ]); - - // setup - $data = [ - 'name' => $temp_location->name, - 'image' => $temp_location->image, - 'address' => $temp_location->address, - 'address2' => $temp_location->address2, - 'city' => $temp_location->city, - 'state' => $temp_location->state, - 'country' => $temp_location->country, - 'zip' => $temp_location->zip, - 'parent_id' => $temp_location->parent_id, - 'parent_id' => $temp_location->parent_id, - 'manager_id' => $temp_location->manager_id, - 'currency' => $temp_location->currency, - ]; - - // create - $I->sendPOST('/locations', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateLocationWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an location with PATCH'); - - // create - $location = \App\Models\Location::factory()->create([ - 'name' => 'Original Location Name', - ]); - $I->assertInstanceOf(\App\Models\Location::class, $location); - - $temp_location = \App\Models\Location::factory()->make([ - 'name' => 'updated location name', - ]); - - $data = [ - 'name' => $temp_location->name, - 'image' => $temp_location->image, - 'address' => $temp_location->address, - 'address2' => $temp_location->address2, - 'city' => $temp_location->city, - 'state' => $temp_location->state, - 'country' => $temp_location->country, - 'zip' => $temp_location->zip, - 'parent_id' => $temp_location->parent_id, - 'parent_id' => $temp_location->parent_id, - 'manager_id' => $temp_location->manager_id, - 'currency' => $temp_location->currency, - ]; - - $I->assertNotEquals($location->name, $data['name']); - - // update - $I->sendPATCH('/locations/'.$location->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/locations/message.update.success'), $response->messages); - $I->assertEquals($location->id, $response->payload->id); // location id does not change - $I->assertEquals($temp_location->name, $response->payload->name); // location name updated - - // Some necessary manual copying - $temp_location->created_at = Carbon::parse($response->payload->created_at->datetime); - $temp_location->updated_at = Carbon::parse($response->payload->updated_at->datetime); - $temp_location->id = $location->id; - - // verify - $I->sendGET('/locations/'.$location->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new LocationsTransformer)->transformLocation($temp_location)); - } - - /** @test */ - public function deleteLocationTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an location'); - - // create - $location = \App\Models\Location::factory()->create([ - 'name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\Location::class, $location); - - // delete - $I->sendDELETE('/locations/'.$location->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/locations/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/locations/'.$location->id); - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } -} diff --git a/tests/api/ApiManufacturersCest.php b/tests/api/ApiManufacturersCest.php deleted file mode 100644 index be2f4cc483..0000000000 --- a/tests/api/ApiManufacturersCest.php +++ /dev/null @@ -1,142 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexManufacturers(ApiTester $I) - { - $I->wantTo('Get a list of manufacturers'); - - // call - $I->sendGET('/manufacturers?order_by=id&limit=10'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - // sample verify - $manufacturer = App\Models\Manufacturer::withCount('assets as assets_count', 'accessories as accessories_count', 'consumables as consumables_count', 'licenses as licenses_count') - ->orderByDesc('created_at')->take(10)->get()->shuffle()->first(); - - $I->seeResponseContainsJson($I->removeTimestamps((new ManufacturersTransformer)->transformManufacturer($manufacturer))); - } - - /** @test */ - public function createManufacturer(ApiTester $I, $scenario) - { - $I->wantTo('Create a new manufacturer'); - - $temp_manufacturer = \App\Models\Manufacturer::factory()->apple()->make([ - 'name' => 'Test Manufacturer Tag', - ]); - - // setup - $data = [ - 'image' => $temp_manufacturer->image, - 'name' => $temp_manufacturer->name, - 'support_email' => $temp_manufacturer->support_email, - 'support_phone' => $temp_manufacturer->support_phone, - 'support_url' => $temp_manufacturer->support_url, - 'url' => $temp_manufacturer->url, - ]; - - // create - $I->sendPOST('/manufacturers', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateManufacturerWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an manufacturer with PATCH'); - - // create - $manufacturer = \App\Models\Manufacturer::factory()->apple() - ->create([ - 'name' => 'Original Manufacturer Name', - ]); - $I->assertInstanceOf(\App\Models\Manufacturer::class, $manufacturer); - - $temp_manufacturer = \App\Models\Manufacturer::factory()->dell()->make([ - 'name' => 'updated manufacturer name', - ]); - - $data = [ - 'image' => $temp_manufacturer->image, - 'name' => $temp_manufacturer->name, - 'support_email' => $temp_manufacturer->support_email, - 'support_phone' => $temp_manufacturer->support_phone, - 'support_url' => $temp_manufacturer->support_url, - 'url' => $temp_manufacturer->url, - ]; - - $I->assertNotEquals($manufacturer->name, $data['name']); - - // update - $I->sendPATCH('/manufacturers/'.$manufacturer->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/manufacturers/message.update.success'), $response->messages); - $I->assertEquals($manufacturer->id, $response->payload->id); // manufacturer id does not change - $I->assertEquals($temp_manufacturer->name, $response->payload->name); // manufacturer name updated - // Some manual copying to compare against - $temp_manufacturer->created_at = Carbon::parse($response->payload->created_at); - $temp_manufacturer->updated_at = Carbon::parse($response->payload->updated_at); - $temp_manufacturer->id = $manufacturer->id; - - // verify - $I->sendGET('/manufacturers/'.$manufacturer->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new ManufacturersTransformer)->transformManufacturer($temp_manufacturer)); - } - - /** @test */ - public function deleteManufacturerTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an manufacturer'); - - // create - $manufacturer = \App\Models\Manufacturer::factory()->apple()->create([ - 'name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\Manufacturer::class, $manufacturer); - - // delete - $I->sendDELETE('/manufacturers/'.$manufacturer->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/manufacturers/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/manufacturers/'.$manufacturer->id); - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } -} diff --git a/tests/api/ApiModelsCest.php b/tests/api/ApiModelsCest.php deleted file mode 100644 index 1d3d6fc788..0000000000 --- a/tests/api/ApiModelsCest.php +++ /dev/null @@ -1,145 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexAssetModels(ApiTester $I) - { - $I->wantTo('Get a list of assetmodels'); - - // call - $I->sendGET('/models?limit=10'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - $assetmodel = App\Models\AssetModel::orderByDesc('created_at') - ->withCount('assets as assets_count')->take(10)->get()->shuffle()->first(); - $I->seeResponseContainsJson($I->removeTimestamps((new AssetModelsTransformer)->transformAssetModel($assetmodel))); - } - - /** @test */ - public function createAssetModel(ApiTester $I, $scenario) - { - $I->wantTo('Create a new assetmodel'); - - $temp_assetmodel = \App\Models\AssetModel::factory()->mbp13Model()->make([ - 'name' => 'Test AssetModel Tag', - ]); - - // setup - $data = [ - 'category_id' => $temp_assetmodel->category_id, - 'depreciation_id' => $temp_assetmodel->depreciation_id, - 'eol' => $temp_assetmodel->eol, - 'image' => $temp_assetmodel->image, - 'manufacturer_id' => $temp_assetmodel->manufacturer_id, - 'model_number' => $temp_assetmodel->model_number, - 'name' => $temp_assetmodel->name, - 'notes' => $temp_assetmodel->notes, - ]; - - // create - $I->sendPOST('/models', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateAssetModelWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an assetmodel with PATCH'); - - // create - $assetmodel = \App\Models\AssetModel::factory()->mbp13Model()->create([ - 'name' => 'Original AssetModel Name', - ]); - $I->assertInstanceOf(\App\Models\AssetModel::class, $assetmodel); - - $temp_assetmodel = \App\Models\AssetModel::factory()->polycomcxModel()->make([ - 'name' => 'updated AssetModel name', - 'fieldset_id' => 2, - ]); - - $data = [ - 'category_id' => $temp_assetmodel->category_id, - 'depreciation_id' => $temp_assetmodel->depreciation_id, - 'eol' => $temp_assetmodel->eol, - 'image' => $temp_assetmodel->image, - 'manufacturer_id' => $temp_assetmodel->manufacturer_id, - 'model_number' => $temp_assetmodel->model_number, - 'name' => $temp_assetmodel->name, - 'notes' => $temp_assetmodel->notes, - 'fieldset' => $temp_assetmodel->fieldset->id, - ]; - - $I->assertNotEquals($assetmodel->name, $data['name']); - - // update - $I->sendPATCH('/models/'.$assetmodel->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/models/message.update.success'), $response->messages); - $I->assertEquals($assetmodel->id, $response->payload->id); // assetmodel id does not change - $I->assertEquals($temp_assetmodel->name, $response->payload->name); // assetmodel name updated - - // Some necessary manual copying - $temp_assetmodel->created_at = Carbon::parse($response->payload->created_at); - $temp_assetmodel->updated_at = Carbon::parse($response->payload->updated_at); - $temp_assetmodel->id = $assetmodel->id; - // verify - $I->sendGET('/models/'.$assetmodel->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new AssetModelsTransformer)->transformAssetModel($temp_assetmodel)); - } - - /** @test */ - public function deleteAssetModelTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an assetmodel'); - - // create - $assetmodel = \App\Models\AssetModel::factory()->mbp13Model()->create([ - 'name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\AssetModel::class, $assetmodel); - - // delete - $I->sendDELETE('/models/'.$assetmodel->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/models/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/models/'.$assetmodel->id); - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } -} diff --git a/tests/api/ApiStatusLabelsCest.php b/tests/api/ApiStatusLabelsCest.php deleted file mode 100644 index fabb71d51f..0000000000 --- a/tests/api/ApiStatusLabelsCest.php +++ /dev/null @@ -1,142 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexStatuslabels(ApiTester $I) - { - $I->wantTo('Get a list of statuslabels'); - - // call - $I->sendGET('/statuslabels?limit=10'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - // sample verify - $statuslabel = App\Models\Statuslabel::orderByDesc('created_at') - ->withCount('assets as assets_count') - ->take(10)->get()->shuffle()->first(); - $I->seeResponseContainsJson($I->removeTimestamps((new StatuslabelsTransformer)->transformStatuslabel($statuslabel))); - } - - /** @test */ - public function createStatuslabel(ApiTester $I, $scenario) - { - $I->wantTo('Create a new statuslabel'); - - $temp_statuslabel = \App\Models\Statuslabel::factory()->make([ - 'name' => 'Test Statuslabel Tag', - ]); - - // setup - $data = [ - 'name' => $temp_statuslabel->name, - 'archived' => $temp_statuslabel->archived, - 'deployable' => $temp_statuslabel->deployable, - 'notes' => $temp_statuslabel->notes, - 'pending' => $temp_statuslabel->pending, - 'type' => 'deployable', - ]; - - // create - $I->sendPOST('/statuslabels', $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateStatuslabelWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an statuslabel with PATCH'); - - // create - $statuslabel = \App\Models\Statuslabel::factory()->rtd()->create([ - 'name' => 'Original Statuslabel Name', - ]); - $I->assertInstanceOf(\App\Models\Statuslabel::class, $statuslabel); - - $temp_statuslabel = \App\Models\Statuslabel::factory()->pending()->make([ - 'name' => 'updated statuslabel name', - 'type' => 'pending', - ]); - - $data = [ - 'name' => $temp_statuslabel->name, - 'archived' => $temp_statuslabel->archived, - 'deployable' => $temp_statuslabel->deployable, - 'notes' => $temp_statuslabel->notes, - 'pending' => $temp_statuslabel->pending, - 'type' => $temp_statuslabel->type, - ]; - - $I->assertNotEquals($statuslabel->name, $data['name']); - - // update - $I->sendPATCH('/statuslabels/'.$statuslabel->id, $data); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - // dd($response); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/statuslabels/message.update.success'), $response->messages); - $I->assertEquals($statuslabel->id, $response->payload->id); // statuslabel id does not change - $I->assertEquals($temp_statuslabel->name, $response->payload->name); // statuslabel name updated - // Some manual copying to compare against - $temp_statuslabel->created_at = Carbon::parse($response->payload->created_at); - $temp_statuslabel->updated_at = Carbon::parse($response->payload->updated_at); - $temp_statuslabel->id = $statuslabel->id; - - // verify - $I->sendGET('/statuslabels/'.$statuslabel->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new StatuslabelsTransformer)->transformStatuslabel($temp_statuslabel)); - } - - /** @test */ - public function deleteStatuslabelTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an statuslabel'); - - // create - $statuslabel = \App\Models\Statuslabel::factory()->create([ - 'name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\Statuslabel::class, $statuslabel); - - // delete - $I->sendDELETE('/statuslabels/'.$statuslabel->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/statuslabels/message.delete.success'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/statuslabels/'.$statuslabel->id); - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } -} diff --git a/tests/api/ApiUsersCest.php b/tests/api/ApiUsersCest.php deleted file mode 100644 index 912653be2d..0000000000 --- a/tests/api/ApiUsersCest.php +++ /dev/null @@ -1,205 +0,0 @@ -user = \App\Models\User::find(1); - $I->haveHttpHeader('Accept', 'application/json'); - $I->amBearerAuthenticated($I->getToken($this->user)); - } - - /** @test */ - public function indexUsers(ApiTester $I) - { - $I->wantTo('Get a list of users'); - - // call - $I->sendGET('/users?limit=10&sort=created_at'); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse(), true); - // sample verify - $user = App\Models\User::orderByDesc('created_at') - ->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count') - ->take(10)->get()->shuffle()->first(); - $I->seeResponseContainsJson($I->removeTimestamps((new UsersTransformer)->transformUser($user))); - } - - /** @test */ - public function createUser(ApiTester $I, $scenario) - { - $I->wantTo('Create a new user'); - - $temp_user = \App\Models\User::factory()->make([ - 'name' => 'Test User Name', - ]); - Group::factory()->count(2)->create(); - $groups = Group::pluck('id'); - // setup - $data = [ - 'activated' => $temp_user->activated, - 'address' => $temp_user->address, - 'city' => $temp_user->city, - 'company_id' => $temp_user->company_id, - 'country' => $temp_user->country, - 'department_id' => $temp_user->department_id, - 'email' => $temp_user->email, - 'employee_num' => $temp_user->employee_num, - 'first_name' => $temp_user->first_name, - 'jobtitle' => $temp_user->jobtitle, - 'last_name' => $temp_user->last_name, - 'locale' => $temp_user->locale, - 'location_id' => $temp_user->location_id, - 'notes' => $temp_user->notes, - 'manager_id' => $temp_user->manager_id, - 'password' => $temp_user->password, - 'password_confirmation' => $temp_user->password, - 'phone' => $temp_user->phone, - 'state' => $temp_user->state, - 'username' => $temp_user->username, - 'zip' => $temp_user->zip, - 'groups' => $groups, - ]; - - // create - $I->sendPOST('/users', $data); - $I->seeResponseIsJson(); - $user = User::where('username', $temp_user->username)->first(); - $I->assertEquals($groups, $user->groups()->pluck('id')); - $I->seeResponseCodeIs(200); - } - - // Put is routed to the same method in the controller - // DO we actually need to test both? - - /** @test */ - public function updateUserWithPatch(ApiTester $I, $scenario) - { - $I->wantTo('Update an user with PATCH'); - - // create - $user = \App\Models\User::factory()->create([ - 'first_name' => 'Original User Name', - 'company_id' => 2, - 'location_id' => 3, - ]); - $I->assertInstanceOf(\App\Models\User::class, $user); - - $temp_user = \App\Models\User::factory()->make([ - 'company_id' => 3, - 'first_name' => 'updated user name', - 'location_id' => 1, - ]); - - Group::factory()->count(2)->create(); - $groups = Group::pluck('id'); - - $data = [ - 'activated' => $temp_user->activated, - 'address' => $temp_user->address, - 'city' => $temp_user->city, - 'company_id' => $temp_user->company_id, - 'country' => $temp_user->country, - 'department_id' => $temp_user->department_id, - 'email' => $temp_user->email, - 'employee_num' => $temp_user->employee_num, - 'first_name' => $temp_user->first_name, - 'groups' => $groups, - 'jobtitle' => $temp_user->jobtitle, - 'last_name' => $temp_user->last_name, - 'locale' => $temp_user->locale, - 'location_id' => $temp_user->location_id, - 'notes' => $temp_user->notes, - 'manager_id' => $temp_user->manager_id, - 'password' => $temp_user->password, - 'phone' => $temp_user->phone, - 'state' => $temp_user->state, - 'username' => $temp_user->username, - 'zip' => $temp_user->zip, - ]; - - $I->assertNotEquals($user->first_name, $data['first_name']); - - // update - $I->sendPATCH('/users/'.$user->id, $data); - $I->seeResponseIsJson(); - - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/users/message.success.update'), $response->messages); - $I->assertEquals($user->id, $response->payload->id); // user id does not change - $I->assertEquals($temp_user->company_id, $response->payload->company->id); // company_id updated - $I->assertEquals($temp_user->first_name, $response->payload->first_name); // user name updated - $I->assertEquals($temp_user->location_id, $response->payload->location->id); // user location_id updated - $newUser = User::where('username', $temp_user->username)->first(); - $I->assertEquals($groups, $newUser->groups()->pluck('id')); - $temp_user->created_at = Carbon::parse($response->payload->created_at->datetime); - $temp_user->updated_at = Carbon::parse($response->payload->updated_at->datetime); - $temp_user->id = $user->id; - // verify - $I->sendGET('/users/'.$user->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - $I->seeResponseContainsJson((new UsersTransformer)->transformUser($temp_user)); - } - - /** @test */ - public function deleteUserTest(ApiTester $I, $scenario) - { - $I->wantTo('Delete an user'); - - // create - $user = \App\Models\User::factory()->create([ - 'first_name' => 'Soon to be deleted', - ]); - $I->assertInstanceOf(\App\Models\User::class, $user); - - // delete - $I->sendDELETE('/users/'.$user->id); - $I->seeResponseIsJson(); - $I->seeResponseCodeIs(200); - - $response = json_decode($I->grabResponse()); - // dd($response); - $I->assertEquals('success', $response->status); - $I->assertEquals(trans('admin/users/message.success.delete'), $response->messages); - - // verify, expect a 200 - $I->sendGET('/users/'.$user->id); - - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - } - - /** @test */ - public function fetchUserAssetsTest(ApiTester $I, $scenario) - { - $I->wantTo('Fetch assets for a user'); - - $user = User::has('assets')->first(); - $asset = $user->assets->shuffle()->first(); - $I->sendGET("/users/{$user->id}/assets"); - $response = json_decode($I->grabResponse()); - $I->seeResponseCodeIs(200); - $I->seeResponseIsJson(); - - // Just test a random one. - $I->seeResponseContainsJson([ - 'asset_tag' => $asset->asset_tag, - ]); - } -} diff --git a/tests/api/_bootstrap.php b/tests/api/_bootstrap.php deleted file mode 100644 index 62817a53c4..0000000000 --- a/tests/api/_bootstrap.php +++ /dev/null @@ -1,3 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - $I->seeAuthentication(); - } - - // tests - public function loadsFormWithoutErrors(FunctionalTester $I) - { - $I->wantTo('ensure that the create accessories form loads without errors'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage('/accessories/create'); - $I->seeResponseCodeIs(200); - $I->dontSee('Create Accessory', '.page-header'); - $I->see('Create Accessory', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage('/accessories/create'); - $I->seeResponseCodeIs(200); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - $I->see('The category id field is required.', '.alert-msg'); - $I->see('The qty field is required.', '.alert-msg'); - } - - public function failsShortValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with short name'); - $I->amOnPage('/accessories/create'); - $I->seeResponseCodeIs(200); - $I->fillField('name', 't2'); - $I->fillField('qty', '-15'); - $I->fillField('min_amt', '-15'); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name must be at least 3 characters', '.alert-msg'); - $I->see('The category id field is required', '.alert-msg'); - $I->see('The qty must be at least 1', '.alert-msg'); - $I->see('The min amt must be at least 0', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $accessory = \App\Models\Accessory::factory()->appleBtKeyboard()->make(); - $values = [ - 'category_id' => $accessory->category_id, - 'location_id' => $accessory->location_id, - 'manufacturer_id' => $accessory->manufacturer_id, - 'min_amt' => $accessory->min_amt, - 'name' => 'Test Accessory', - 'order_number' => $accessory->order_number, - 'purchase_date' => '2016-01-01', - 'qty' => $accessory->qty, - ]; - - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage('/accessories/create'); - $I->seeResponseCodeIs(200); - - $I->submitForm('form#create-form', $values); - $I->seeRecord('accessories', $values); - - $I->dontSee('<span class="'); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete an accessory'); - $I->sendDelete(route('accessories.destroy', $I->getAccessoryId()), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/AssetModelsCest.php b/tests/functional/AssetModelsCest.php deleted file mode 100644 index fbf43a5c57..0000000000 --- a/tests/functional/AssetModelsCest.php +++ /dev/null @@ -1,63 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('Test Asset Model Creation'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('models.create')); - $I->seeInTitle('Create Asset Model'); - $I->see('Create Asset Model', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('models.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - $I->see('The manufacturer id field is required.', '.alert-msg'); - $I->see('The category id field is required.', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $model = \App\Models\AssetModel::factory()->mbp13Model()->make(['name'=>'Test Model']); - $values = [ - 'category_id' => $model->category_id, - 'depreciation_id' => $model->depreciation_id, - 'eol' => $model->eol, - 'manufacturer_id' => $model->manufacturer_id, - 'model_number' => $model->model_number, - 'name' => $model->name, - 'notes' => $model->notes, - ]; - - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('models.create')); - - $I->submitForm('form#create-form', $values); - $I->seeRecord('models', $values); - $I->dontSee('<span class="'); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete an asset model'); - $model = \App\Models\AssetModel::factory()->mbp13Model()->create(['name' => 'Test Model']); - $I->sendDelete(route('models.destroy', $model->id), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/AssetsCest.php b/tests/functional/AssetsCest.php deleted file mode 100644 index 3c7ffc1282..0000000000 --- a/tests/functional/AssetsCest.php +++ /dev/null @@ -1,94 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('ensure that the create assets form loads without errors'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('hardware.create')); - $I->dontSee('Create Asset', '.page-header'); - $I->see('Create Asset', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('hardware.create')); - // Settings factory can enable auto prefixes, which generate a random asset id. Lets clear it out for the sake of this test. - $I->fillField('#asset_tag', ''); - $I->click('Save'); - $I->see('The asset tag field is required.', '.alert-msg'); - $I->see('The model id field is required.', '.alert-msg'); - $I->see('The status id field is required.', '.alert-msg'); - } - - public function passesCreateAndCheckout(FunctionalTester $I) - { - $asset = \App\Models\Asset::factory()->laptopMbp()->make([ - 'asset_tag'=>'test tag', - 'name'=> 'test asset', - 'company_id'=>1, - 'warranty_months'=>15, - ]); - $userId = $I->getUserId(); - $values = [ - 'asset_tags[1]' => $asset->asset_tag, - 'assigned_user' => $userId, - 'company_id' => $asset->company_id, - 'model_id' => $asset->model_id, - 'name' => $asset->name, - 'notes' => $asset->notes, - 'order_number' => $asset->order_number, - 'purchase_cost' => $asset->purchase_cost, - 'purchase_date' => '2016-01-01', - 'requestable' => $asset->requestable, - 'rtd_location_id' => $asset->rtd_location_id, - 'serials[1]' => $asset->serial, - 'status_id' => $asset->status_id, - 'supplier_id' => $asset->supplier_id, - 'warranty_months' => $asset->warranty_months, - ]; - - $seenValues = [ - 'asset_tag' => $asset->asset_tag, - 'assigned_to' => $userId, - 'assigned_type' => \App\Models\User::class, - 'company_id' => $asset->company_id, - 'model_id' => $asset->model_id, - 'name' => $asset->name, - 'notes' => $asset->notes, - 'order_number' => $asset->order_number, - 'purchase_cost' => $asset->purchase_cost, - 'purchase_date' => '2016-01-01', - 'requestable' => $asset->requestable, - 'rtd_location_id' => $asset->rtd_location_id, - 'serial' => $asset->serial, - 'status_id' => $asset->status_id, - 'supplier_id' => $asset->supplier_id, - 'warranty_months' => $asset->warranty_months, - ]; - - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('hardware.create')); - $I->submitForm('form#create-form', $values); - $I->seeRecord('assets', $seenValues); - $I->seeResponseCodeIs(200); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete an asset'); - $I->sendDelete(route('hardware.destroy', $I->getAssetId()), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/CategoriesCest.php b/tests/functional/CategoriesCest.php deleted file mode 100644 index ff89fcc152..0000000000 --- a/tests/functional/CategoriesCest.php +++ /dev/null @@ -1,66 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - public function _after(FunctionalTester $I) - { - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('Test Category Creation'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('categories.create')); - $I->seeInTitle('Create Category'); - $I->see('Create Category', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('categories.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - $I->see('The category type field is required.', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $category = \App\Models\Category::factory()->assetLaptopCategory()->make([ - 'name' => 'Test Category', - ]); - $values = [ - 'category_type' => $category->category_type, - 'checkin_email' => $category->checkin_email, - 'eula_text' => $category->eula_text, - 'name' => $category->name, - 'require_acceptance' => $category->require_acceptance, - ]; - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('categories.create')); - $I->submitForm('form#create-form', $values); - $I->seeRecord('categories', $values); - $I->dontSee('<span class="'); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete a category'); - $category = \App\Models\Category::factory()->assetLaptopCategory()->create([ - 'name'=>'Deletable Test Category', - ]); - $I->sendDelete(route('categories.destroy', $category->id), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/CompaniesCest.php b/tests/functional/CompaniesCest.php deleted file mode 100644 index 75724aa206..0000000000 --- a/tests/functional/CompaniesCest.php +++ /dev/null @@ -1,46 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('Test Company Creation'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('companies.create')); - $I->seeInTitle('Create Company'); - $I->see('Create Company', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('companies.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $company = \App\Models\Company::factory()->make(); - $values = [ - 'name' => $company->name, - ]; - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('companies.create')); - $I->fillField('name', 'TestCompany'); - $I->submitForm('form#create-form', $values); - $I->seeRecord('companies', $values); - $I->dontSee('<span class="'); - $I->seeElement('.alert-success'); - } -} diff --git a/tests/functional/ComponentsCest.php b/tests/functional/ComponentsCest.php deleted file mode 100644 index 6e2a7f136b..0000000000 --- a/tests/functional/ComponentsCest.php +++ /dev/null @@ -1,79 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('ensure that the create components form loads without errors'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('components.create')); - $I->dontSee('Create Component', '.page-header'); - $I->see('Create Component', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('components.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - $I->see('The category id field is required.', '.alert-msg'); - $I->see('The qty field is required.', '.alert-msg'); - } - - public function failsShortValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with short name'); - $I->amOnPage(route('components.create')); - $I->fillField('name', 't2'); - $I->fillField('qty', '-15'); - $I->fillField('min_amt', '-15'); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name must be at least 3 characters', '.alert-msg'); - $I->see('The qty must be at least 1', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $component = \App\Models\Component::factory()->ramCrucial4()->make([ - 'name' => 'Test Component', - 'serial' => '3523-235325-1350235', - ]); - $values = [ - 'category_id' => $component->category_id, - 'company_id' => $component->company_id, - 'location_id' => $component->location_id, - 'min_amt' => $component->min_amt, - 'name' => $component->name, - 'order_number' => $component->order_number, - 'purchase_cost' => $component->purchase_cost, - 'purchase_date' => '2016-01-01', - 'qty' => $component->qty, - 'serial' => $component->serial, - ]; - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('components.create')); - $I->submitForm('form#create-form', $values); - $I->seeRecord('components', $values); - $I->dontSee('<span class="'); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete a component'); - $I->sendDelete(route('components.destroy', $I->getComponentId()), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/ConsumablesCest.php b/tests/functional/ConsumablesCest.php deleted file mode 100644 index c47eb23c0f..0000000000 --- a/tests/functional/ConsumablesCest.php +++ /dev/null @@ -1,81 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('ensure that the create consumables form loads without errors'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('consumables.create')); - $I->dontSee('Create Consumable', '.page-header'); - $I->see('Create Consumable', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('consumables.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - $I->see('The category id field is required.', '.alert-msg'); - $I->see('The qty field is required.', '.alert-msg'); - } - - public function failsShortValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with short name'); - $I->amOnPage(route('consumables.create')); - $I->fillField('name', 't2'); - $I->fillField('qty', '-15'); - $I->fillField('min_amt', '-15'); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name must be at least 3 characters', '.alert-msg'); - $I->see('The qty must be at least 0', '.alert-msg'); - $I->see('The min amt must be at least 0', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $consumable = \App\Models\Consumable::factory()->cardstock()->make([ - 'name' => 'Test Consumable', - 'model_number' => 23520, - ]); - // dd($consumable); - $values = [ - 'category_id' => $consumable->category_id, - 'company_id' => $consumable->company_id, - 'item_no' => $consumable->item_no, - 'manufacturer_id' => $consumable->manufacturer_id, - 'min_amt' => $consumable->min_amt, - 'model_number' => $consumable->model_number, - 'name' => $consumable->name, - 'order_number' => $consumable->order_number, - 'purchase_cost' => $consumable->purchase_cost, - 'purchase_date' => '2016-01-01', - 'qty' => $consumable->qty, - ]; - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('consumables.create')); - $I->submitForm('form#create-form', $values); - $I->seeRecord('consumables', $values); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete a consumable'); - $I->sendDelete(route('consumables.destroy', $I->getConsumableId()), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/DepreciationsCest.php b/tests/functional/DepreciationsCest.php deleted file mode 100644 index 25dcfaef1f..0000000000 --- a/tests/functional/DepreciationsCest.php +++ /dev/null @@ -1,66 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('Test Depreciation Creation'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('depreciations.create')); - $I->seeInTitle('Create Depreciation'); - $I->dontSee('Create Depreciation', '.page-header'); - $I->see('Create Depreciation', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('depreciations.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - $I->see('The months field is required.', '.alert-msg'); - } - - public function failsShortValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with short name'); - $I->amOnPage(route('depreciations.create')); - $I->fillField('name', 't2'); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name must be at least 3 characters', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $depreciation = \App\Models\Depreciation::factory()->computer()->make([ - 'name'=>'Test Depreciation', - ]); - $values = [ - 'name' => $depreciation->name, - 'months' => $depreciation->months, - ]; - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('depreciations.create')); - $I->submitForm('form#create-form', $values); - $I->seeRecord('depreciations', $values); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete a depreciation'); - $I->sendDelete(route('depreciations.destroy', $I->getDepreciationId()), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/GroupsCest.php b/tests/functional/GroupsCest.php deleted file mode 100644 index aa9ba9872a..0000000000 --- a/tests/functional/GroupsCest.php +++ /dev/null @@ -1,74 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function loadsFormWithoutErrors(FunctionalTester $I) - { - $I->wantTo('ensure that the create groups form loads without errors'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('groups.create')); - $I->seeResponseCodeIs(200); - $I->dontSee('Create New Group', '.page-header'); - $I->see('Create New Group', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('groups.create')); - $I->seeResponseCodeIs(200); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - } - - public function failsShortValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with short name'); - $I->amOnPage(route('groups.create')); - $I->seeResponseCodeIs(200); - $I->fillField('name', 't'); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name must be at least 2 characters', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('groups.create')); - $I->seeResponseCodeIs(200); - $I->fillField('name', 'TestGroup'); - $I->click('Save'); - $I->dontSee('<span class="'); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I, $scenario) - { - $I->wantTo('Ensure I can delete a group'); - // create a group - $I->amOnPage(route('groups.create')); - $I->seeResponseCodeIs(200); - $I->fillField('name', 'TestGroup'); - $I->click('Save'); - $I->dontSee('<span class="'); - $I->seeElement('.alert-success'); - - $I->sendDelete(route('groups.destroy', Group::whereName('TestGroup')->doesntHave('users')->first()->id)); - $I->seeResponseCodeIs(200); - $I->seeElement('.alert-success'); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/LicensesCest.php b/tests/functional/LicensesCest.php deleted file mode 100644 index 5add67f51d..0000000000 --- a/tests/functional/LicensesCest.php +++ /dev/null @@ -1,88 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('ensure that the create licenses form loads without errors'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('licenses.create')); - $I->dontSee('Create License', '.page-header'); - $I->see('Create License', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('licenses.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - $I->see('The seats field is required.', '.alert-msg'); - $I->see('The category id field is required.', '.alert-msg'); - } - - public function failsShortValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with short name'); - $I->amOnPage(route('licenses.create')); - $I->fillField('name', 't2'); - $I->fillField('seats', '-15'); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name must be at least 3 characters', '.alert-msg'); - $I->see('The seats must be at least 1', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $license = \App\Models\License::factory()->photoshop()->make([ - 'name' => 'Test License', - 'company_id' => 3, - ]); - $values = [ - 'company_id' => $license->company_id, - 'expiration_date' => '2018-01-01', - 'license_email' => $license->license_email, - 'license_name' => $license->license_name, - 'maintained' => true, - 'manufacturer_id' => $license->manufacturer_id, - 'category_id' => $license->category_id, - 'name' => $license->name, - 'notes' => $license->notes, - 'order_number' => $license->order_number, - 'purchase_cost' => $license->purchase_cost, - 'purchase_date' => '2016-01-01', - 'purchase_order' => $license->purchase_order, - 'reassignable' => true, - 'seats' => $license->seats, - 'serial' => $license->serial, - 'termination_date' => '2020-01-01', - ]; - - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('licenses.create')); - $I->submitForm('form#create-form', $values); - $I->seeRecord('licenses', $values); - $I->dontSee('<span class="'); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete a license'); - $I->sendDelete(route('licenses.destroy', License::doesntHave('assignedUsers')->first()->id), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/LocationsCest.php b/tests/functional/LocationsCest.php deleted file mode 100644 index 9177c6ae4b..0000000000 --- a/tests/functional/LocationsCest.php +++ /dev/null @@ -1,74 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - /* Create Form */ - $I->wantTo('Test Location Creation'); - $I->lookForwardTo('Finding no Failures'); - $I->amOnPage(route('locations.create')); - $I->dontSee('Create Location', '.page-header'); - $I->see('Create Location', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('locations.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - } - - public function failsShortValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with short values'); - $I->amOnPage(route('locations.create')); - $I->fillField('name', 't'); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name must be at least 2 characters', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $location = \App\Models\Location::factory()->make(); - $values = [ - 'name' => $location->name, - 'parent_id' => $I->getLocationId(), - 'currency' => $location->currency, - 'address' => $location->address, - 'address2' => $location->address2, - 'city' => $location->city, - 'state' => $location->state, - 'country' => $location->country, - 'zip' => $location->zip, - ]; - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('locations.create')); - $I->submitForm('form#create-form', $values); - $I->seeRecord('locations', $values); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete a location'); - $location = \App\Models\Location::factory()->create(); - $I->sendDelete(route('locations.destroy', $location->id), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/ManufacturersCest.php b/tests/functional/ManufacturersCest.php deleted file mode 100644 index 65c8b1d190..0000000000 --- a/tests/functional/ManufacturersCest.php +++ /dev/null @@ -1,66 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('Test Manufacturer Creation'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('manufacturers.create')); - $I->seeInTitle('Create Manufacturer'); - $I->see('Create Manufacturer', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('manufacturers.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - } - - public function failsShortValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with short name'); - $I->amOnPage(route('manufacturers.create')); - $I->fillField('name', 't'); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name must be at least 2 characters', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $manufacturer = \App\Models\Manufacturer::factory()->microsoft()->make([ - 'name' => 'Test Manufacturer', - ]); - $values = [ - 'name' => $manufacturer->name, - ]; - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('manufacturers.create')); - $I->submitForm('form#create-form', $values); - $I->seeRecord('manufacturers', $values); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete a manufacturer'); - $manufacturerId = \App\Models\Manufacturer::factory()->microsoft()->create(['name' => 'Deletable Test Manufacturer'])->id; - $I->sendDelete(route('manufacturers.destroy', $manufacturerId), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/StatusLabelsCest.php b/tests/functional/StatusLabelsCest.php deleted file mode 100644 index ff1ec90961..0000000000 --- a/tests/functional/StatusLabelsCest.php +++ /dev/null @@ -1,67 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('ensure that the create statuslabels form loads without errors'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('statuslabels.create')); - $I->dontSee('Create Status Label', '.page-header'); - $I->see('Create Status Label', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('statuslabels.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $status = \App\Models\Statuslabel::factory()->pending()->make(); - $submitValues = [ - 'name' => 'Testing Status', - 'statuslabel_types' => 'pending', - 'color' => '#b46262', - 'notes' => $status->notes, - 'show_in_nav' => true, - ]; - - $recordValues = [ - 'name' => 'Testing Status', - 'pending' => $status->pending, - 'deployable' => $status->archived, - 'archived' => $status->deployable, - 'color' => '#b46262', - 'notes' => $status->notes, - 'show_in_nav' => true, - ]; - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('statuslabels.create')); - $I->submitForm('form#create-form', $submitValues); - $I->seeRecord('status_labels', $recordValues); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete a Status Label'); - $I->sendDelete(route('statuslabels.destroy', Statuslabel::doesntHave('assets')->first()->id), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/SuppliersCest.php b/tests/functional/SuppliersCest.php deleted file mode 100644 index 69746f86a5..0000000000 --- a/tests/functional/SuppliersCest.php +++ /dev/null @@ -1,65 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('ensure that the create settings/suppliers form loads without errors'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('suppliers.create')); - $I->dontSee('Create Supplier', '.page-header'); - $I->see('Create Supplier', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('suppliers.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The name field is required.', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $supplier = \App\Models\Supplier::factory()->make(); - - $values = [ - 'name' => $supplier->name, - 'address' => $supplier->address, - 'address2' => $supplier->address2, - 'city' => $supplier->city, - 'state' => $supplier->state, - 'zip' => $supplier->zip, - 'country' => $supplier->country, - 'contact' => $supplier->contact, - 'phone' => $supplier->phone, - 'fax' => $supplier->fax, - 'email' => $supplier->email, - 'url' => $supplier->url, - 'notes' => $supplier->notes, - ]; - $I->wantTo('Test Validation Succeeds'); - $I->amOnPage(route('suppliers.create')); - $I->submitForm('form#create-form', $values); - $I->seeRecord('suppliers', $values); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $I->wantTo('Ensure I can delete a supplier'); - $supplier = \App\Models\Supplier::factory()->create(); - $I->sendDelete(route('suppliers.destroy', $supplier->id), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/UsersCest.php b/tests/functional/UsersCest.php deleted file mode 100644 index e861694918..0000000000 --- a/tests/functional/UsersCest.php +++ /dev/null @@ -1,98 +0,0 @@ -amOnPage('/login'); - $I->fillField('username', 'admin'); - $I->fillField('password', 'password'); - $I->click('Login'); - } - - // tests - public function tryToTest(FunctionalTester $I) - { - $I->wantTo('ensure that the create users form loads without errors'); - $I->lookForwardTo('seeing it load without errors'); - $I->amOnPage(route('users.create')); - $I->dontSee('Create User', '.page-header'); - $I->see('Create User', 'h1.pull-left'); - } - - public function failsEmptyValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with blank elements'); - $I->amOnPage(route('users.create')); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The first name field is required.', '.alert-msg'); - $I->see('The username field is required unless ldap import is in 1.', '.alert-msg'); - $I->see('The password field is required.', '.alert-msg'); - } - - public function failsShortValidation(FunctionalTester $I) - { - $I->wantTo('Test Validation Fails with short name'); - $I->amOnPage(route('users.create')); - $I->fillField('first_name', 't2'); - $I->fillField('last_name', 't2'); - $I->fillField('username', 'a'); - $I->fillField('password', '12345'); - $I->click('Save'); - $I->seeElement('.alert-danger'); - $I->see('The password must be at least 8 characters', '.alert-msg'); - } - - public function passesCorrectValidation(FunctionalTester $I) - { - $user = \App\Models\User::factory()->make(); - $submitValues = [ - 'first_name' => $user->first_name, - 'last_name' => $user->last_name, - 'username' => $user->username, - 'password' => $user->password, - 'password_confirmation' => $user->password, - 'email' => $user->email, - 'company_id' => $user->company_id, - 'locale' => $user->locale, - 'employee_num' => $user->employee_num, - 'jobtitle' => $user->jobtitle, - 'manager_id' => $user->manager_id, - 'location_id' => $user->location_id, - 'phone' => $user->phone, - 'activated' => true, - 'notes' => $user->notes, - ]; - $storedValues = [ - 'first_name' => $user->first_name, - 'last_name' => $user->last_name, - 'username' => $user->username, - 'email' => $user->email, - 'company_id' => $user->company_id, - 'locale' => $user->locale, - 'employee_num' => $user->employee_num, - 'jobtitle' => $user->jobtitle, - 'manager_id' => $user->manager_id, - 'location_id' => $user->location_id, - 'phone' => $user->phone, - 'activated' => true, - 'notes' => $user->notes, - ]; - $I->amOnPage(route('users.create')); - $I->wantTo('Test Validation Succeeds'); - $I->submitForm('form#userForm', $submitValues); - $I->seeRecord('users', $storedValues); - $I->seeElement('.alert-success'); - } - - public function allowsDelete(FunctionalTester $I) - { - $user = \App\Models\User::factory()->create(); - $I->wantTo('Ensure I can delete a user'); - $I->sendDelete(route('users.destroy', $user->id), ['_token' => csrf_token()]); - $I->seeResponseCodeIs(200); - } -} diff --git a/tests/functional/_bootstrap.php b/tests/functional/_bootstrap.php deleted file mode 100644 index 62817a53c4..0000000000 --- a/tests/functional/_bootstrap.php +++ /dev/null @@ -1,3 +0,0 @@ -