import test from 'zopf'
import proxyquire from 'proxyquire'
import assign from 'object-assign'

import electron from './stubs/electron'

let setup = t => {
  let os = {}

  let stubs = assign({
    './os': os
  }, electron)

  let updater = proxyquire('../app/util/auto-updater', stubs)
  return assign({updater, os}, electron)
}

test('updater should be bypassed on darwin', t => {
  let {os, updater} = setup(t)
  t.stub(os, 'platform').returns('darwin')
  t.false(updater.run(), 'returns false')
})

test('updater should be bypassed on linux', t => {
  let {os, updater} = setup(t)
  t.stub(os, 'platform').returns('linux')
  t.false(updater.run(), 'returns false')
})

test(`auto-updater/win32 should noop if no squirrel cli args`, t => {
  let {os, updater} = setup(t)
  t.stub(os, 'platform').returns('win32')
  t.false(updater.run(), 'returns false')
})

;['install', 'updated', 'uninstall', 'obsolete'].forEach((action) => {
  test(`auto-updater/win32 should quit on ${action}`, t => {
    let {os, app, updater} = setup(t)
    t.stub(os, 'platform').returns('win32')
    t.stub(os, 'cli_args').returns(['hi mom', `--squirrel-${action}`])
    t.mock(app).expects('quit').once()
    t.true(updater.run(), 'returns true')
  })
})

@@ -334,32 +334,45 @@
 st('
+auto-
 updater
- should be bypass
+', t =%3E %7B%0A  t.case('stubb
 ed o
@@ -381,32 +381,34 @@
 darwin', t =%3E %7B%0A
+  
   let %7Bos, updat
@@ -414,32 +414,34 @@
 ter%7D = setup(t)%0A
+  
   t.stub(os, 'pl
@@ -465,24 +465,26 @@
 'darwin')%0A  
+ 
+ 
 t.false(upda
@@ -515,36 +515,24 @@
 e')%0A
+  
 %7D)%0A%0A
-test('updater should be 
+  t.case('
 bypa
@@ -548,32 +548,34 @@
 inux', t =%3E %7B%0A  
+ 
+ 
 let %7Bos, updater
@@ -579,32 +579,34 @@
 ter%7D = setup(t)%0A
+  
   t.stub(os, 'pl
@@ -631,16 +631,18 @@
 linux')%0A
+  
   t.fals
@@ -671,24 +671,29 @@
 rns false')%0A
+  %7D)%0A
 %7D)%0A%0Atest(%60au
@@ -685,25 +685,25 @@
 %7D)%0A%7D)%0A%0Atest(
-%60
+'
 auto-updater
@@ -708,24 +708,36 @@
 er/win32
- should 
+', t =%3E %7B%0A  t.case(%60
 noop if 
@@ -753,15 +753,14 @@
 el c
-li args
+ommand
 %60, t
@@ -763,24 +763,26 @@
 %60, t =%3E %7B%0A  
+ 
+ 
 let %7Bos, upd
@@ -798,16 +798,18 @@
 etup(t)%0A
+  
   t.stub
@@ -842,16 +842,18 @@
 win32')%0A
+  
   t.fals
@@ -886,20 +886,24 @@
 false')%0A
+  
 %7D)%0A%0A
+  
 ;%5B'insta
@@ -971,40 +971,18 @@
 %7B%0A  
-test(%60auto-updater/win32 should 
+  t.case(%60
 quit
@@ -1000,32 +1000,34 @@
 n%7D%60, t =%3E %7B%0A    
+ 
+ 
 let %7Bos, app, up
@@ -1036,32 +1036,34 @@
 ter%7D = setup(t)%0A
+  
     t.stub(os, '
@@ -1086,24 +1086,26 @@
 ns('win32')%0A
+  
     t.stub(o
@@ -1167,16 +1167,18 @@
 %60%5D)%0A    
+  
 t.mock(a
@@ -1208,16 +1208,18 @@
 e()%0A    
+ 
+ 
 t.true(u
@@ -1244,20 +1244,27 @@
 urns true')%0A
+    %7D)%0A
   %7D)%0A%7D)%0A

Use t.case in auto-updater-spec