const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { test } = require('node:test');

const { collectBuiltAssets, isAndroidReleaseAsset } = require('./gitea-release');

test('isAndroidReleaseAsset matches apk files only', () => {
  assert.equal(isAndroidReleaseAsset('/tmp/Toju-1.0.5-android-debug.apk'), true);
  assert.equal(isAndroidReleaseAsset('/tmp/notes.txt'), false);
});

test('collectBuiltAssets includes apk files from dist-android', () => {
  const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gitea-release-'));
  const distAndroid = path.join(tempDir, 'dist-android');

  fs.mkdirSync(distAndroid);
  const apkPath = path.join(distAndroid, 'Toju-1.0.5-android-debug.apk');
  fs.writeFileSync(apkPath, 'apk');

  const files = collectBuiltAssets({
    'dist-android': distAndroid,
    'dist-electron': path.join(tempDir, 'missing-electron'),
    'dist-server': path.join(tempDir, 'missing-server')
  });

  assert.deepEqual(files, [apkPath]);
});
