import Bacon from 'baconjs'
import { expect } from 'chai'
import { expectation } from 'sinon'
import startServiceOrTakeRunning from  '../../lib/deploy-to-tutum/start-service-or-take-running'

describe('deploy to tutum', function () {
  describe('start service or take running', function () {
    it('should start a service that succeeds and has before', function (done) {
      let service = {
        resource_uri: '/api/v1/service/74352707-0c01-4b3a-8024-ed2334ad81f2/',
        state: 'Running'
      }

      let fakeTutum = {}
      fakeTutum.startService = expectation.create('startService')
        .once()
        .returns(Promise.resolve({
          resource_uri: service.resource_uri,
          state: 'Starting'
        }))

      let fakeTutumStream = Bacon.once({
        resource_uri: service.resource_uri,
        state: 'Running'
      })

      startServiceOrTakeRunning(service, fakeTutum, fakeTutumStream)
        .onValue((isSuccessful) => {
          expect(isSuccessful).to.be.true
          fakeTutum.startService.verify()
          done()
        })
    })

    it('should take a running service start that succeeds', function (done) {
      let service = {
        resource_uri: '/api/v1/service/74352707-0c01-4b3a-8024-ed2334ad81f2/',
        state: 'Starting'
      }

      let fakeTutum = {}
      fakeTutum.startService = expectation.create('startService').never()

      let fakeTutumStream = Bacon.once({
        resource_uri: service.resource_uri,
        state: 'Running'
      })

      startServiceOrTakeRunning(service, fakeTutum, fakeTutumStream)
        .onValue((isSuccessful) => {
          expect(isSuccessful).to.be.true
          fakeTutum.startService.verify()
          done()
        })
    })

    it('should start a service that fails and has before', function (done) {
      let service = {
        resource_uri: '/api/v1/service/74352707-0c01-4b3a-8024-ed2334ad81f2/',
        state: 'Stopped'
      }

      let fakeTutum = {}
      fakeTutum.startService = expectation.create('startService')
        .once()
        .returns(Promise.resolve({
          resource_uri: service.resource_uri,
          state: 'Starting'
        }))

      let fakeTutumStream = Bacon.once({
        resource_uri: service.resource_uri,
        state: 'Stopped'
      })

      startServiceOrTakeRunning(service, fakeTutum, fakeTutumStream)
        .onValue((isSuccessful) => {
          expect(isSuccessful).to.be.false
          fakeTutum.startService.verify()
          done()
        })
    })

    it('should take a running service start that fails', function (done) {
      let service = {
        resource_uri: '/api/v1/service/74352707-0c01-4b3a-8024-ed2334ad81f2/',
        state: 'Starting'
      }

      let fakeTutum = {}
      fakeTutum.startService = expectation.create('startService').never()

      let fakeTutumStream = Bacon.once({
        resource_uri: service.resource_uri,
        state: 'Stopped'
      })

      startServiceOrTakeRunning(service, fakeTutum, fakeTutumStream)
        .onValue((isSuccessful) => {
          expect(isSuccessful).to.be.false
          fakeTutum.startService.verify()
          done()
        })
    })
  })
})

@@ -2577,16 +2577,45 @@
 at fails
+ after 6s long false positive
 ', funct
@@ -2904,32 +2904,34 @@
 .once(%7B%0A        
+  
 resource_uri: se
@@ -2942,32 +2942,153 @@
 e.resource_uri,%0A
+          state: 'Running'%0A        %7D)%0A        .merge(Bacon.later(6000, %7B%0A          resource_uri: service.resource_uri,%0A  
         state: '
@@ -3094,33 +3094,36 @@
 'Stopped'%0A      
-%7D
+  %7D)
 )%0A%0A      startSe

Add a false positivity test while starting service