11var Backend = require ( '../../lib/backend' ) ;
22var expect = require ( 'chai' ) . expect ;
3- var util = require ( '../util' ) ;
43var lolex = require ( 'lolex' ) ;
54var MemoryDb = require ( '../../lib/db/memory' ) ;
65var MemoryMilestoneDb = require ( '../../lib/milestone-db/memory' ) ;
76var sinon = require ( 'sinon' ) ;
7+ var async = require ( 'async' ) ;
88
99describe ( 'SnapshotTimestampRequest' , function ( ) {
1010 var backend ;
@@ -70,112 +70,95 @@ describe('SnapshotTimestampRequest', function() {
7070
7171 beforeEach ( function ( done ) {
7272 var doc = backend . connect ( ) . get ( 'books' , 'time-machine' ) ;
73- util . callInSeries ( [
74- function ( next ) {
75- doc . create ( { title : 'The Time Machine' } , next ) ;
76- } ,
73+ async . series ( [
74+ doc . create . bind ( doc , { title : 'The Time Machine' } ) ,
7775 function ( next ) {
7876 clock . tick ( ONE_DAY ) ;
7977 doc . submitOp ( { p : [ 'author' ] , oi : 'HG Wells' } , next ) ;
8078 } ,
8179 function ( next ) {
8280 clock . tick ( ONE_DAY ) ;
8381 doc . submitOp ( { p : [ 'author' ] , od : 'HG Wells' , oi : 'H.G. Wells' } , next ) ;
84- } ,
85- done
86- ] ) ;
82+ }
83+ ] , done ) ;
8784 } ) ;
8885
8986 it ( 'fetches the version at exactly day 1' , function ( done ) {
90- util . callInSeries ( [
91- function ( next ) {
92- backend . connect ( ) . fetchSnapshotByTimestamp ( 'books' , 'time-machine' , day1 , next ) ;
93- } ,
87+ var connection = backend . connect ( ) ;
88+ async . waterfall ( [
89+ connection . fetchSnapshotByTimestamp . bind ( connection , 'books' , 'time-machine' , day1 ) ,
9490 function ( snapshot , next ) {
9591 expect ( snapshot ) . to . eql ( v1 ) ;
9692 next ( ) ;
97- } ,
98- done
99- ] ) ;
93+ }
94+ ] , done ) ;
10095 } ) ;
10196
10297 it ( 'fetches the version at exactly day 2' , function ( done ) {
103- util . callInSeries ( [
104- function ( next ) {
105- backend . connect ( ) . fetchSnapshotByTimestamp ( 'books' , 'time-machine' , day2 , next ) ;
106- } ,
98+ var connection = backend . connect ( ) ;
99+ async . waterfall ( [
100+ connection . fetchSnapshotByTimestamp . bind ( connection , 'books' , 'time-machine' , day2 ) ,
107101 function ( snapshot , next ) {
108102 expect ( snapshot ) . to . eql ( v2 ) ;
109103 next ( ) ;
110- } ,
111- done
112- ] ) ;
104+ }
105+ ] , done ) ;
113106 } ) ;
114107
115108 it ( 'fetches the version at exactly day 3' , function ( done ) {
116- util . callInSeries ( [
117- function ( next ) {
118- backend . connect ( ) . fetchSnapshotByTimestamp ( 'books' , 'time-machine' , day3 , next ) ;
119- } ,
109+ var connection = backend . connect ( ) ;
110+ async . waterfall ( [
111+ connection . fetchSnapshotByTimestamp . bind ( connection , 'books' , 'time-machine' , day3 ) ,
120112 function ( snapshot , next ) {
121113 expect ( snapshot ) . to . eql ( v3 ) ;
122114 next ( ) ;
123- } ,
124- done
125- ] ) ;
115+ }
116+ ] , done ) ;
126117 } ) ;
127118
128119 it ( 'fetches the day 2 version when asking for a time halfway between days 2 and 3' , function ( done ) {
129120 var halfwayBetweenDays2and3 = ( day2 + day3 ) * 0.5 ;
130- util . callInSeries ( [
131- function ( next ) {
132- backend . connect ( ) . fetchSnapshotByTimestamp ( 'books' , 'time-machine' , halfwayBetweenDays2and3 , next ) ;
133- } ,
121+ var connection = backend . connect ( ) ;
122+ async . waterfall ( [
123+ connection . fetchSnapshotByTimestamp . bind ( connection , 'books' , 'time-machine' , halfwayBetweenDays2and3 ) ,
134124 function ( snapshot , next ) {
135125 expect ( snapshot ) . to . eql ( v2 ) ;
136126 next ( ) ;
137- } ,
138- done
139- ] ) ;
127+ }
128+ ] , done ) ;
140129 } ) ;
141130
142131 it ( 'fetches the day 3 version when asking for a time after day 3' , function ( done ) {
143- util . callInSeries ( [
144- function ( next ) {
145- backend . connect ( ) . fetchSnapshotByTimestamp ( 'books' , 'time-machine' , day4 , next ) ;
146- } ,
132+ var connection = backend . connect ( ) ;
133+ async . waterfall ( [
134+ connection . fetchSnapshotByTimestamp . bind ( connection , 'books' , 'time-machine' , day4 ) ,
147135 function ( snapshot , next ) {
148136 expect ( snapshot ) . to . eql ( v3 ) ;
149137 next ( ) ;
150- } ,
151- done
152- ] ) ;
138+ }
139+ ] , done ) ;
153140 } ) ;
154141
155142 it ( 'fetches the most recent version when not specifying a timestamp' , function ( done ) {
156- util . callInSeries ( [
157- function ( next ) {
158- backend . connect ( ) . fetchSnapshotByTimestamp ( 'books' , 'time-machine' , next ) ;
159- } ,
143+ var connection = backend . connect ( ) ;
144+ async . waterfall ( [
145+ connection . fetchSnapshotByTimestamp . bind ( connection , 'books' , 'time-machine' ) ,
160146 function ( snapshot , next ) {
161147 expect ( snapshot ) . to . eql ( v3 ) ;
162148 next ( ) ;
163- } ,
164- done
165- ] ) ;
149+ }
150+ ] , done ) ;
166151 } ) ;
167152
168153 it ( 'fetches an empty snapshot if the timestamp is before the document creation' , function ( done ) {
169- util . callInSeries ( [
170- function ( next ) {
171- backend . connect ( ) . fetchSnapshotByTimestamp ( 'books' , 'time-machine' , day0 , next ) ;
172- } ,
154+ var connection = backend . connect ( ) ;
155+ async . waterfall ( [
156+ connection . fetchSnapshotByTimestamp . bind ( connection , 'books' , 'time-machine' , day0 ) ,
173157 function ( snapshot , next ) {
174158 expect ( snapshot ) . to . eql ( v0 ) ;
175159 next ( ) ;
176- } ,
177- done
178- ] ) ;
160+ }
161+ ] , done ) ;
179162 } ) ;
180163
181164 it ( 'throws if the timestamp is undefined' , function ( ) {
@@ -407,10 +390,8 @@ describe('SnapshotTimestampRequest', function() {
407390
408391 var doc = backendWithMilestones . connect ( ) . get ( 'books' , 'mocking-bird' ) ;
409392
410- util . callInSeries ( [
411- function ( next ) {
412- doc . create ( { title : 'To Kill a Mocking Bird' } , next ) ;
413- } ,
393+ async . series ( [
394+ doc . create . bind ( doc , { title : 'To Kill a Mocking Bird' } ) ,
414395 function ( next ) {
415396 clock . tick ( ONE_DAY ) ;
416397 doc . submitOp ( { p : [ 'author' ] , oi : 'Harper Lea' } , next ) ;
@@ -426,9 +407,8 @@ describe('SnapshotTimestampRequest', function() {
426407 function ( next ) {
427408 clock . tick ( ONE_DAY ) ;
428409 doc . submitOp ( { p : [ 'year' ] , od : 1959 , oi : 1960 } , next ) ;
429- } ,
430- done
431- ] ) ;
410+ }
411+ ] , done ) ;
432412 } ) ;
433413
434414 it ( 'fetches a snapshot between two milestones using the milestones' , function ( done ) {
0 commit comments