import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';

import {
  describe,
  expect,
  it
} from 'vitest';

import { ANDROID_REQUIRED_MANIFEST_PERMISSIONS, findMissingAndroidManifestPermissions } from './mobile-android-manifest-permissions.rules';

describe('mobile-android-manifest-permissions.rules', () => {
  it('requires MODIFY_AUDIO_SETTINGS so Capacitor WebView audio grants succeed', () => {
    expect(ANDROID_REQUIRED_MANIFEST_PERMISSIONS).toContain('android.permission.MODIFY_AUDIO_SETTINGS');
  });

  it('declares every required permission in the Android app manifest', () => {
    const manifestPath = resolve(process.cwd(), 'android/app/src/main/AndroidManifest.xml');
    const manifestXml = readFileSync(manifestPath, 'utf8');
    const missing = findMissingAndroidManifestPermissions(manifestXml);

    expect(missing).toEqual([]);
  });
});
