UNPKG

3.57 kBJavaScriptView Raw
1"use strict";
2
3var when = require('when')
4, helper = require('../src/helper')
5, defines = require('../src/defines')
6, assert = require('assert')
7, chai = require('chai')
8, chaiAsPromised = require('chai-as-promised');
9
10chai.Should();
11chai.use(chaiAsPromised);
12require("mocha-as-promised")();
13
14describe('helper', function() {
15
16 describe('#getOptions()', function() {
17
18 it('should return the correct defaults', function() {
19 var options = helper.getOptions();
20
21 options.should.deep.eql({
22 name: 'default_name',
23 appendString: '',
24 prependString: '',
25 headerRow: 0,
26 ignoreEmptyHeaders: false,
27 forceTypes: undefined,
28 ignoreTypes: undefined,
29 useHeaders: undefined,
30 maintainHeaders: false,
31 dataOnly: false,
32 createOnly: false,
33 insertStatements: false
34 });
35 });
36
37 it.skip('should set a name');
38 it.skip('should set an append string');
39 it.skip('should set a prepend string');
40 it.skip('should set the header row');
41 it.skip('should set ignoreEmptyHeaders');
42
43 it('should set force types (object passed in)', function() {
44
45 var options = helper.getOptions({
46 forceTypes: {
47 'foo': 'boolean',
48 'bar': 'text'
49 }
50 });
51
52 options.forceTypes.should.deep.eql({
53 'foo': defines.BOOLEAN,
54 'bar': defines.TEXT
55 });
56 });
57
58 it('should set force types (string passed in)', function() {
59 var options = helper.getOptions({
60 forceTypes: 'foo:boolean,bar:text'
61 });
62
63 options.forceTypes.should.deep.eql({
64 'foo': defines.BOOLEAN,
65 'bar': defines.TEXT
66 });
67 });
68
69 it('should set normalize strings (object)', function() {
70 var options = helper.getOptions({
71 forceTypes: {
72 'foo bar': 'boolean',
73 '0': 'text'
74 }
75 });
76
77 options.forceTypes.should.deep.eql({
78 'foo_bar': defines.BOOLEAN,
79 'column_0': defines.TEXT
80 });
81 });
82
83 it('should set force types (string)', function() {
84 var options = helper.getOptions({
85 forceTypes: 'foo bar:boolean,0:text'
86 });
87
88 options.forceTypes.should.deep.eql({
89 'foo_bar': defines.BOOLEAN,
90 'column_0': defines.TEXT
91 });
92 });
93
94 it.skip('should set ignore types');
95 it.skip('should set the headers to use');
96 it.skip('should set maintain headers');
97 it.skip('should set data only');
98 it.skip('should set create only');
99 it.skip('should set insert only');
100
101 it.only('should set xls sheet numbers', function() {
102 var options = helper.getOptions();
103 assert.equal(options.xlsSheetNumbers, undefined);
104 options = helper.getOptions({ xlsSheetNumbers: [1, 2, 3] });
105 options.xlsSheetNumbers.should.eql([1, 2 ,3]);
106 options = helper.getOptions({ xlsSheetNumbers: ['1', '2', '3'] });
107 options.xlsSheetNumbers.should.eql([1, 2 ,3]);
108 options = helper.getOptions({ xlsSheetNumbers: '1,2,3' });
109 options.xlsSheetNumbers.should.eql([1, 2 ,3]);
110 });
111
112 });
113
114 describe('#normalizeString()', function() {
115 it('should remove all surrounding whitespace', function() {
116 helper.normalizeString(" column_name ")
117 .should.equal("column_name");
118 });
119 it('should replace all spaces with underscores', function() {
120 helper.normalizeString("column name")
121 .should.equal("column_name");
122 });
123 it('should remove all characters that are not [A-Za-z09_]', function() {
124 helper.normalizeString("!#!#!#column_name@@@@@@####")
125 .should.equal("column_name");
126 });
127 });
128
129 describe('#normalizeHeader()', function() {
130 it('should replace all header names starting with a number', function() {
131 var headers = "88";
132 helper.normalizeHeader(headers).should.eql("column_88");
133 });
134 });
135
136});