11// testing-routes.js
22import cache from './cache' ;
3-
3+ import * as middlewares from './middlewares' ;
4+ import { ParseServer } from './index' ;
5+ import { Parse } from 'parse/node' ;
46var express = require ( 'express' ) ,
5- middlewares = require ( './middlewares' ) ,
6- cryptoUtils = require ( './cryptoUtils' ) ;
7+ cryptoUtils = require ( './cryptoUtils' ) ;
78
89var router = express . Router ( ) ;
910
1011// creates a unique app in the cache, with a collection prefix
1112function createApp ( req , res ) {
1213 var appId = cryptoUtils . randomHexString ( 32 ) ;
13- // TODO: (nlutsenko) This doesn't work and should die, since there are no controllers on this configuration.
14- cache . apps . set ( appId , {
15- 'collectionPrefix' : appId + '_' ,
16- 'masterKey' : 'master'
14+
15+ ParseServer ( {
16+ appId : appId ,
17+ masterKey : 'master' ,
18+ serverURL : Parse . serverURL ,
19+ collectionPrefix : appId
1720 } ) ;
1821 var keys = {
1922 'application_id' : appId ,
20- 'client_key' : 'unused' ,
21- 'windows_key' : 'unused' ,
23+ 'client_key' : 'unused' ,
24+ 'windows_key' : 'unused' ,
2225 'javascript_key' : 'unused' ,
23- 'webhook_key' : 'unused' ,
24- 'rest_api_key' : 'unused' ,
25- 'master_key' : 'master'
26+ 'webhook_key' : 'unused' ,
27+ 'rest_api_key' : 'unused' ,
28+ 'master_key' : 'master'
2629 } ;
2730 res . status ( 200 ) . send ( keys ) ;
2831}
2932
3033// deletes all collections with the collectionPrefix of the app
3134function clearApp ( req , res ) {
3235 if ( ! req . auth . isMaster ) {
33- return res . status ( 401 ) . send ( { "error" : "unauthorized" } ) ;
36+ return res . status ( 401 ) . send ( { "error" : "unauthorized" } ) ;
3437 }
3538 return req . config . database . deleteEverything ( ) . then ( ( ) => {
3639 res . status ( 200 ) . send ( { } ) ;
@@ -40,7 +43,7 @@ function clearApp(req, res) {
4043// deletes all collections and drops the app from cache
4144function dropApp ( req , res ) {
4245 if ( ! req . auth . isMaster ) {
43- return res . status ( 401 ) . send ( { "error" : "unauthorized" } ) ;
46+ return res . status ( 401 ) . send ( { "error" : "unauthorized" } ) ;
4447 }
4548 return req . config . database . deleteEverything ( ) . then ( ( ) => {
4649 cache . apps . remove ( req . config . applicationId ) ;
@@ -53,21 +56,14 @@ function notImplementedYet(req, res) {
5356 res . status ( 200 ) . send ( { } ) ;
5457}
5558
56- router . post ( '/rest_clear_app' ,
57- middlewares . handleParseHeaders , clearApp ) ;
58- router . post ( '/rest_block' ,
59- middlewares . handleParseHeaders , notImplementedYet ) ;
60- router . post ( '/rest_mock_v8_client' ,
61- middlewares . handleParseHeaders , notImplementedYet ) ;
62- router . post ( '/rest_unmock_v8_client' ,
63- middlewares . handleParseHeaders , notImplementedYet ) ;
64- router . post ( '/rest_verify_analytics' ,
65- middlewares . handleParseHeaders , notImplementedYet ) ;
59+ router . post ( '/rest_clear_app' , middlewares . handleParseHeaders , clearApp ) ;
60+ router . post ( '/rest_block' , middlewares . handleParseHeaders , notImplementedYet ) ;
61+ router . post ( '/rest_mock_v8_client' , middlewares . handleParseHeaders , notImplementedYet ) ;
62+ router . post ( '/rest_unmock_v8_client' , middlewares . handleParseHeaders , notImplementedYet ) ;
63+ router . post ( '/rest_verify_analytics' , middlewares . handleParseHeaders , notImplementedYet ) ;
6664router . post ( '/rest_create_app' , createApp ) ;
67- router . post ( '/rest_drop_app' ,
68- middlewares . handleParseHeaders , dropApp ) ;
69- router . post ( '/rest_configure_app' ,
70- middlewares . handleParseHeaders , notImplementedYet ) ;
65+ router . post ( '/rest_drop_app' , middlewares . handleParseHeaders , dropApp ) ;
66+ router . post ( '/rest_configure_app' , middlewares . handleParseHeaders , notImplementedYet ) ;
7167
7268module . exports = {
7369 router : router
0 commit comments