UNPKG

1.91 kBJavaScriptView Raw
1// Dependencies
2var format = require('../lib/utils/format');
3 vows = require('vows'),
4 assert = require('assert');
5
6//nock.recorder.rec();
7
8// Suite Test
9
10var suite = vows.describe('Solr Client Utilities');
11
12suite.addBatch({
13 'format' : {
14 'dateISOify()' : {
15 'when an array is used' : {
16 topic : function() {
17 return format.dateISOify([
18 {
19 id: 1,
20 date1: new Date()
21 },
22 {
23 id: 2,
24 date1: new Date()
25 }
26 ]);
27 },
28 'it should replace all nested date objects with strings' : function(list) {
29 assert.equal(typeof list[0].date1, "string");
30 assert.equal(typeof list[1].date1, "string");
31 }
32 },
33 'when an object is used' : {
34 topic : function() {
35 return format.dateISOify({
36 id: 1,
37 date1: new Date()
38 });
39 },
40 'it should replace all nested date objects with strings' : function(doc) {
41 assert.equal(typeof doc.date1, "string");
42 }
43 },
44 'when a date object itself is used' : {
45 topic : function() {
46 return format.dateISOify(new Date());
47 },
48 'it should return a string' : function (date) {
49 assert.equal(typeof date, "string");
50 }
51 }
52 },
53 'toISOString()' : {
54 'when invalid date objects are found' : {
55 topic : function() {
56 return format.toISOString(new Date("0000-00-00"));
57 },
58 'it should be replaced by null' : function(date){
59 assert.strictEqual(date, null);
60 }
61 }
62 }
63 }
64}).export(module);