1
1
var Backend = require ( '../../lib/backend' ) ;
2
2
var expect = require ( 'chai' ) . expect ;
3
- var util = require ( '../util' ) ;
4
3
var lolex = require ( 'lolex' ) ;
5
4
var MemoryDb = require ( '../../lib/db/memory' ) ;
6
5
var MemoryMilestoneDb = require ( '../../lib/milestone-db/memory' ) ;
7
6
var sinon = require ( 'sinon' ) ;
7
+ var async = require ( 'async' ) ;
8
8
9
9
describe ( 'SnapshotTimestampRequest' , function ( ) {
10
10
var backend ;
@@ -70,112 +70,95 @@ describe('SnapshotTimestampRequest', function() {
70
70
71
71
beforeEach ( function ( done ) {
72
72
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' } ) ,
77
75
function ( next ) {
78
76
clock . tick ( ONE_DAY ) ;
79
77
doc . submitOp ( { p : [ 'author' ] , oi : 'HG Wells' } , next ) ;
80
78
} ,
81
79
function ( next ) {
82
80
clock . tick ( ONE_DAY ) ;
83
81
doc . submitOp ( { p : [ 'author' ] , od : 'HG Wells' , oi : 'H.G. Wells' } , next ) ;
84
- } ,
85
- done
86
- ] ) ;
82
+ }
83
+ ] , done ) ;
87
84
} ) ;
88
85
89
86
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 ) ,
94
90
function ( snapshot , next ) {
95
91
expect ( snapshot ) . to . eql ( v1 ) ;
96
92
next ( ) ;
97
- } ,
98
- done
99
- ] ) ;
93
+ }
94
+ ] , done ) ;
100
95
} ) ;
101
96
102
97
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 ) ,
107
101
function ( snapshot , next ) {
108
102
expect ( snapshot ) . to . eql ( v2 ) ;
109
103
next ( ) ;
110
- } ,
111
- done
112
- ] ) ;
104
+ }
105
+ ] , done ) ;
113
106
} ) ;
114
107
115
108
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 ) ,
120
112
function ( snapshot , next ) {
121
113
expect ( snapshot ) . to . eql ( v3 ) ;
122
114
next ( ) ;
123
- } ,
124
- done
125
- ] ) ;
115
+ }
116
+ ] , done ) ;
126
117
} ) ;
127
118
128
119
it ( 'fetches the day 2 version when asking for a time halfway between days 2 and 3' , function ( done ) {
129
120
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 ) ,
134
124
function ( snapshot , next ) {
135
125
expect ( snapshot ) . to . eql ( v2 ) ;
136
126
next ( ) ;
137
- } ,
138
- done
139
- ] ) ;
127
+ }
128
+ ] , done ) ;
140
129
} ) ;
141
130
142
131
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 ) ,
147
135
function ( snapshot , next ) {
148
136
expect ( snapshot ) . to . eql ( v3 ) ;
149
137
next ( ) ;
150
- } ,
151
- done
152
- ] ) ;
138
+ }
139
+ ] , done ) ;
153
140
} ) ;
154
141
155
142
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' ) ,
160
146
function ( snapshot , next ) {
161
147
expect ( snapshot ) . to . eql ( v3 ) ;
162
148
next ( ) ;
163
- } ,
164
- done
165
- ] ) ;
149
+ }
150
+ ] , done ) ;
166
151
} ) ;
167
152
168
153
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 ) ,
173
157
function ( snapshot , next ) {
174
158
expect ( snapshot ) . to . eql ( v0 ) ;
175
159
next ( ) ;
176
- } ,
177
- done
178
- ] ) ;
160
+ }
161
+ ] , done ) ;
179
162
} ) ;
180
163
181
164
it ( 'throws if the timestamp is undefined' , function ( ) {
@@ -407,10 +390,8 @@ describe('SnapshotTimestampRequest', function() {
407
390
408
391
var doc = backendWithMilestones . connect ( ) . get ( 'books' , 'mocking-bird' ) ;
409
392
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' } ) ,
414
395
function ( next ) {
415
396
clock . tick ( ONE_DAY ) ;
416
397
doc . submitOp ( { p : [ 'author' ] , oi : 'Harper Lea' } , next ) ;
@@ -426,9 +407,8 @@ describe('SnapshotTimestampRequest', function() {
426
407
function ( next ) {
427
408
clock . tick ( ONE_DAY ) ;
428
409
doc . submitOp ( { p : [ 'year' ] , od : 1959 , oi : 1960 } , next ) ;
429
- } ,
430
- done
431
- ] ) ;
410
+ }
411
+ ] , done ) ;
432
412
} ) ;
433
413
434
414
it ( 'fetches a snapshot between two milestones using the milestones' , function ( done ) {
0 commit comments