'use strict';

/**
 * Test the 'line' codec in a recipe:
 */

var path = require('path');
require('chai').should();
let uut = require('../../lib/streamFromRecipe');

let recipes = [
  {
    name: 'read',
    input: {
      channel: 'gulp',
      glob: [
        path.join(__dirname, '../fixtures/file.csv'),
        path.join(__dirname, '../fixtures/file2.csv')
      ],
      opts: { buffer: false },
      codec: {
        line: {
          drop: 1
        }
      }
    },
    output: {
      channel: 'noop'
    },
    filter: [
      {
        csv: {
          columns: [
            'greeting'
          ]
        }
      }
    ]
  }
];

let connections = {};
let codecs = require('../../lib/codecs');
let channels = require('../../lib/channels')(connections, codecs, recipes);

describe('line codec in a recipe', function() {
  it('should read', function(done) {
    uut(recipes[0], connections, codecs, channels)
    .collect()
    .doto(ar => {
      ar
      .map(file => JSON.parse(String(file.contents)))
      .should.eql([
        {'greeting': 'hello'},
        {'greeting': 'bonjour'},
        {'greeting': 'howdy'},

        {'greeting': 'wotcha'},
        {'greeting': 'bona sera'}
      ]);
    })
    .done(done)
    ;
  });
});

@@ -1031,32 +1031,73 @@
 .eql(%5B%0A        %7B
+%0A          'message': 'hello',%0A          
 'greeting': 'hel
@@ -1099,16 +1099,25 @@
  'hello'
+%0A        
 %7D,%0A     
@@ -1112,32 +1112,75 @@
     %7D,%0A        %7B
+%0A          'message': 'bonjour',%0A          
 'greeting': 'bon
@@ -1184,16 +1184,25 @@
 bonjour'
+%0A        
 %7D,%0A     
@@ -1197,32 +1197,73 @@
     %7D,%0A        %7B
+%0A          'message': 'howdy',%0A          
 'greeting': 'how
@@ -1265,16 +1265,25 @@
  'howdy'
+%0A        
 %7D,%0A%0A    
@@ -1279,32 +1279,74 @@
    %7D,%0A%0A        %7B
+%0A          'message': 'wotcha',%0A          
 'greeting': 'wot
@@ -1349,16 +1349,25 @@
 'wotcha'
+%0A        
 %7D,%0A     
@@ -1370,16 +1370,61 @@
        %7B
+%0A          'message': 'bona sera',%0A          
 'greetin
@@ -1438,16 +1438,25 @@
 na sera'
+%0A        
 %7D%0A      

add failing test