'use strict'

const download = require('../src/download')
const unzip = require('../src/unzip')
const fs = require('fs-extra')
const config = require('./config.json')
const path = require('path')
const os = require('os')
const test = require('ava')

for (const downloadOpts of download.createDownloadCombos({ electronVersion: config.version }, ['darwin', 'mas'], ['x64'])) {
  test.serial(`unzip preserves symbolic links (${downloadOpts.platform})`, t => { return unzipPreserveSymbolicLinks(t, downloadOpts) })
}

async function unzipPreserveSymbolicLinks (t, downloadOpts) {
  const zipPath = await download.downloadElectronZip(downloadOpts)
  const tempPath = await fs.mkdtemp(path.join(os.tmpdir(), 'symlinktest-'))

  await unzip(zipPath, tempPath)

  const testSymlinkPath = path.join(tempPath, 'Electron.app/Contents/Frameworks/Electron Framework.framework/Libraries')
  const stat = await fs.lstat(testSymlinkPath)
  t.true(stat.isSymbolicLink(), 'extract symoblic links')
}

'use strict'

const { assertSymlink } = require('./_util')
const config = require('./config.json')
const download = require('../src/download')
const path = require('path')
const test = require('ava')
const unzip = require('../src/unzip')

test('unzip preserves symbolic links', async t => {
  const downloadOpts = download.createDownloadOpts({ electronVersion: config.version }, 'darwin', 'x64')
  const zipPath = await download.downloadElectronZip(downloadOpts)

  await unzip(zipPath, t.context.tempDir)

  await assertSymlink(t, path.join(t.context.tempDir, 'Electron.app/Contents/Frameworks/Electron Framework.framework/Libraries'), 'symbolic link extracted correctly')
})

refactor for efficiency and readability