Skip to content

A free open source IT asset/license management system

Updated tests

snipeec779f587680
diff --git a/tests/Feature/SyncAdapters/ExtraFieldMappingTest.php b/tests/Feature/SyncAdapters/ExtraFieldMappingTest.php
index 445e821a89..ff66181d9d 100644
--- a/tests/Feature/SyncAdapters/ExtraFieldMappingTest.php
+++ b/tests/Feature/SyncAdapters/ExtraFieldMappingTest.php
@@ -118,25 +118,42 @@ class ExtraFieldMappingTest extends TestCase
]);
}
- public function test_extra_field_options_only_include_skip_and_custom_targets()
+ public function test_extra_field_options_include_skip_native_and_custom_targets_for_text_type()
{
CustomField::factory()->create(['element' => 'text', 'name' => 'Team Assignment']);
- $options = MappingTargets::optionsForExtra();
+ $options = MappingTargets::optionsForExtra('text');
- // First option is always skip.
$this->assertArrayHasKey('skip', $options);
- // Every non-skip option is a custom:{id} target. Extras never
- // route to native or external targets by design.
+ // Text-type extras can route to native asset_tag / notes so
+ // admins whose vendor stores per-device metadata in labels /
+ // blueprints / teams can land it in a native column instead
+ // of forcing a custom field. Everything else must be
+ // custom:{id}.
+ $this->assertArrayHasKey('native:asset_tag', $options);
+ $this->assertArrayHasKey('native:notes', $options);
foreach ($options as $target => $label) {
- if ($target === 'skip') {
+ if (in_array($target, ['skip', 'native:asset_tag', 'native:notes'], true)) {
continue;
}
$this->assertStringStartsWith('custom:', $target);
}
}
+ public function test_boolean_extra_field_options_stay_custom_only()
+ {
+ CustomField::factory()->create(['element' => 'checkbox', 'name' => 'Flagged']);
+
+ $options = MappingTargets::optionsForExtra('boolean');
+
+ // Boolean-typed extras stay custom-fields-only because no
+ // native asset column carries a boolean semantic.
+ $this->assertArrayHasKey('skip', $options);
+ $this->assertArrayNotHasKey('native:asset_tag', $options);
+ $this->assertArrayNotHasKey('native:notes', $options);
+ }
+
public function test_asset_tag_native_target_overwrites_the_asset_tag_column()
{
$fleet = $this->configuredFleetInstance();
diff --git a/tests/Feature/SyncAdapters/Fleet/FleetLicenseTierTest.php b/tests/Feature/SyncAdapters/Fleet/FleetLicenseTierTest.php
new file mode 100644
index 0000000000..236110e733
--- /dev/null
+++ b/tests/Feature/SyncAdapters/Fleet/FleetLicenseTierTest.php
@@ -0,0 +1,124 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters\Fleet;
+
+use App\Models\Category;
+use App\Models\Statuslabel;
+use App\Models\SyncAdapterConfig;
+use App\Models\SyncAdapterInstance;
+use App\Models\User;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+/**
+ * Coverage for Fleet Premium detection. After the admin saves the
+ * Fleet config, the adapter probes /api/latest/fleet/config, caches
+ * the license tier, and hides the group-mapping UI on Free tier so
+ * admins don't hit a 402 when they try to Refresh.
+ */
+class FleetLicenseTierTest extends TestCase
+{
+ /**
+ * @return array<string, int>
+ */
+ private function requiredFields(string $slug): array
+ {
+ return [
+ $slug.'_default_category_id' => Category::factory()->create()->id,
+ $slug.'_default_status_id' => Statuslabel::factory()->rtd()->create()->id,
+ ];
+ }
+
+ public function test_saving_free_tier_fleet_caches_free_and_hides_group_scoping()
+ {
+ $fleet = SyncAdapterInstance::where('slug', 'fleet')->firstOrFail();
+
+ Http::fake([
+ '*/api/latest/fleet/config' => Http::response([
+ 'license' => ['tier' => 'free'],
+ ]),
+ ]);
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->post(route('settings.adapters.save', $fleet), $this->requiredFields('fleet') + [
+ 'fleet_url' => 'https://example.com/free-fleet',
+ 'fleet_token' => 'plaintext-token',
+ ])
+ ->assertSessionHasNoErrors()
+ ->assertRedirect();
+
+ $this->assertSame('free', SyncAdapterConfig::get($fleet->id, 'fleet_license_tier'));
+ $this->assertFalse($fleet->fresh()->adapter()->supportsGroupScoping());
+ }
+
+ public function test_saving_premium_tier_fleet_caches_premium_and_keeps_group_scoping()
+ {
+ $fleet = SyncAdapterInstance::where('slug', 'fleet')->firstOrFail();
+
+ Http::fake([
+ '*/api/latest/fleet/config' => Http::response([
+ 'license' => ['tier' => 'premium', 'device_count' => 500],
+ ]),
+ ]);
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->post(route('settings.adapters.save', $fleet), $this->requiredFields('fleet') + [
+ 'fleet_url' => 'https://example.com/premium-fleet',
+ 'fleet_token' => 'plaintext-token',
+ ])
+ ->assertRedirect();
+
+ $this->assertSame('premium', SyncAdapterConfig::get($fleet->id, 'fleet_license_tier'));
+ $this->assertTrue($fleet->fresh()->adapter()->supportsGroupScoping());
+ }
+
+ public function test_unreachable_config_endpoint_leaves_cache_absent_and_defaults_group_scoping_on()
+ {
+ $fleet = SyncAdapterInstance::where('slug', 'fleet')->firstOrFail();
+
+ // /config returns 500. licenseTier() catches and returns null,
+ // afterSaveConfig() writes nothing, supportsGroupScoping()
+ // stays permissive (unknown != free).
+ Http::fake([
+ '*/api/latest/fleet/config' => Http::response([], 500),
+ ]);
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->post(route('settings.adapters.save', $fleet), $this->requiredFields('fleet') + [
+ 'fleet_url' => 'https://example.com/broken-fleet',
+ 'fleet_token' => 'plaintext-token',
+ ])
+ ->assertRedirect();
+
+ $this->assertNull(SyncAdapterConfig::get($fleet->id, 'fleet_license_tier'));
+ $this->assertTrue($fleet->fresh()->adapter()->supportsGroupScoping());
+ }
+
+ public function test_free_tier_stays_hidden_across_subsequent_saves_until_upgrade()
+ {
+ $fleet = SyncAdapterInstance::where('slug', 'fleet')->firstOrFail();
+ SyncAdapterConfig::put($fleet->id, 'fleet_license_tier', 'free');
+ SyncAdapterConfig::put($fleet->id, 'url', 'https://example.com/free-fleet');
+ SyncAdapterConfig::put($fleet->id, 'token', Crypt::encrypt('t'));
+
+ $this->assertFalse($fleet->fresh()->adapter()->supportsGroupScoping());
+
+ // Simulate the admin upgrading Fleet to Premium and re-saving.
+ Http::fake([
+ '*/api/latest/fleet/config' => Http::response([
+ 'license' => ['tier' => 'premium'],
+ ]),
+ ]);
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->post(route('settings.adapters.save', $fleet), $this->requiredFields('fleet') + [
+ 'fleet_url' => 'https://example.com/free-fleet',
+ 'fleet_token' => 'plaintext-token',
+ ])
+ ->assertRedirect();
+
+ $this->assertSame('premium', SyncAdapterConfig::get($fleet->id, 'fleet_license_tier'));
+ $this->assertTrue($fleet->fresh()->adapter()->supportsGroupScoping());
+ }
+}
diff --git a/tests/Feature/SyncAdapters/Fleet/FleetSyncNowTest.php b/tests/Feature/SyncAdapters/Fleet/FleetSyncNowTest.php
index efdd33d8e5..a969c1a2ed 100644
--- a/tests/Feature/SyncAdapters/Fleet/FleetSyncNowTest.php
+++ b/tests/Feature/SyncAdapters/Fleet/FleetSyncNowTest.php
@@ -13,7 +13,7 @@ use Tests\TestCase;
/**
* Covers the "Sync Now" button flow (POST /admin/adapters/fleet/sync)
- * and the snipeit:sync-inventory artisan command targeted at Fleet.
+ * and the snipeit:pull-inventory artisan command targeted at Fleet.
* Both share the same adapter plumbing, but each entry point is tested
* independently so a regression in either path is caught.
*/
@@ -79,14 +79,14 @@ class FleetSyncNowTest extends TestCase
public function test_artisan_command_fails_when_fleet_is_not_configured()
{
- $exit = Artisan::call('snipeit:sync-inventory', ['adapter' => 'fleet']);
+ $exit = Artisan::call('snipeit:pull-inventory', ['adapter' => 'fleet']);
$this->assertSame(1, $exit);
}
public function test_artisan_command_fails_with_unknown_instance()
{
- $exit = Artisan::call('snipeit:sync-inventory', ['adapter' => 'nope']);
+ $exit = Artisan::call('snipeit:pull-inventory', ['adapter' => 'nope']);
$this->assertSame(1, $exit);
$this->assertStringContainsString('Unknown adapter instance', Artisan::output());
@@ -104,7 +104,7 @@ class FleetSyncNowTest extends TestCase
]),
]);
- $exit = Artisan::call('snipeit:sync-inventory', ['adapter' => $fleet->slug]);
+ $exit = Artisan::call('snipeit:pull-inventory', ['adapter' => $fleet->slug]);
$this->assertSame(0, $exit);
$this->assertDatabaseCount('asset_external_sources', 1);
diff --git a/tests/Feature/SyncAdapters/Intune/IntunePushTest.php b/tests/Feature/SyncAdapters/Intune/IntunePushTest.php
new file mode 100644
index 0000000000..1a745299cc
--- /dev/null
+++ b/tests/Feature/SyncAdapters/Intune/IntunePushTest.php
@@ -0,0 +1,146 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters\Intune;
+
+use App\Models\Asset;
+use App\Models\AssetExternalSource;
+use App\Models\Statuslabel;
+use App\Models\SyncAdapterConfig;
+use App\Models\SyncAdapterInstance;
+use App\SyncAdapters\Intune\IntuneAdapter;
+use App\SyncAdapters\PushableAdapter;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+/**
+ * End-to-end coverage for the Intune composed-notes push path.
+ * Intune's writable per-device surface is limited so v1 only pushes
+ * composed notes (the pattern Brady Widener's community PowerShell
+ * script uses). Tests verify the PATCH lands on Graph beta with
+ * the right shape, the target override works, and dry-run behaves.
+ */
+class IntunePushTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Statuslabel::factory()->rtd()->create();
+ }
+
+ public function test_intune_adapter_implements_pushable_interface()
+ {
+ $this->assertInstanceOf(PushableAdapter::class, $this->configuredIntune());
+ }
+
+ public function test_push_notes_template_patches_intune_managed_device()
+ {
+ $adapter = $this->configuredIntune(template: "Tag: {asset_tag}\nStatus: {status}");
+ $status = Statuslabel::factory()->rtd()->create(['name' => 'Deployable']);
+ $asset = Asset::factory()->create([
+ 'asset_tag' => 'INT-42',
+ 'status_id' => $status->id,
+ ]);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => 'graph-device-uuid-42',
+ ]);
+
+ Http::fake(function ($request) {
+ if (str_contains($request->url(), '/oauth2/v2.0/token')) {
+ return Http::response(['access_token' => 'stub-bearer', 'expires_in' => 3600]);
+ }
+ if ($request->method() === 'PATCH' && str_contains($request->url(), '/beta/deviceManagement/managedDevices/graph-device-uuid-42')) {
+ return Http::response(['ok' => true]);
+ }
+
+ return Http::response(['unmatched' => true], 500);
+ });
+
+ $adapter->push($asset);
+
+ Http::assertSent(function ($request) {
+ if ($request->method() !== 'PATCH') {
+ return false;
+ }
+ if (! str_contains($request->url(), '/beta/deviceManagement/managedDevices/graph-device-uuid-42')) {
+ return false;
+ }
+ $notes = $request->data()['notes'] ?? '';
+
+ return str_contains($notes, 'Tag: INT-42') && str_contains($notes, 'Status: Deployable');
+ });
+ }
+
+ public function test_target_override_writes_to_admin_configured_field()
+ {
+ // Admin points composed notes at a Graph field other than
+ // "notes" via the vendor-field override.
+ $adapter = $this->configuredIntune(template: 'Tag: {asset_tag}');
+ $instance = SyncAdapterInstance::where('slug', 'intune')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'push_notes_target', 'roleScopeTagIds');
+
+ $asset = Asset::factory()->create(['asset_tag' => 'OVR-1']);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => 'guid-99',
+ ]);
+
+ Http::fake(function ($request) {
+ if (str_contains($request->url(), '/oauth2/v2.0/token')) {
+ return Http::response(['access_token' => 'stub', 'expires_in' => 3600]);
+ }
+
+ return Http::response(['ok' => true]);
+ });
+
+ // Re-hydrate the adapter so the new push_notes_target config
+ // gets picked up (the accessor reads through SyncAdapterConfig,
+ // no cache to invalidate, but we hydrate anyway for clarity).
+ $freshInstance = SyncAdapterInstance::where('slug', 'intune')->firstOrFail();
+ $freshAdapter = new IntuneAdapter($freshInstance);
+ $freshAdapter->push($asset);
+
+ Http::assertSent(function ($request) {
+ if ($request->method() !== 'PATCH') {
+ return false;
+ }
+
+ return ($request->data()['roleScopeTagIds'] ?? null) === 'Tag: OVR-1'
+ && ! isset($request->data()['notes']);
+ });
+ }
+
+ public function test_blank_template_skips_push_entirely()
+ {
+ $adapter = $this->configuredIntune(template: '');
+ $asset = Asset::factory()->create(['asset_tag' => 'NO-TPL']);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => 'guid-77',
+ ]);
+
+ Http::fake();
+
+ $adapter->push($asset);
+
+ Http::assertNothingSent();
+ }
+
+ private function configuredIntune(?string $template = null): IntuneAdapter
+ {
+ $instance = SyncAdapterInstance::where('slug', 'intune')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'url', 'https://graph.microsoft.com');
+ SyncAdapterConfig::put($instance->id, 'tenant_id', 'stub-tenant');
+ SyncAdapterConfig::put($instance->id, 'client_id', 'stub-client');
+ SyncAdapterConfig::put($instance->id, 'client_secret', Crypt::encrypt('fake-secret'));
+ if ($template !== null) {
+ SyncAdapterConfig::put($instance->id, 'push_notes_template', $template);
+ }
+
+ return new IntuneAdapter($instance->fresh());
+ }
+}
diff --git a/tests/Feature/SyncAdapters/Jamf/JamfPushTest.php b/tests/Feature/SyncAdapters/Jamf/JamfPushTest.php
new file mode 100644
index 0000000000..22bac28e82
--- /dev/null
+++ b/tests/Feature/SyncAdapters/Jamf/JamfPushTest.php
@@ -0,0 +1,107 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters\Jamf;
+
+use App\Models\Asset;
+use App\Models\AssetExternalSource;
+use App\Models\Statuslabel;
+use App\Models\SyncAdapterConfig;
+use App\Models\SyncAdapterInstance;
+use App\SyncAdapters\Jamf\JamfAdapter;
+use App\SyncAdapters\PushableAdapter;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+/**
+ * End-to-end coverage for the Jamf Pro push path. Verifies the
+ * PushableAdapter interface, the PATCH payload shape (nested
+ * userAndLocation.assetTag path per Jamf's inventory-detail JSON),
+ * and dry-run behavior.
+ */
+class JamfPushTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Statuslabel::factory()->rtd()->create();
+ }
+
+ public function test_jamf_adapter_implements_pushable_interface()
+ {
+ $this->assertInstanceOf(PushableAdapter::class, $this->configuredJamf());
+ }
+
+ public function test_push_asset_tag_sends_patch_with_nested_user_and_location_path()
+ {
+ $adapter = $this->configuredJamf();
+ $instance = SyncAdapterInstance::where('slug', 'jamf')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+
+ $asset = Asset::factory()->create([
+ 'asset_tag' => 'SNIPE-JAMF-42',
+ ]);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => 'jamf-computer-id-42',
+ ]);
+
+ Http::fake([
+ '*/api/v1/computers-inventory-detail/*' => Http::response(['ok' => true]),
+ ]);
+
+ $adapter->push($asset);
+
+ Http::assertSent(function ($request) {
+ return $request->method() === 'PATCH'
+ && str_contains($request->url(), '/api/v1/computers-inventory-detail/jamf-computer-id-42')
+ && ($request->data()['userAndLocation']['assetTag'] ?? null) === 'SNIPE-JAMF-42';
+ });
+ }
+
+ public function test_push_dry_run_logs_instead_of_sending()
+ {
+ $adapter = $this->configuredJamf();
+ $instance = SyncAdapterInstance::where('slug', 'jamf')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+ SyncAdapterConfig::put($instance->id, 'push_dry_run', '1');
+
+ $asset = Asset::factory()->create(['asset_tag' => 'DRY-RUN-JAMF']);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => 'jamf-99',
+ ]);
+
+ Http::fake();
+
+ $adapter->push($asset);
+
+ Http::assertNothingSent();
+ }
+
+ public function test_push_skipped_when_asset_has_no_external_source()
+ {
+ $adapter = $this->configuredJamf();
+ $instance = SyncAdapterInstance::where('slug', 'jamf')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+
+ $asset = Asset::factory()->create(['asset_tag' => 'NO-SOURCE-JAMF']);
+
+ Http::fake();
+
+ $adapter->push($asset);
+
+ Http::assertNothingSent();
+ }
+
+ private function configuredJamf(): JamfAdapter
+ {
+ $instance = SyncAdapterInstance::where('slug', 'jamf')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'url', 'https://example.com/jamf');
+ SyncAdapterConfig::put($instance->id, 'token', Crypt::encrypt('fake-jamf-token'));
+
+ return new JamfAdapter($instance->fresh());
+ }
+}
diff --git a/tests/Feature/SyncAdapters/Kandji/KandjiPushTest.php b/tests/Feature/SyncAdapters/Kandji/KandjiPushTest.php
new file mode 100644
index 0000000000..8d0de9f8c6
--- /dev/null
+++ b/tests/Feature/SyncAdapters/Kandji/KandjiPushTest.php
@@ -0,0 +1,155 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters\Kandji;
+
+use App\Models\AssetExternalSource;
+use App\Models\Statuslabel;
+use App\Models\SyncAdapterConfig;
+use App\Models\SyncAdapterInstance;
+use App\SyncAdapters\Kandji\KandjiAdapter;
+use App\SyncAdapters\PushableAdapter;
+use App\SyncAdapters\SyncHostFromAdapter;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+/**
+ * End-to-end coverage for the Kandji push path. Verifies the mapping
+ * table's direction column, PushableAdapter dispatch, and the actual
+ * PATCH shape (form-encoded asset_tag) that goes to Kandji.
+ */
+class KandjiPushTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Statuslabel::factory()->rtd()->create();
+ }
+
+ public function test_kandji_adapter_implements_pushable_interface()
+ {
+ $adapter = $this->configuredKandji();
+
+ $this->assertInstanceOf(PushableAdapter::class, $adapter);
+ }
+
+ public function test_push_asset_tag_sends_patch_to_kandji()
+ {
+ $adapter = $this->configuredKandji();
+ SyncAdapterConfig::put(SyncAdapterInstance::where('slug', 'kandji')->firstOrFail()->id, 'direction.asset_tag', 'push');
+
+ // Seed an asset + external-source row so push() has a device
+ // id to write against. Using the sync path to seed keeps the
+ // shape realistic.
+ Http::fake([
+ '*/api/v1/devices*' => Http::response([
+ $this->kandjiDevice(deviceId: 'kandji-uuid-1', name: 'test-host'),
+ ]),
+ ]);
+
+ foreach ($adapter->pull() as $record) {
+ SyncHostFromAdapter::run($record);
+ }
+
+ $asset = \App\Models\Asset::where('name', 'test-host')->firstOrFail();
+ $asset->asset_tag = 'SNIPE-EDIT-1234';
+ $asset->save();
+
+ // Fresh fake for the push PATCH.
+ Http::fake([
+ 'PATCH */api/v1/devices/kandji-uuid-1' => Http::response(['ok' => true]),
+ ]);
+
+ $adapter->push($asset);
+
+ Http::assertSent(function ($request) {
+ return $request->method() === 'PATCH'
+ && str_contains($request->url(), '/api/v1/devices/kandji-uuid-1')
+ && $request['asset_tag'] === 'SNIPE-EDIT-1234';
+ });
+ }
+
+ public function test_push_skipped_when_no_field_is_push_directed()
+ {
+ $adapter = $this->configuredKandji();
+ // Explicitly leave direction unset. Defaults to 'pull'.
+ $this->seedExternalSource($adapter, 'kandji-uuid-2');
+
+ Http::fake();
+
+ $adapter->push(\App\Models\Asset::first());
+
+ Http::assertNothingSent();
+ }
+
+ public function test_push_skipped_when_asset_has_no_external_source_for_this_instance()
+ {
+ $adapter = $this->configuredKandji();
+ SyncAdapterConfig::put(SyncAdapterInstance::where('slug', 'kandji')->firstOrFail()->id, 'direction.asset_tag', 'push');
+
+ // Asset with no asset_external_sources row for this instance.
+ $asset = \App\Models\Asset::factory()->create();
+
+ Http::fake();
+
+ $adapter->push($asset);
+
+ Http::assertNothingSent();
+ }
+
+ public function test_pull_path_does_not_overwrite_asset_tag_when_directed_push()
+ {
+ $adapter = $this->configuredKandji();
+ SyncAdapterConfig::put(SyncAdapterInstance::where('slug', 'kandji')->firstOrFail()->id, 'direction.asset_tag', 'push');
+
+ Http::fake([
+ '*/api/v1/devices*' => Http::response([
+ $this->kandjiDevice(deviceId: 'kandji-uuid-3', name: 'flip-host', assetTag: 'VENDOR-SIDE-TAG'),
+ ]),
+ ]);
+
+ foreach ($adapter->pull() as $record) {
+ SyncHostFromAdapter::run($record);
+ }
+
+ $asset = \App\Models\Asset::where('name', 'flip-host')->firstOrFail();
+ // asset_tag came from the auto-tag path (autoincrement or
+ // adapter pattern) rather than the vendor's asset_tag because
+ // direction.asset_tag is 'push', not 'pull'.
+ $this->assertNotSame('VENDOR-SIDE-TAG', $asset->asset_tag);
+ }
+
+ private function configuredKandji(): KandjiAdapter
+ {
+ $instance = SyncAdapterInstance::where('slug', 'kandji')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'url', 'https://example.com/kandji');
+ SyncAdapterConfig::put($instance->id, 'token', Crypt::encrypt('fake-kandji-token'));
+
+ return new KandjiAdapter($instance->fresh());
+ }
+
+ private function seedExternalSource(KandjiAdapter $adapter, string $externalId): void
+ {
+ $asset = \App\Models\Asset::factory()->create();
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => $externalId,
+ ]);
+ }
+
+ /**
+ * @return array<string, mixed>
+ */
+ private function kandjiDevice(string $deviceId, string $name, ?string $assetTag = null): array
+ {
+ return [
+ 'device_id' => $deviceId,
+ 'device_name' => $name,
+ 'serial_number' => 'SN-'.$deviceId,
+ 'model' => 'MacBook Pro',
+ 'platform' => 'Mac',
+ 'asset_tag' => $assetTag,
+ ];
+ }
+}
diff --git a/tests/Feature/SyncAdapters/Mosyle/MosylePushTest.php b/tests/Feature/SyncAdapters/Mosyle/MosylePushTest.php
new file mode 100644
index 0000000000..3561bdc4db
--- /dev/null
+++ b/tests/Feature/SyncAdapters/Mosyle/MosylePushTest.php
@@ -0,0 +1,108 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters\Mosyle;
+
+use App\Models\Asset;
+use App\Models\AssetExternalSource;
+use App\Models\Statuslabel;
+use App\Models\SyncAdapterConfig;
+use App\Models\SyncAdapterInstance;
+use App\SyncAdapters\Mosyle\MosyleAdapter;
+use App\SyncAdapters\PushableAdapter;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+/**
+ * End-to-end coverage for the Mosyle push path. Mosyle's write API
+ * is a single POST endpoint dispatched by an `operation` field, so
+ * tests verify the payload carries the right operation + serial +
+ * value.
+ */
+class MosylePushTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Statuslabel::factory()->rtd()->create();
+ }
+
+ public function test_mosyle_adapter_implements_pushable_interface()
+ {
+ $this->assertInstanceOf(PushableAdapter::class, $this->configuredMosyle());
+ }
+
+ public function test_push_asset_tag_sends_operation_scoped_by_serial()
+ {
+ $adapter = $this->configuredMosyle();
+ $instance = SyncAdapterInstance::where('slug', 'mosyle')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+
+ $asset = Asset::factory()->create([
+ 'asset_tag' => 'SNIPE-MOS-77',
+ 'serial' => 'MOS-SN-777',
+ ]);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => 'mosyle-udid-abc',
+ ]);
+
+ Http::fake([
+ '*/devices' => Http::response(['status' => 'ok']),
+ ]);
+
+ $adapter->push($asset);
+
+ Http::assertSent(function ($request) {
+ if ($request->method() !== 'POST') {
+ return false;
+ }
+ $body = $request->data();
+
+ return ($body['operation'] ?? null) === 'set_asset_tag_by_serial_number'
+ && ($body['serial_number'] ?? null) === 'MOS-SN-777'
+ && ($body['asset_tag'] ?? null) === 'SNIPE-MOS-77';
+ });
+ }
+
+ public function test_push_falls_back_to_external_id_when_serial_missing()
+ {
+ // Mosyle Business uses the device serial as external_id for
+ // some device types, so pushes still work for assets that
+ // never populated the serial column but do have an
+ // asset_external_sources row.
+ $adapter = $this->configuredMosyle();
+ $instance = SyncAdapterInstance::where('slug', 'mosyle')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+
+ $asset = Asset::factory()->create([
+ 'asset_tag' => 'SNIPE-MOS-88',
+ 'serial' => null,
+ ]);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => 'MOS-SN-888',
+ ]);
+
+ Http::fake([
+ '*/devices' => Http::response(['status' => 'ok']),
+ ]);
+
+ $adapter->push($asset);
+
+ Http::assertSent(function ($request) {
+ return ($request->data()['serial_number'] ?? null) === 'MOS-SN-888';
+ });
+ }
+
+ private function configuredMosyle(): MosyleAdapter
+ {
+ $instance = SyncAdapterInstance::where('slug', 'mosyle')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'url', 'https://example.com/mosyle');
+ SyncAdapterConfig::put($instance->id, 'token', Crypt::encrypt('fake-mosyle-token'));
+
+ return new MosyleAdapter($instance->fresh());
+ }
+}
diff --git a/tests/Feature/SyncAdapters/NinjaOne/NinjaOneComposedNotesPushTest.php b/tests/Feature/SyncAdapters/NinjaOne/NinjaOneComposedNotesPushTest.php
new file mode 100644
index 0000000000..909057d1bd
--- /dev/null
+++ b/tests/Feature/SyncAdapters/NinjaOne/NinjaOneComposedNotesPushTest.php
@@ -0,0 +1,112 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters\NinjaOne;
+
+use App\Models\Asset;
+use App\Models\AssetExternalSource;
+use App\Models\Statuslabel;
+use App\Models\SyncAdapterConfig;
+use App\Models\SyncAdapterInstance;
+use App\SyncAdapters\NinjaOne\NinjaOneAdapter;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+/**
+ * Coverage for NinjaOne composed-notes push. Ninja has no built-in
+ * notes column, so admins point the composed notes at an admin-named
+ * Custom Field via the push_notes_target override. Tests verify the
+ * PATCH lands with both asset_tag AND composed notes in the same
+ * /custom-fields call.
+ */
+class NinjaOneComposedNotesPushTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Statuslabel::factory()->rtd()->create();
+ }
+
+ public function test_push_writes_asset_tag_and_composed_notes_in_one_patch()
+ {
+ $instance = SyncAdapterInstance::where('slug', 'ninjaone')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'url', 'https://example.com/ninja');
+ SyncAdapterConfig::put($instance->id, 'client_id', 'stub');
+ SyncAdapterConfig::put($instance->id, 'client_secret', Crypt::encrypt('secret'));
+ SyncAdapterConfig::put($instance->id, 'asset_tag_custom_field', 'snipeAssetTag');
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+ SyncAdapterConfig::put($instance->id, 'push_notes_template', 'Tag: {asset_tag}');
+ SyncAdapterConfig::put($instance->id, 'push_notes_target', 'snipeInfo');
+
+ $adapter = new NinjaOneAdapter($instance->fresh());
+
+ $asset = Asset::factory()->create(['asset_tag' => 'NIN-42']);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => '42',
+ ]);
+
+ Http::fake(function ($request) {
+ if (str_contains($request->url(), '/ws/oauth/token')) {
+ return Http::response(['access_token' => 'stub', 'expires_in' => 3600]);
+ }
+ if ($request->method() === 'PATCH' && str_contains($request->url(), '/v2/device/42/custom-fields')) {
+ return Http::response(['ok' => true]);
+ }
+
+ return Http::response(['unmatched' => true], 500);
+ });
+
+ $adapter->push($asset);
+
+ Http::assertSent(function ($request) {
+ $body = $request->data();
+
+ return $request->method() === 'PATCH'
+ && ($body['snipeAssetTag'] ?? null) === 'NIN-42'
+ && ($body['snipeInfo'] ?? null) === 'Tag: NIN-42';
+ });
+ }
+
+ public function test_composed_notes_no_op_when_target_field_blank()
+ {
+ // No push_notes_target set. Even with a template, we don't
+ // guess a field name; skip silently. asset_tag push still
+ // fires because it has its own dedicated slot.
+ $instance = SyncAdapterInstance::where('slug', 'ninjaone')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'url', 'https://example.com/ninja');
+ SyncAdapterConfig::put($instance->id, 'client_id', 'stub');
+ SyncAdapterConfig::put($instance->id, 'client_secret', Crypt::encrypt('secret'));
+ SyncAdapterConfig::put($instance->id, 'asset_tag_custom_field', 'snipeAssetTag');
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+ SyncAdapterConfig::put($instance->id, 'push_notes_template', 'Tag: {asset_tag}');
+
+ $adapter = new NinjaOneAdapter($instance->fresh());
+
+ $asset = Asset::factory()->create(['asset_tag' => 'NIN-77']);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => '77',
+ ]);
+
+ Http::fake(function ($request) {
+ if (str_contains($request->url(), '/ws/oauth/token')) {
+ return Http::response(['access_token' => 'stub', 'expires_in' => 3600]);
+ }
+
+ return Http::response(['ok' => true]);
+ });
+
+ $adapter->push($asset);
+
+ Http::assertSent(function ($request) {
+ $body = $request->data();
+
+ return $request->method() === 'PATCH'
+ && ($body['snipeAssetTag'] ?? null) === 'NIN-77'
+ && ! array_key_exists('snipeInfo', $body ?? []);
+ });
+ }
+}
diff --git a/tests/Feature/SyncAdapters/NinjaOne/NinjaOnePushTest.php b/tests/Feature/SyncAdapters/NinjaOne/NinjaOnePushTest.php
new file mode 100644
index 0000000000..30e747bd59
--- /dev/null
+++ b/tests/Feature/SyncAdapters/NinjaOne/NinjaOnePushTest.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters\NinjaOne;
+
+use App\Models\Asset;
+use App\Models\AssetExternalSource;
+use App\Models\Statuslabel;
+use App\Models\SyncAdapterConfig;
+use App\Models\SyncAdapterInstance;
+use App\SyncAdapters\NinjaOne\NinjaOneAdapter;
+use App\SyncAdapters\PushableAdapter;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+/**
+ * End-to-end coverage for the NinjaOne push path. NinjaOne has no
+ * native asset_tag field, so push writes to an admin-configured
+ * per-device Custom Field. Tests verify the payload shape, the
+ * skip-when-unconfigured path, and the correct field name lands in
+ * the PATCH body.
+ */
+class NinjaOnePushTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Statuslabel::factory()->rtd()->create();
+ }
+
+ public function test_ninjaone_adapter_implements_pushable_interface()
+ {
+ $this->assertInstanceOf(PushableAdapter::class, $this->configuredNinja());
+ }
+
+ public function test_push_asset_tag_writes_to_configured_custom_field()
+ {
+ $adapter = $this->configuredNinja(customFieldName: 'snipeAssetTag');
+ $instance = SyncAdapterInstance::where('slug', 'ninjaone')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+
+ $asset = Asset::factory()->create(['asset_tag' => 'SNIPE-NIN-1234']);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => '42',
+ ]);
+
+ Http::fake(function ($request) {
+ if (str_contains($request->url(), '/ws/oauth/token')) {
+ return Http::response(['access_token' => 'stub-bearer', 'expires_in' => 3600]);
+ }
+ if ($request->method() === 'PATCH' && str_contains($request->url(), '/v2/device/42/custom-fields')) {
+ return Http::response(['ok' => true]);
+ }
+
+ return Http::response(['unmatched' => true], 500);
+ });
+
+ $adapter->push($asset);
+
+ Http::assertSent(function ($request) {
+ return $request->method() === 'PATCH'
+ && str_contains($request->url(), '/v2/device/42/custom-fields')
+ && ($request->data()['snipeAssetTag'] ?? null) === 'SNIPE-NIN-1234';
+ });
+ }
+
+ public function test_push_skips_when_custom_field_name_is_blank()
+ {
+ // Ninja has no native asset_tag, so with no custom field
+ // configured there's nothing to push to. Silently skip
+ // with an info-level log rather than error out.
+ $adapter = $this->configuredNinja(customFieldName: null);
+ $instance = SyncAdapterInstance::where('slug', 'ninjaone')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+
+ $asset = Asset::factory()->create(['asset_tag' => 'SNIPE-NIN-NO-FIELD']);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => '99',
+ ]);
+
+ Http::fake();
+
+ $adapter->push($asset);
+
+ Http::assertNothingSent();
+ }
+
+ private function configuredNinja(?string $customFieldName = null): NinjaOneAdapter
+ {
+ $instance = SyncAdapterInstance::where('slug', 'ninjaone')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'url', 'https://example.com/ninja');
+ SyncAdapterConfig::put($instance->id, 'client_id', 'stub-client');
+ SyncAdapterConfig::put($instance->id, 'client_secret', Crypt::encrypt('fake-ninja-secret'));
+ if ($customFieldName !== null) {
+ SyncAdapterConfig::put($instance->id, 'asset_tag_custom_field', $customFieldName);
+ }
+
+ return new NinjaOneAdapter($instance->fresh());
+ }
+}
diff --git a/tests/Feature/SyncAdapters/NotesComposerTest.php b/tests/Feature/SyncAdapters/NotesComposerTest.php
new file mode 100644
index 0000000000..33324bba86
--- /dev/null
+++ b/tests/Feature/SyncAdapters/NotesComposerTest.php
@@ -0,0 +1,118 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters;
+
+use App\Models\Asset;
+use App\Models\CustomField;
+use App\Models\Statuslabel;
+use App\SyncAdapters\Support\NotesComposer;
+use Tests\TestCase;
+
+/**
+ * Coverage for NotesComposer, the helper that renders composed
+ * notes blobs from Snipe-IT assets using placeholder templates.
+ * Adapters use this for push-to-notes-field flows (Intune, Kandji,
+ * Jamf, Mosyle).
+ */
+class NotesComposerTest extends TestCase
+{
+ public function test_renders_native_placeholders()
+ {
+ $status = Statuslabel::factory()->rtd()->create(['name' => 'Deployable']);
+ $asset = Asset::factory()->create([
+ 'asset_tag' => 'ABC-1234',
+ 'name' => 'workstation-01',
+ 'serial' => 'FW-ABC-123',
+ 'status_id' => $status->id,
+ ]);
+
+ $out = NotesComposer::compose(
+ $asset,
+ "Tag: {asset_tag}\nName: {name}\nSerial: {serial}\nStatus: {status}",
+ );
+
+ $this->assertSame("Tag: ABC-1234\nName: workstation-01\nSerial: FW-ABC-123\nStatus: Deployable", $out);
+ }
+
+ public function test_unknown_placeholders_render_blank()
+ {
+ $asset = Asset::factory()->create(['asset_tag' => 'ABC-1']);
+
+ $out = NotesComposer::compose(
+ $asset,
+ 'Tag: {asset_tag} | Unknown: {not_a_real_field} | End',
+ );
+
+ $this->assertSame('Tag: ABC-1 | Unknown: | End', $out);
+ }
+
+ public function test_null_native_values_render_blank_not_literal()
+ {
+ $asset = Asset::factory()->create(['asset_tag' => 'X', 'notes' => null]);
+
+ $out = NotesComposer::compose($asset, 'Notes: {notes}!');
+
+ // Null asset->notes renders as empty string, not the literal {notes}.
+ $this->assertSame('Notes: !', $out);
+ }
+
+ public function test_custom_field_placeholder_resolves_by_name()
+ {
+ $customField = CustomField::factory()->create([
+ 'element' => 'text',
+ 'name' => 'Cost Center',
+ ]);
+ $asset = Asset::factory()->create(['asset_tag' => 'CC-1']);
+ // Custom fields are stored on the asset via db_column.
+ $asset->setAttribute($customField->db_column, 'FINANCE-42');
+ $asset->save();
+
+ $out = NotesComposer::compose($asset, 'CC: {custom.Cost Center}');
+
+ $this->assertSame('CC: FINANCE-42', $out);
+ }
+
+ public function test_custom_field_with_unknown_name_renders_blank()
+ {
+ $asset = Asset::factory()->create(['asset_tag' => 'X']);
+
+ $out = NotesComposer::compose($asset, 'Missing: {custom.Nonexistent Field}!');
+
+ $this->assertSame('Missing: !', $out);
+ }
+
+ public function test_blank_template_returns_empty_string()
+ {
+ $asset = Asset::factory()->create();
+
+ $this->assertSame('', NotesComposer::compose($asset, ''));
+ $this->assertSame('', NotesComposer::compose($asset, " \n\t"));
+ }
+
+ public function test_composed_intune_style_template_matches_brady_script_shape()
+ {
+ // Sanity check that a template shaped like Brady Widener's
+ // community PowerShell (asset tag + status + checkout info)
+ // composes cleanly. That's the canonical Intune push use case.
+ $status = Statuslabel::factory()->rtd()->create(['name' => 'Deployable']);
+ $asset = Asset::factory()->create([
+ 'asset_tag' => 'IT-42',
+ 'status_id' => $status->id,
+ 'last_checkout' => '2026-01-15 10:00:00',
+ ]);
+
+ $template = <<<'TPL'
+ [INFO FROM SNIPE-IT]
+ Asset Tag: {asset_tag}
+ Status: {status}
+ Assigned to: {assigned_to}
+ Last checkout: {last_checkout}
+ TPL;
+
+ $out = NotesComposer::compose($asset, $template);
+
+ $this->assertStringContainsString('Asset Tag: IT-42', $out);
+ $this->assertStringContainsString('Status: Deployable', $out);
+ $this->assertStringContainsString('Last checkout: 2026-01-15', $out);
+ }
+}
diff --git a/tests/Feature/SyncAdapters/WorkspaceOne/WorkspaceOneComposedNotesPushTest.php b/tests/Feature/SyncAdapters/WorkspaceOne/WorkspaceOneComposedNotesPushTest.php
new file mode 100644
index 0000000000..6791daa8c3
--- /dev/null
+++ b/tests/Feature/SyncAdapters/WorkspaceOne/WorkspaceOneComposedNotesPushTest.php
@@ -0,0 +1,123 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters\WorkspaceOne;
+
+use App\Models\Asset;
+use App\Models\AssetExternalSource;
+use App\Models\Statuslabel;
+use App\Models\SyncAdapterConfig;
+use App\Models\SyncAdapterInstance;
+use App\SyncAdapters\WorkspaceOne\WorkspaceOneAdapter;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+/**
+ * Coverage for Workspace ONE composed-notes push. WS1 has no built-in
+ * device-level notes field, so composed notes get written to an
+ * admin-named Custom Attribute via a separate POST endpoint
+ * (/customattributes) from the top-level AssetNumber PUT.
+ */
+class WorkspaceOneComposedNotesPushTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Statuslabel::factory()->rtd()->create();
+ }
+
+ public function test_push_fires_both_endpoints_when_asset_tag_and_notes_configured()
+ {
+ $instance = SyncAdapterInstance::where('slug', 'workspace_one')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'url', 'https://example.com/ws1');
+ SyncAdapterConfig::put($instance->id, 'tenant_code', 'stub');
+ SyncAdapterConfig::put($instance->id, 'client_id', 'stub');
+ SyncAdapterConfig::put($instance->id, 'client_secret', Crypt::encrypt('secret'));
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+ SyncAdapterConfig::put($instance->id, 'push_notes_template', 'Tag: {asset_tag}');
+ SyncAdapterConfig::put($instance->id, 'push_notes_target', 'SnipeInfo');
+
+ $adapter = new WorkspaceOneAdapter($instance->fresh());
+
+ $asset = Asset::factory()->create(['asset_tag' => 'WS1-42']);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => 'ws1-uuid-42',
+ ]);
+
+ Http::fake(function ($request) {
+ if (str_contains($request->url(), '/connect/token')) {
+ return Http::response(['access_token' => 'stub', 'expires_in' => 3600]);
+ }
+
+ return Http::response(['ok' => true]);
+ });
+
+ $adapter->push($asset);
+
+ // Top-level device PUT for AssetNumber.
+ Http::assertSent(function ($request) {
+ return $request->method() === 'PUT'
+ && str_contains($request->url(), '/api/mdm/devices/ws1-uuid-42')
+ && ! str_contains($request->url(), 'customattributes')
+ && ($request->data()['AssetNumber'] ?? null) === 'WS1-42';
+ });
+
+ // Separate POST for the Custom Attribute.
+ Http::assertSent(function ($request) {
+ if ($request->method() !== 'POST') {
+ return false;
+ }
+ if (! str_contains($request->url(), '/api/mdm/devices/ws1-uuid-42/customattributes')) {
+ return false;
+ }
+ $attr = $request->data()['CustomAttributes'][0] ?? null;
+
+ return $attr !== null
+ && $attr['Name'] === 'SnipeInfo'
+ && $attr['Value'] === 'Tag: WS1-42';
+ });
+ }
+
+ public function test_composed_notes_only_skips_the_top_level_put()
+ {
+ $instance = SyncAdapterInstance::where('slug', 'workspace_one')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'url', 'https://example.com/ws1');
+ SyncAdapterConfig::put($instance->id, 'tenant_code', 'stub');
+ SyncAdapterConfig::put($instance->id, 'client_id', 'stub');
+ SyncAdapterConfig::put($instance->id, 'client_secret', Crypt::encrypt('secret'));
+ // No direction.asset_tag = 'push' -> AssetNumber not pushed
+ SyncAdapterConfig::put($instance->id, 'push_notes_template', 'Just notes');
+ SyncAdapterConfig::put($instance->id, 'push_notes_target', 'SnipeInfo');
+
+ $adapter = new WorkspaceOneAdapter($instance->fresh());
+
+ $asset = Asset::factory()->create(['asset_tag' => 'WS1-88']);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => 'ws1-uuid-88',
+ ]);
+
+ Http::fake(function ($request) {
+ if (str_contains($request->url(), '/connect/token')) {
+ return Http::response(['access_token' => 'stub', 'expires_in' => 3600]);
+ }
+
+ return Http::response(['ok' => true]);
+ });
+
+ $adapter->push($asset);
+
+ Http::assertNotSent(function ($request) {
+ return $request->method() === 'PUT'
+ && str_contains($request->url(), '/api/mdm/devices/ws1-uuid-88')
+ && ! str_contains($request->url(), 'customattributes');
+ });
+ Http::assertSent(function ($request) {
+ return $request->method() === 'POST'
+ && str_contains($request->url(), '/api/mdm/devices/ws1-uuid-88/customattributes');
+ });
+ }
+}
diff --git a/tests/Feature/SyncAdapters/WorkspaceOne/WorkspaceOnePushTest.php b/tests/Feature/SyncAdapters/WorkspaceOne/WorkspaceOnePushTest.php
new file mode 100644
index 0000000000..b2be14e7c6
--- /dev/null
+++ b/tests/Feature/SyncAdapters/WorkspaceOne/WorkspaceOnePushTest.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace Tests\Feature\SyncAdapters\WorkspaceOne;
+
+use App\Models\Asset;
+use App\Models\AssetExternalSource;
+use App\Models\Statuslabel;
+use App\Models\SyncAdapterConfig;
+use App\Models\SyncAdapterInstance;
+use App\SyncAdapters\PushableAdapter;
+use App\SyncAdapters\WorkspaceOne\WorkspaceOneAdapter;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Http;
+use Tests\TestCase;
+
+/**
+ * End-to-end coverage for the Workspace ONE push path. AssetNumber
+ * is WS1's native asset_tag equivalent (top-level string field on
+ * the device record), so the push shape is a simple JSON PUT.
+ */
+class WorkspaceOnePushTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ Statuslabel::factory()->rtd()->create();
+ }
+
+ public function test_workspace_one_adapter_implements_pushable_interface()
+ {
+ $this->assertInstanceOf(PushableAdapter::class, $this->configuredWs1());
+ }
+
+ public function test_push_asset_tag_puts_asset_number_field()
+ {
+ $adapter = $this->configuredWs1();
+ $instance = SyncAdapterInstance::where('slug', 'workspace_one')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'direction.asset_tag', 'push');
+
+ $asset = Asset::factory()->create(['asset_tag' => 'SNIPE-WS1-1234']);
+ AssetExternalSource::create([
+ 'asset_id' => $asset->id,
+ 'source' => $adapter->name(),
+ 'external_id' => 'ws1-uuid-42',
+ ]);
+
+ Http::fake(function ($request) {
+ if (str_contains($request->url(), '/connect/token')) {
+ return Http::response(['access_token' => 'stub-bearer', 'expires_in' => 3600]);
+ }
+ if ($request->method() === 'PUT' && str_contains($request->url(), '/api/mdm/devices/ws1-uuid-42')) {
+ return Http::response(['ok' => true]);
+ }
+
+ return Http::response(['unmatched' => true], 500);
+ });
+
+ $adapter->push($asset);
+
+ Http::assertSent(function ($request) {
+ return $request->method() === 'PUT'
+ && str_contains($request->url(), '/api/mdm/devices/ws1-uuid-42')
+ && ($request->data()['AssetNumber'] ?? null) === 'SNIPE-WS1-1234';
+ });
+ }
+
+ private function configuredWs1(): WorkspaceOneAdapter
+ {
+ $instance = SyncAdapterInstance::where('slug', 'workspace_one')->firstOrFail();
+ SyncAdapterConfig::put($instance->id, 'url', 'https://example.com/ws1');
+ SyncAdapterConfig::put($instance->id, 'tenant_code', 'stub-tenant');
+ SyncAdapterConfig::put($instance->id, 'client_id', 'stub-client');
+ SyncAdapterConfig::put($instance->id, 'client_secret', Crypt::encrypt('fake-ws1-secret'));
+
+ return new WorkspaceOneAdapter($instance->fresh());
+ }
+}