@@ -174,6 +174,24 @@ describe("OrderedKeyValue Database", () => {
174174 ] ) ;
175175 } ) ;
176176
177+ it ( "add a value - index 0" , async ( ) => {
178+ const value = "value1" ;
179+ const key = "key1" ;
180+
181+ const value2 = "value2" ;
182+ const key2 = "key2" ;
183+
184+ const hash = await db . put ( key , value ) ;
185+ const hash2 = await db . put ( key2 , value2 , 0 ) ;
186+
187+ const actual = await db . all ( ) ;
188+
189+ expect ( actual ) . to . deep . equal ( [
190+ { value : value2 , key : key2 , hash : hash2 } ,
191+ { value : value , key, hash } ,
192+ ] ) ;
193+ } ) ;
194+
177195 it ( "add a value - negative index" , async ( ) => {
178196 const value = "value1" ;
179197 const key = "key1" ;
@@ -187,8 +205,8 @@ describe("OrderedKeyValue Database", () => {
187205 const actual = await db . all ( ) ;
188206
189207 expect ( actual ) . to . deep . equal ( [
190- { value : value2 , key : key2 , hash : hash2 } ,
191208 { value : value , key, hash } ,
209+ { value : value2 , key : key2 , hash : hash2 } ,
192210 ] ) ;
193211 } ) ;
194212
@@ -228,6 +246,24 @@ describe("OrderedKeyValue Database", () => {
228246 ] ) ;
229247 } ) ;
230248
249+ it ( "move a value - index 0" , async ( ) => {
250+ const value = "value1" ;
251+ const key = "key1" ;
252+
253+ const value2 = "value2" ;
254+ const key2 = "key2" ;
255+
256+ const hash = await db . put ( key , value ) ;
257+ const hash2 = await db . put ( key2 , value2 ) ;
258+ await db . move ( key2 , 0 ) ;
259+ const actual = await db . all ( ) ;
260+
261+ expect ( actual ) . to . deep . equal ( [
262+ { value : value2 , key : key2 , hash : hash2 } ,
263+ { value : value , key, hash } ,
264+ ] ) ;
265+ } ) ;
266+
231267 it ( "move a value - negative index" , async ( ) => {
232268 const value = "value1" ;
233269 const key = "key1" ;
@@ -237,7 +273,7 @@ describe("OrderedKeyValue Database", () => {
237273
238274 const hash = await db . put ( key , value ) ;
239275 const hash2 = await db . put ( key2 , value2 ) ;
240- await db . move ( key2 , - 1 ) ;
276+ await db . move ( key , - 1 ) ;
241277 const actual = await db . all ( ) ;
242278
243279 expect ( actual ) . to . deep . equal ( [
@@ -305,46 +341,86 @@ describe("OrderedKeyValue Database", () => {
305341 ] ) ;
306342 } ) ;
307343
344+ it . skip ( "move a value twice" , async ( ) => {
345+ const value = "value1" ;
346+ const key = "key1" ;
347+
348+ const value2 = "value2" ;
349+ const key2 = "key2" ;
350+
351+ const value3 = "value3" ;
352+ const key3 = "key3" ;
353+
354+ const hash = await db . put ( key , value ) ;
355+ const hash2 = await db . put ( key2 , value2 ) ;
356+ const hash3 = await db . put ( key3 , value3 ) ;
357+ await db . move ( key , 1 ) ;
358+
359+ const actual1 = await db . all ( ) ;
360+ expect ( actual1 ) . to . deep . equal ( [
361+ { value : value2 , key : key2 , hash : hash2 } ,
362+ { value : value , key, hash } ,
363+ { value : value3 , key : key3 , hash : hash3 } ,
364+ ] ) ;
365+
366+ await db . move ( key , 2 ) ;
367+
368+ const actual2 = await db . all ( ) ;
369+ expect ( actual2 ) . to . deep . equal ( [
370+ { value : value2 , key : key2 , hash : hash2 } ,
371+ { value : value3 , key : key3 , hash : hash3 } ,
372+ { value : value , key, hash } ,
373+ ] ) ;
374+ } ) ;
375+
308376 it ( "returns all values" , async ( ) => {
309377 const keyvalue : {
310378 value : DBElements ;
311379 key : string ;
312380 position : number ;
381+ clock : number ;
313382 hash ?: string ;
314383 } [ ] = [
315384 {
316385 key : "key1" ,
317386 position : 0 ,
387+ clock : - 6 ,
318388 value : "init" ,
319389 } ,
320390 {
321391 key : "key2" ,
322392 position : 1 ,
393+ clock : - 5 ,
323394 value : true ,
324395 } ,
325396 {
326397 key : "key3" ,
327398 position : 2 ,
399+ clock : - 4 ,
328400 value : "hello" ,
329401 } ,
330402 {
331403 key : "key4" ,
332404 position : 3 ,
405+ clock : - 3 ,
333406 value : "friend" ,
334407 } ,
335408 {
336409 key : "key5" ,
337410 position : 4 ,
411+ clock : - 2 ,
338412 value : "12345" ,
339413 } ,
340414 {
341415 key : "key6" ,
342416 position : 5 ,
417+ clock : - 1 ,
343418 value : "empty" ,
344419 } ,
345420 {
346421 key : "key7" ,
347422 position : 6 ,
423+ clock : 0 ,
348424 value : "friend33" ,
349425 } ,
350426 ] ;
0 commit comments