@@ -3051,6 +3051,42 @@ describe('schemas', () => {
3051
3051
} ) ;
3052
3052
} ) ;
3053
3053
3054
+ it ( 'allows add unique index when you create a class' , async ( ) => {
3055
+ await reconfigureServer ( { silent : false } ) ;
3056
+ const response = await request ( {
3057
+ url : 'http://localhost:8378/1/schemas' ,
3058
+ method : 'POST' ,
3059
+ headers : masterKeyHeaders ,
3060
+ json : true ,
3061
+ body : {
3062
+ className : 'NewClass' ,
3063
+ fields : {
3064
+ aString : { type : 'String' } ,
3065
+ } ,
3066
+ indexes : {
3067
+ name1 : { aString : 1 , _options : { unique : true } } ,
3068
+ } ,
3069
+ } ,
3070
+ } ) ;
3071
+ expect ( response . data ) . toEqual ( {
3072
+ className : 'NewClass' ,
3073
+ fields : {
3074
+ ACL : { type : 'ACL' } ,
3075
+ createdAt : { type : 'Date' } ,
3076
+ updatedAt : { type : 'Date' } ,
3077
+ objectId : { type : 'String' } ,
3078
+ aString : { type : 'String' } ,
3079
+ } ,
3080
+ classLevelPermissions : defaultClassLevelPermissions ,
3081
+ indexes : {
3082
+ name1 : { aString : 1 , _options : { unique : true } } ,
3083
+ } ,
3084
+ } ) ;
3085
+ const indexes = await config . database . adapter . getIndexes ( 'NewClass' ) ;
3086
+ expect ( indexes . length ) . toBe ( 2 ) ;
3087
+ expect ( indexes . filter ( row => row . unique ) . length ) . toEqual ( 1 ) ;
3088
+ } ) ;
3089
+
3054
3090
it ( 'empty index returns nothing' , done => {
3055
3091
request ( {
3056
3092
url : 'http://localhost:8378/1/schemas' ,
@@ -3148,6 +3184,70 @@ describe('schemas', () => {
3148
3184
} ) ;
3149
3185
} ) ;
3150
3186
3187
+ it ( 'lets you add unique indexes' , async ( ) => {
3188
+ await request ( {
3189
+ url : 'http://localhost:8378/1/schemas/NewClass' ,
3190
+ method : 'POST' ,
3191
+ headers : masterKeyHeaders ,
3192
+ json : true ,
3193
+ body : { } ,
3194
+ } ) ;
3195
+ let response = await request ( {
3196
+ url : 'http://localhost:8378/1/schemas/NewClass' ,
3197
+ method : 'PUT' ,
3198
+ headers : masterKeyHeaders ,
3199
+ json : true ,
3200
+ body : {
3201
+ fields : {
3202
+ aString : { type : 'String' } ,
3203
+ } ,
3204
+ indexes : {
3205
+ name1 : { aString : 1 , _options : { unique : true } } ,
3206
+ } ,
3207
+ } ,
3208
+ } ) ;
3209
+ expect (
3210
+ dd ( response . data , {
3211
+ className : 'NewClass' ,
3212
+ fields : {
3213
+ ACL : { type : 'ACL' } ,
3214
+ createdAt : { type : 'Date' } ,
3215
+ updatedAt : { type : 'Date' } ,
3216
+ objectId : { type : 'String' } ,
3217
+ aString : { type : 'String' } ,
3218
+ } ,
3219
+ classLevelPermissions : defaultClassLevelPermissions ,
3220
+ indexes : {
3221
+ _id_ : { _id : 1 } ,
3222
+ name1 : { aString : 1 , _options : { unique : true } } ,
3223
+ } ,
3224
+ } )
3225
+ ) . toEqual ( undefined ) ;
3226
+ response = await request ( {
3227
+ url : 'http://localhost:8378/1/schemas/NewClass' ,
3228
+ headers : masterKeyHeaders ,
3229
+ json : true ,
3230
+ } ) ;
3231
+ expect ( response . data ) . toEqual ( {
3232
+ className : 'NewClass' ,
3233
+ fields : {
3234
+ ACL : { type : 'ACL' } ,
3235
+ createdAt : { type : 'Date' } ,
3236
+ updatedAt : { type : 'Date' } ,
3237
+ objectId : { type : 'String' } ,
3238
+ aString : { type : 'String' } ,
3239
+ } ,
3240
+ classLevelPermissions : defaultClassLevelPermissions ,
3241
+ indexes : {
3242
+ _id_ : { _id : 1 } ,
3243
+ name1 : { aString : 1 , _options : { unique : true } } ,
3244
+ } ,
3245
+ } ) ;
3246
+ const indexes = await config . database . adapter . getIndexes ( 'NewClass' ) ;
3247
+ expect ( indexes . length ) . toEqual ( 2 ) ;
3248
+ expect ( indexes . filter ( row => row . unique ) . length ) . toEqual ( 1 ) ;
3249
+ } ) ;
3250
+
3151
3251
it_only_db ( 'mongo' ) ( 'lets you add index with with pointer like structure' , done => {
3152
3252
request ( {
3153
3253
url : 'http://localhost:8378/1/schemas/NewClass' ,
0 commit comments