|
| 1 | +var request = require('request'); |
| 2 | +var dd = require('deep-diff'); |
| 3 | + |
| 4 | +describe('schemas', () => { |
| 5 | + it('requires the master key to get all schemas', (done) => { |
| 6 | + request.get({ |
| 7 | + url: 'http://localhost:8378/1/schemas', |
| 8 | + json: true, |
| 9 | + headers: { |
| 10 | + 'X-Parse-Application-Id': 'test', |
| 11 | + 'X-Parse-REST-API-Key': 'rest', |
| 12 | + }, |
| 13 | + }, (error, response, body) => { |
| 14 | + expect(response.statusCode).toEqual(401); |
| 15 | + expect(body.error).toEqual('unauthorized'); |
| 16 | + done(); |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + it('responds with empty list when there are no schemas', done => { |
| 21 | + request.get({ |
| 22 | + url: 'http://localhost:8378/1/schemas', |
| 23 | + json: true, |
| 24 | + headers: { |
| 25 | + 'X-Parse-Application-Id': 'test', |
| 26 | + 'X-Parse-Master-Key': 'test', |
| 27 | + }, |
| 28 | + }, (error, response, body) => { |
| 29 | + expect(body.results).toEqual([]); |
| 30 | + done(); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + it('responds with a list of schemas after creating objects', done => { |
| 35 | + var obj1 = new Parse.Object('HasAllPOD'); |
| 36 | + obj1.set('aNumber', 5); |
| 37 | + obj1.set('aString', 'string'); |
| 38 | + obj1.set('aBool', true); |
| 39 | + obj1.set('aDate', new Date()); |
| 40 | + obj1.set('aObject', {k1: 'value', k2: true, k3: 5}); |
| 41 | + obj1.set('aArray', ['contents', true, 5]); |
| 42 | + obj1.set('aGeoPoint', new Parse.GeoPoint({latitude: 0, longitude: 0})); |
| 43 | + obj1.set('aFile', new Parse.File('f.txt', { base64: 'V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=' })); |
| 44 | + var obj1ACL = new Parse.ACL(); |
| 45 | + obj1ACL.setPublicWriteAccess(false); |
| 46 | + obj1.setACL(obj1ACL); |
| 47 | + |
| 48 | + obj1.save().then(savedObj1 => { |
| 49 | + var obj2 = new Parse.Object('HasPointersAndRelations'); |
| 50 | + obj2.set('aPointer', savedObj1); |
| 51 | + var relation = obj2.relation('aRelation'); |
| 52 | + relation.add(obj1); |
| 53 | + return obj2.save(); |
| 54 | + }).then(() => { |
| 55 | + request.get({ |
| 56 | + url: 'http://localhost:8378/1/schemas', |
| 57 | + json: true, |
| 58 | + headers: { |
| 59 | + 'X-Parse-Application-Id': 'test', |
| 60 | + 'X-Parse-Master-Key': 'test', |
| 61 | + }, |
| 62 | + }, (error, response, body) => { |
| 63 | + var expected = { |
| 64 | + results: [ |
| 65 | + { |
| 66 | + className: 'HasAllPOD', |
| 67 | + fields: { |
| 68 | + //Default fields |
| 69 | + ACL: {type: 'ACL'}, |
| 70 | + createdAt: {type: 'Date'}, |
| 71 | + updatedAt: {type: 'Date'}, |
| 72 | + objectId: {type: 'String'}, |
| 73 | + //Custom fields |
| 74 | + aNumber: {type: 'Number'}, |
| 75 | + aString: {type: 'String'}, |
| 76 | + aBool: {type: 'Boolean'}, |
| 77 | + aDate: {type: 'Date'}, |
| 78 | + aObject: {type: 'Object'}, |
| 79 | + aArray: {type: 'Array'}, |
| 80 | + aGeoPoint: {type: 'GeoPoint'}, |
| 81 | + aFile: {type: 'File'} |
| 82 | + }, |
| 83 | + }, |
| 84 | + { |
| 85 | + className: 'HasPointersAndRelations', |
| 86 | + fields: { |
| 87 | + //Default fields |
| 88 | + ACL: {type: 'ACL'}, |
| 89 | + createdAt: {type: 'Date'}, |
| 90 | + updatedAt: {type: 'Date'}, |
| 91 | + objectId: {type: 'String'}, |
| 92 | + //Custom fields |
| 93 | + aPointer: { |
| 94 | + type: 'Pointer', |
| 95 | + targetClass: 'HasAllPOD', |
| 96 | + }, |
| 97 | + aRelation: { |
| 98 | + type: 'Relation', |
| 99 | + targetClass: 'HasAllPOD', |
| 100 | + }, |
| 101 | + }, |
| 102 | + } |
| 103 | + ] |
| 104 | + }; |
| 105 | + expect(body).toEqual(expected); |
| 106 | + done(); |
| 107 | + }) |
| 108 | + }); |
| 109 | + }); |
| 110 | +}); |
0 commit comments