'use strict';

const expect = require('chai').expect,
    Redis = require('ioredis'),
    RigidDB = require('../index');

let redisClient = new Redis({
    db: 15
});

let store;

describe('Find', function() {
    beforeEach(function() {
        return redisClient.flushdb().then(function() {
            store = new RigidDB('foo', { db: 15 });

            return store.setSchema(1, {
                cars: {
                    definition: {
                        color: { type: 'string', allowNull: true },
                        mileage: 'int',
                        convertible: 'boolean',
                        purchaseDate: 'date',
                        serviceDate: 'timestamp',
                        extra: 'string'
                    },
                    indices: {
                        first: {
                            uniq: true,
                            fields: [ 'purchaseDate', 'color' ]
                        },
                        second: {
                            uniq: false,
                            fields: [ 'color', 'mileage', 'convertible' ]
                        }
                    }
                }
            });
        }).then(function() {
            return store.create('cars', {
                color: null,
                mileage: 12345,
                convertible: true,
                purchaseDate: new Date('Sun Nov 01 2015 17:41:24 GMT+0100 (CET)'),
                serviceDate: new Date('Sun Nov 01 2015 17:41:24 GMT+0100 (CET)'),
                extra: '~'
            });
        }).then(function() {
            return store.create('cars', {
                color: 'blue',
                mileage: 12345,
                convertible: true,
                purchaseDate: new Date('Sun Nov 01 2015 22:41:24 GMT+0100 (CET)'),
                serviceDate: new Date('Sun Nov 01 2015 17:41:24 GMT+0100 (CET)'),
                extra: '~~~'
            });
        });
    });

    it('Prints collection', function() {
        console.table = function(params) { // eslint-disable-line no-console
            expect(params).to.deep.equal([
                {
                    color: '[NULL]',
                    extra: '\"~\"',
                    id: '1',
                    mileage: 12345,
                    purchaseDate: 'Sun Nov 01 2015 17:41:24 GMT+0100 (CET)',
                    serviceDate: 'Sun Nov 01 2015 17:41:24 GMT+0100 (CET)'
                }, {
                    color: '\"blue\"',
                    extra: '\"~~~\"',
                    id: '2',
                    mileage: 12345,
                    purchaseDate: 'Sun Nov 01 2015 22:41:24 GMT+0100 (CET)',
                    serviceDate: 'Sun Nov 01 2015 17:41:24 GMT+0100 (CET)'
                }
            ]);
        };


        return store.debugPrint('cars').then(function() {
        });
    });
});

@@ -2296,32 +2296,41 @@
   purchaseDate: 
+new Date(
 'Sun Nov 01 2015
@@ -2346,32 +2346,44 @@
  GMT+0100 (CET)'
+).toString()
 ,%0A              
@@ -2393,32 +2393,41 @@
    serviceDate: 
+new Date(
 'Sun Nov 01 2015
@@ -2443,32 +2443,44 @@
  GMT+0100 (CET)'
+).toString()
 %0A               
@@ -2657,24 +2657,33 @@
 rchaseDate: 
+new Date(
 'Sun Nov 01 
@@ -2711,16 +2711,28 @@
 0 (CET)'
+).toString()
 ,%0A      
@@ -2758,16 +2758,25 @@
 ceDate: 
+new Date(
 'Sun Nov
@@ -2808,16 +2808,28 @@
 0 (CET)'
+).toString()
 %0A       

Fix time sensitive test