import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = dirname(fileURLToPath(import.meta.url));
const root = resolve(__dirname, '..');

function readSource(path) {
  return readFileSync(resolve(root, path), 'utf8');
}

test('driver app sends Android device metadata during OTP verification', () => {
  const models = readSource('app/src/main/java/pl/firmatpp/kierowca/data/model/DriverModels.kt');
  const repository = readSource('app/src/main/java/pl/firmatpp/kierowca/data/DriverRepository.kt');
  const deviceInfo = readSource('app/src/main/java/pl/firmatpp/kierowca/data/DeviceInfoProvider.kt');

  assert.match(models, /data class DriverDeviceInfo/);
  assert.match(models, /val device: DriverDeviceInfo/);
  assert.match(repository, /DeviceInfoProvider/);
  assert.match(repository, /deviceInfoProvider\.currentDeviceInfo/);
  assert.match(deviceInfo, /Settings\.Secure\.ANDROID_ID/);
  assert.match(deviceInfo, /Build\.MANUFACTURER/);
  assert.match(deviceInfo, /Build\.MODEL/);
  assert.match(deviceInfo, /BuildConfig\.VERSION_NAME/);
});
