mock(ActiveDirectory::class)->shouldReceive('users')->once()->andReturn([ ['guid' => '00112233-4455-6677-8899-aabbccddeeff', 'email' => 'missing@example.test', 'name' => 'Missing', 'enabled' => true], ]); $this->artisan('ad:sync --email')->assertSuccessful(); expect(User::count())->toBe(0); }); it('matches an existing Laravel user by email without creating a new user', function () { $user = User::factory()->create(['email' => 'existing@example.test']); $this->mock(ActiveDirectory::class)->shouldReceive('users')->once()->andReturn([ ['guid' => '00112233-4455-6677-8899-aabbccddeeff', 'email' => 'existing@example.test', 'name' => 'Existing', 'enabled' => false], ]); $this->artisan('ad:sync --email')->assertSuccessful(); expect(User::count())->toBe(1) ->and($user->refresh()->ad_guid)->toBe('00112233-4455-6677-8899-aabbccddeeff') ->and($user->ad_disabled_at)->not->toBeNull(); }); it('decodes Microsoft and Samba user account control bitmasks', function () { $flags = AccountControl::flags(AccountControl::NORMAL_ACCOUNT | AccountControl::ACCOUNTDISABLE | AccountControl::DONT_EXPIRE_PASSWORD); expect($flags)->toContain('NORMAL_ACCOUNT', 'ACCOUNTDISABLE', 'DONT_EXPIRE_PASSWORD') ->not->toContain('LOCKOUT'); }); it('exposes the ActiveDirectory module and its sync command', function () { expect(file_exists(base_path('Modules/ActiveDirectory/module.json')))->toBeTrue(); $this->artisan('list')->assertSuccessful(); });