/* global describe, it, xit */
/* jslint node: true, esnext: true */

'use strict';

const chai = require('chai'),
  expect = chai.expect,
  assert = chai.assert,
  should = chai.should(),
  SVNHTTPSScheme = require('../dist/svn').SVNHTTPSScheme;

chai.use(require('chai-datetime'));

const credentials = {
  password: 'xxx',
  user: 'yyy'
};

if (process.env.SVN_USER) {
  credentials.user = process.env.SVN_USER;
}

if (process.env.SVN_PASSWORD) {
  credentials.password = process.env.SVN_PASSWORD;
}

describe('svn', () => {

  const svn = new SVNHTTPSScheme({
    proxy: process.env.HTTP_PROXY,
    credentials: credentials
  });

  it('has type', () => assert.equal(svn.type, 'svn+https'));

  /*
    const init = svn.initialize();

    if (process.env.SVN_USER) {
      it('has davFeatures', () =>
        init.then(svn => {
          assert.equal(svn.davFeatures.has('1'), true);
          assert.equal(svn.davFeatures.has('2'), true);
          assert.equal(svn.davFeatures.has('baseline'), true);
          assert.equal(svn.davFeatures.has('version-control'), true);
          assert.equal(svn.davFeatures.has('checkout'), true);
          assert.equal(svn.davFeatures.has('working-resource'), true);
          assert.equal(svn.davFeatures.has('merge'), true);
          assert.equal(svn.davFeatures.has('version-controlled-collection'), true);
          assert.equal(svn.davFeatures.has('http://subversion.tigris.org/xmlns/dav/svn/mergeinfo'), true);
        })
      );

      it('has allowedMethods', () =>
        init.then(svn => {
          assert.equal(svn.allowedMethods.has('GET'), true);
          assert.equal(svn.allowedMethods.has('OPTIONS'), true);
        })
      );
    }
  */

  if (process.env.SVN_USER) {
    describe('activityCollectionSet', () => {

      xit('attributes', () => svn.activityCollectionSet('https://subversion.assembla.com/svn/delivery_notes/')
        .then(({
          attributes
        }) => assert.deepEqual(attributes, {
          'SVN-Youngest-Rev': 17
        })));
    });

    xit('put', () =>
      svn.put('https://subversion.assembla.com/svn/delivery_notes/', undefined, {
        message: 'this is the message'
      })
    );

    it('stat', () =>
      svn.stat('https://subversion.assembla.com/svn/delivery_notes/data/environments.json').then(stat => assert.deepEqual(
        stat, {
          creationDate: new Date('2016-01-30T13:36:16.649803Z'),
          size: 114,
          creator: 'arlac77',
          version: 1481
        }))
    );

    it('history', () =>
      svn.history('https://subversion.assembla.com/svn/delivery_notes/', {
        version: 0,
        chunkSize: 10
      }).then(cursor => {
        let i = 0;

        for (const e of cursor()) {
          e.then(entry => {
            //console.log(entry);
            if (i === 0) {
              assert.equal(entry.version, 0);
              assert.afterDate(entry.date, new Date(2011, 1, 1));
              assert.beforeDate(entry.date, new Date(2015, 1, 1));
              assert.include(entry.message, 'Automatically created readme.textile');
            }
            i++;
          });
        }
      }).catch(console.log));

    it('list', () =>
      svn.list('https://subversion.assembla.com/svn/delivery_notes/data').then(
        entries => {
          assert.include(entries.map(e => e.name), 'releases.json');
          assert.include(entries.map(e => e.name), 'comp1');
          assert.include(entries.map(e => e.name), 'releases');
          assert.include(entries.map(e => e.name), 'servers');
          assert.include(entries.map(e => e.name), 'config.json');
          assert.include(entries.map(e => e.name), 'environments.json');
        }));
  }
});

@@ -2194,36 +2194,62 @@
  it('stat', 
+async
 () =%3E
+ %7B
 %0A      
+const stat = await 
 svn.stat('ht
@@ -2325,21 +2325,15 @@
 on')
-.then(stat =%3E
+;%0A     
  ass
@@ -2513,22 +2513,23 @@
       %7D)
-)
+;
 %0A    
+%7D
 );%0A%0A    
@@ -3197,35 +3197,64 @@
  it('list', 
+async
 () =%3E
-%0A
+ %7B%0A 
      
+const entries = await
  svn.list('h
@@ -3313,40 +3313,10 @@
 ta')
-.then(%0A        entries =%3E %7B%0A    
+;%0A
     
@@ -3368,36 +3368,32 @@
 eleases.json');%0A
-    
       assert.inc
@@ -3431,36 +3431,32 @@
 'comp1');%0A      
-    
 assert.include(e
@@ -3491,36 +3491,32 @@
 leases');%0A      
-  
-  
 assert.include(e
@@ -3550,36 +3550,32 @@
 ervers');%0A      
-   
- 
 assert.include(e
@@ -3611,28 +3611,24 @@
 fig.json');%0A
-    
       assert
@@ -3688,22 +3688,17 @@
 ');%0A    
-    %7D)
+%7D
 );%0A  %7D%0A%7D

use async/await