/* global Blob */

var createTorrent = require('../../')
var fixtures = require('webtorrent-fixtures')
var fs = require('fs')
var parseTorrent = require('parse-torrent')
var path = require('path')
var sha1 = require('simple-sha1')
var test = require('tape')

function makeFileShim (buf, name, fullPath) {
  var file = new Blob([ buf ])
  file.fullPath = fullPath
  file.name = name
  return file
}

var numbers1 = makeFileShim(fs.readFileSync(path.join(fixtures.numbers.contentPath, '1.txt'), 'utf8'), '1.txt', '/numbers/1.txt')
var numbers2 = makeFileShim(fs.readFileSync(path.join(fixtures.numbers.contentPath, '2.txt'), 'utf8'), '2.txt', '/numbers/2.txt')
var numbers3 = makeFileShim(fs.readFileSync(path.join(fixtures.numbers.contentPath, '3.txt'), 'utf8'), '3.txt', '/numbers/3.txt')
var DSStore = makeFileShim('blah', '.DS_Store', '/numbers/.DS_Store') // this should be ignored

test('create multi file torrent with directory at root', function (t) {
  t.plan(15)

  var startTime = Date.now()
  createTorrent([ numbers1, numbers2, numbers3, DSStore ], function (err, torrent) {
    t.error(err)

    var parsedTorrent = parseTorrent(torrent)

    t.equals(parsedTorrent.name, 'numbers')

    t.notOk(parsedTorrent.private)

    t.ok(parsedTorrent.created.getTime() >= startTime, 'created time is after start time')

    t.ok(Array.isArray(parsedTorrent.announce))

    t.deepEquals(parsedTorrent.files[0].path, 'numbers/1.txt')
    t.deepEquals(parsedTorrent.files[0].length, 1)

    t.deepEquals(parsedTorrent.files[1].path, 'numbers/2.txt')
    t.deepEquals(parsedTorrent.files[1].length, 2)

    t.deepEquals(parsedTorrent.files[2].path, 'numbers/3.txt')
    t.deepEquals(parsedTorrent.files[2].length, 3)

    t.equal(parsedTorrent.length, 6)
    t.equal(parsedTorrent.info.pieces.length, 20)

    t.deepEquals(parsedTorrent.pieces, [
      '1f74648e50a6a6708ec54ab327a163d5536b7ced'
    ])

    t.equals(sha1.sync(parsedTorrent.infoBuffer), '89d97c2261a21b040cf11caa661a3ba7233bb7e6')
  })
})

@@ -54,54 +54,8 @@
 /')%0A
-var fixtures = require('webtorrent-fixtures')%0A
 var 
@@ -73,16 +73,16 @@
 e('fs')%0A
+
 var pars
@@ -404,39 +404,76 @@
 oin(
-fixtures.numbers.contentPath, '
+__dirname, '../../node_modules/webtorrent-fixtures/fixtures/numbers/
 1.tx
@@ -488,33 +488,32 @@
 f8'), '1.txt', '
-/
 numbers/1.txt')%0A
@@ -570,39 +570,76 @@
 oin(
-fixtures.numbers.contentPath, '
+__dirname, '../../node_modules/webtorrent-fixtures/fixtures/numbers/
 2.tx
@@ -654,33 +654,32 @@
 f8'), '2.txt', '
-/
 numbers/2.txt')%0A
@@ -736,39 +736,76 @@
 oin(
-fixtures.numbers.contentPath, '
+__dirname, '../../node_modules/webtorrent-fixtures/fixtures/numbers/
 3.tx
@@ -824,25 +824,24 @@
 , '3.txt', '
-/
 numbers/3.tx
@@ -840,24 +840,25 @@
 ers/3.txt')%0A
+%0A
 var DSStore 

fix errors