@@ -23,11 +23,55 @@ describe('rest create', () => {
23
23
expect ( results . length ) . toEqual ( 1 ) ;
24
24
var obj = results [ 0 ] ;
25
25
expect ( typeof obj . objectId ) . toEqual ( 'string' ) ;
26
+ expect ( obj . objectId . length ) . toEqual ( 10 ) ;
26
27
expect ( obj . _id ) . toBeUndefined ( ) ;
27
28
done ( ) ;
28
29
} ) ;
29
30
} ) ;
30
31
32
+ it ( 'can use custom _id size' , done => {
33
+ config . objectIdSize = 20 ;
34
+ rest . create ( config , auth . nobody ( config ) , 'Foo' , { } )
35
+ . then ( ( ) => database . adapter . find ( 'Foo' , { fields : { } } , { } , { } ) )
36
+ . then ( ( results ) => {
37
+ expect ( results . length ) . toEqual ( 1 ) ;
38
+ var obj = results [ 0 ] ;
39
+ expect ( typeof obj . objectId ) . toEqual ( 'string' ) ;
40
+ expect ( obj . objectId . length ) . toEqual ( 20 ) ;
41
+ done ( ) ;
42
+ } ) ;
43
+ } ) ;
44
+
45
+ it ( 'is backwards compatible when _id size changes' , done => {
46
+ rest . create ( config , auth . nobody ( config ) , 'Foo' , { size : 10 } )
47
+ . then ( ( ) => {
48
+ config . objectIdSize = 20 ;
49
+ return rest . find ( config , auth . nobody ( config ) , 'Foo' , { size : 10 } ) ;
50
+ } )
51
+ . then ( ( response ) => {
52
+ expect ( response . results . length ) . toEqual ( 1 ) ;
53
+ expect ( response . results [ 0 ] . objectId . length ) . toEqual ( 10 ) ;
54
+ return rest . update ( config , auth . nobody ( config ) , 'Foo' , { objectId : response . results [ 0 ] . objectId } , { update : 20 } ) ;
55
+ } )
56
+ . then ( ( ) => {
57
+ return rest . find ( config , auth . nobody ( config ) , 'Foo' , { size : 10 } ) ;
58
+ } ) . then ( ( response ) => {
59
+ expect ( response . results . length ) . toEqual ( 1 ) ;
60
+ expect ( response . results [ 0 ] . objectId . length ) . toEqual ( 10 ) ;
61
+ expect ( response . results [ 0 ] . update ) . toEqual ( 20 ) ;
62
+ return rest . create ( config , auth . nobody ( config ) , 'Foo' , { size : 20 } ) ;
63
+ } )
64
+ . then ( ( ) => {
65
+ config . objectIdSize = 10 ;
66
+ return rest . find ( config , auth . nobody ( config ) , 'Foo' , { size : 20 } ) ;
67
+ } )
68
+ . then ( ( response ) => {
69
+ expect ( response . results . length ) . toEqual ( 1 ) ;
70
+ expect ( response . results [ 0 ] . objectId . length ) . toEqual ( 20 ) ;
71
+ done ( ) ;
72
+ } ) ;
73
+ } ) ;
74
+
31
75
it ( 'handles array, object, date' , ( done ) => {
32
76
const now = new Date ( ) ;
33
77
var obj = {
0 commit comments