@@ -5,6 +5,7 @@ const dd = require('deep-diff');
5
5
const Config = require ( '../lib/Config' ) ;
6
6
const request = require ( '../lib/request' ) ;
7
7
const TestUtils = require ( '../lib/TestUtils' ) ;
8
+ const SchemaController = require ( '../lib/Controllers/SchemaController' ) . SchemaController ;
8
9
9
10
let config ;
10
11
@@ -239,6 +240,52 @@ describe('schemas', () => {
239
240
} ) ;
240
241
} ) ;
241
242
243
+ it ( 'ensure refresh cache after creating a class' , async done => {
244
+ spyOn ( SchemaController . prototype , 'reloadData' ) . and . callFake ( ( ) => Promise . resolve ( ) ) ;
245
+ await request ( {
246
+ url : 'http://localhost:8378/1/schemas' ,
247
+ method : 'POST' ,
248
+ headers : masterKeyHeaders ,
249
+ json : true ,
250
+ body : {
251
+ className : 'A' ,
252
+ } ,
253
+ } ) ;
254
+ const response = await request ( {
255
+ url : 'http://localhost:8378/1/schemas' ,
256
+ method : 'GET' ,
257
+ headers : masterKeyHeaders ,
258
+ json : true ,
259
+ } ) ;
260
+ const expected = {
261
+ results : [
262
+ userSchema ,
263
+ roleSchema ,
264
+ {
265
+ className : 'A' ,
266
+ fields : {
267
+ //Default fields
268
+ ACL : { type : 'ACL' } ,
269
+ createdAt : { type : 'Date' } ,
270
+ updatedAt : { type : 'Date' } ,
271
+ objectId : { type : 'String' } ,
272
+ } ,
273
+ classLevelPermissions : defaultClassLevelPermissions ,
274
+ } ,
275
+ ] ,
276
+ } ;
277
+ expect (
278
+ response . data . results
279
+ . sort ( ( s1 , s2 ) => s1 . className . localeCompare ( s2 . className ) )
280
+ . map ( s => {
281
+ const withoutIndexes = Object . assign ( { } , s ) ;
282
+ delete withoutIndexes . indexes ;
283
+ return withoutIndexes ;
284
+ } )
285
+ ) . toEqual ( expected . results . sort ( ( s1 , s2 ) => s1 . className . localeCompare ( s2 . className ) ) ) ;
286
+ done ( ) ;
287
+ } ) ;
288
+
242
289
it ( 'responds with a single schema' , done => {
243
290
const obj = hasAllPODobject ( ) ;
244
291
obj . save ( ) . then ( ( ) => {
@@ -1507,6 +1554,46 @@ describe('schemas', () => {
1507
1554
} ) ;
1508
1555
} ) ;
1509
1556
1557
+ it ( 'ensure refresh cache after deleting a class' , async done => {
1558
+ config = Config . get ( 'test' ) ;
1559
+ spyOn ( config . schemaCache , 'del' ) . and . callFake ( ( ) => { } ) ;
1560
+ spyOn ( SchemaController . prototype , 'reloadData' ) . and . callFake ( ( ) => Promise . resolve ( ) ) ;
1561
+ await request ( {
1562
+ url : 'http://localhost:8378/1/schemas' ,
1563
+ method : 'POST' ,
1564
+ headers : masterKeyHeaders ,
1565
+ json : true ,
1566
+ body : {
1567
+ className : 'A' ,
1568
+ } ,
1569
+ } ) ;
1570
+ await request ( {
1571
+ method : 'DELETE' ,
1572
+ url : 'http://localhost:8378/1/schemas/A' ,
1573
+ headers : masterKeyHeaders ,
1574
+ json : true ,
1575
+ } ) ;
1576
+ const response = await request ( {
1577
+ url : 'http://localhost:8378/1/schemas' ,
1578
+ method : 'GET' ,
1579
+ headers : masterKeyHeaders ,
1580
+ json : true ,
1581
+ } ) ;
1582
+ const expected = {
1583
+ results : [ userSchema , roleSchema ] ,
1584
+ } ;
1585
+ expect (
1586
+ response . data . results
1587
+ . sort ( ( s1 , s2 ) => s1 . className . localeCompare ( s2 . className ) )
1588
+ . map ( s => {
1589
+ const withoutIndexes = Object . assign ( { } , s ) ;
1590
+ delete withoutIndexes . indexes ;
1591
+ return withoutIndexes ;
1592
+ } )
1593
+ ) . toEqual ( expected . results . sort ( ( s1 , s2 ) => s1 . className . localeCompare ( s2 . className ) ) ) ;
1594
+ done ( ) ;
1595
+ } ) ;
1596
+
1510
1597
it ( 'deletes collections including join tables' , done => {
1511
1598
const obj = new Parse . Object ( 'MyClass' ) ;
1512
1599
obj . set ( 'data' , 'data' ) ;
0 commit comments