Progres towards moving mongo logic into its adapter
This commit is contained in:
@@ -163,14 +163,26 @@ describe('Schema', () => {
|
||||
.then(schema => schema.addClassIfNotExists('NewClass', {
|
||||
foo: {type: 'String'}
|
||||
}))
|
||||
.then(result => {
|
||||
expect(result).toEqual({
|
||||
_id: 'NewClass',
|
||||
objectId: 'string',
|
||||
updatedAt: 'string',
|
||||
createdAt: 'string',
|
||||
foo: 'string',
|
||||
})
|
||||
.then(actualSchema => {
|
||||
const expectedSchema = {
|
||||
className: 'NewClass',
|
||||
fields: {
|
||||
objectId: { type: 'String' },
|
||||
updatedAt: { type: 'Date' },
|
||||
createdAt: { type: 'Date' },
|
||||
ACL: { type: 'ACL' },
|
||||
foo: { type: 'String' },
|
||||
},
|
||||
classLevelPermissions: {
|
||||
find: { '*': true },
|
||||
get: { '*': true },
|
||||
create: { '*': true },
|
||||
update: { '*': true },
|
||||
delete: { '*': true },
|
||||
addField: { '*': true },
|
||||
},
|
||||
}
|
||||
expect(dd(actualSchema, expectedSchema)).toEqual(undefined);
|
||||
done();
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -201,15 +213,27 @@ describe('Schema', () => {
|
||||
.then(schema => {
|
||||
var p1 = schema.addClassIfNotExists('NewClass', {foo: {type: 'String'}});
|
||||
var p2 = schema.addClassIfNotExists('NewClass', {foo: {type: 'String'}});
|
||||
Promise.race([p1, p2]) //Use race because we expect the first completed promise to be the successful one
|
||||
.then(response => {
|
||||
expect(response).toEqual({
|
||||
_id: 'NewClass',
|
||||
objectId: 'string',
|
||||
updatedAt: 'string',
|
||||
createdAt: 'string',
|
||||
foo: 'string',
|
||||
});
|
||||
Promise.race([p1, p2])
|
||||
.then(actualSchema => {
|
||||
const expectedSchema = {
|
||||
className: 'NewClass',
|
||||
fields: {
|
||||
objectId: { type: 'String' },
|
||||
updatedAt: { type: 'Date' },
|
||||
createdAt: { type: 'Date' },
|
||||
ACL: { type: 'ACL' },
|
||||
foo: { type: 'String' },
|
||||
},
|
||||
classLevelPermissions: {
|
||||
find: { '*': true },
|
||||
get: { '*': true },
|
||||
create: { '*': true },
|
||||
update: { '*': true },
|
||||
delete: { '*': true },
|
||||
addField: { '*': true },
|
||||
},
|
||||
}
|
||||
expect(dd(actualSchema, expectedSchema)).toEqual(undefined);
|
||||
});
|
||||
Promise.all([p1,p2])
|
||||
.catch(error => {
|
||||
@@ -373,23 +397,36 @@ describe('Schema', () => {
|
||||
aPointer: {type: 'Pointer', targetClass: 'ThisClassDoesNotExistYet'},
|
||||
aRelation: {type: 'Relation', targetClass: 'NewClass'},
|
||||
}))
|
||||
.then(mongoObj => {
|
||||
expect(mongoObj).toEqual({
|
||||
_id: 'NewClass',
|
||||
objectId: 'string',
|
||||
createdAt: 'string',
|
||||
updatedAt: 'string',
|
||||
aNumber: 'number',
|
||||
aString: 'string',
|
||||
aBool: 'boolean',
|
||||
aDate: 'date',
|
||||
aObject: 'object',
|
||||
aArray: 'array',
|
||||
aGeoPoint: 'geopoint',
|
||||
aFile: 'file',
|
||||
aPointer: '*ThisClassDoesNotExistYet',
|
||||
aRelation: 'relation<NewClass>',
|
||||
});
|
||||
.then(actualSchema => {
|
||||
const expectedSchema = {
|
||||
className: 'NewClass',
|
||||
fields: {
|
||||
objectId: { type: 'String' },
|
||||
updatedAt: { type: 'Date' },
|
||||
createdAt: { type: 'Date' },
|
||||
ACL: { type: 'ACL' },
|
||||
aString: { type: 'String' },
|
||||
aNumber: { type: 'Number' },
|
||||
aString: { type: 'String' },
|
||||
aBool: { type: 'Boolean' },
|
||||
aDate: { type: 'Date' },
|
||||
aObject: { type: 'Object' },
|
||||
aArray: { type: 'Array' },
|
||||
aGeoPoint: { type: 'GeoPoint' },
|
||||
aFile: { type: 'File' },
|
||||
aPointer: { type: 'Pointer', targetClass: 'ThisClassDoesNotExistYet' },
|
||||
aRelation: { type: 'Relation', targetClass: 'NewClass' },
|
||||
},
|
||||
classLevelPermissions: {
|
||||
find: { '*': true },
|
||||
get: { '*': true },
|
||||
create: { '*': true },
|
||||
update: { '*': true },
|
||||
delete: { '*': true },
|
||||
addField: { '*': true },
|
||||
},
|
||||
}
|
||||
expect(dd(actualSchema, expectedSchema)).toEqual(undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -399,23 +436,35 @@ describe('Schema', () => {
|
||||
.then(schema => schema.addClassIfNotExists('_Installation', {
|
||||
foo: {type: 'Number'},
|
||||
}))
|
||||
.then(mongoObj => {
|
||||
expect(mongoObj).toEqual({
|
||||
_id: '_Installation',
|
||||
createdAt: 'string',
|
||||
updatedAt: 'string',
|
||||
objectId: 'string',
|
||||
foo: 'number',
|
||||
installationId: 'string',
|
||||
deviceToken: 'string',
|
||||
channels: 'array',
|
||||
deviceType: 'string',
|
||||
pushType: 'string',
|
||||
GCMSenderId: 'string',
|
||||
timeZone: 'string',
|
||||
localeIdentifier: 'string',
|
||||
badge: 'number',
|
||||
});
|
||||
.then(actualSchema => {
|
||||
const expectedSchema = {
|
||||
className: '_Installation',
|
||||
fields: {
|
||||
objectId: { type: 'String' },
|
||||
updatedAt: { type: 'Date' },
|
||||
createdAt: { type: 'Date' },
|
||||
ACL: { type: 'ACL' },
|
||||
foo: { type: 'Number' },
|
||||
installationId: { type: 'String' },
|
||||
deviceToken: { type: 'String' },
|
||||
channels: { type: 'Array' },
|
||||
deviceType: { type: 'String' },
|
||||
pushType: { type: 'String' },
|
||||
GCMSenderId: { type: 'String' },
|
||||
timeZone: { type: 'String' },
|
||||
localeIdentifier: { type: 'String' },
|
||||
badge: { type: 'Number' },
|
||||
},
|
||||
classLevelPermissions: {
|
||||
find: { '*': true },
|
||||
get: { '*': true },
|
||||
create: { '*': true },
|
||||
update: { '*': true },
|
||||
delete: { '*': true },
|
||||
addField: { '*': true },
|
||||
},
|
||||
}
|
||||
expect(dd(actualSchema, expectedSchema)).toEqual(undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -423,16 +472,28 @@ describe('Schema', () => {
|
||||
it('creates non-custom classes which include relation field', done => {
|
||||
config.database.loadSchema()
|
||||
.then(schema => schema.addClassIfNotExists('_Role', {}))
|
||||
.then(mongoObj => {
|
||||
expect(mongoObj).toEqual({
|
||||
_id: '_Role',
|
||||
createdAt: 'string',
|
||||
updatedAt: 'string',
|
||||
objectId: 'string',
|
||||
name: 'string',
|
||||
users: 'relation<_User>',
|
||||
roles: 'relation<_Role>',
|
||||
});
|
||||
.then(actualSchema => {
|
||||
const expectedSchema = {
|
||||
className: '_Role',
|
||||
fields: {
|
||||
objectId: { type: 'String' },
|
||||
updatedAt: { type: 'Date' },
|
||||
createdAt: { type: 'Date' },
|
||||
ACL: { type: 'ACL' },
|
||||
name: { type: 'String' },
|
||||
users: { type: 'Relation', targetClass: '_User' },
|
||||
roles: { type: 'Relation', targetClass: '_Role' },
|
||||
},
|
||||
classLevelPermissions: {
|
||||
find: { '*': true },
|
||||
get: { '*': true },
|
||||
create: { '*': true },
|
||||
update: { '*': true },
|
||||
delete: { '*': true },
|
||||
addField: { '*': true },
|
||||
},
|
||||
};
|
||||
expect(dd(actualSchema, expectedSchema)).toEqual(undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -440,19 +501,31 @@ describe('Schema', () => {
|
||||
it('creates non-custom classes which include pointer field', done => {
|
||||
config.database.loadSchema()
|
||||
.then(schema => schema.addClassIfNotExists('_Session', {}))
|
||||
.then(mongoObj => {
|
||||
expect(mongoObj).toEqual({
|
||||
_id: '_Session',
|
||||
createdAt: 'string',
|
||||
updatedAt: 'string',
|
||||
objectId: 'string',
|
||||
restricted: 'boolean',
|
||||
user: '*_User',
|
||||
installationId: 'string',
|
||||
sessionToken: 'string',
|
||||
expiresAt: 'date',
|
||||
createdWith: 'object'
|
||||
});
|
||||
.then(actualSchema => {
|
||||
const expectedSchema = {
|
||||
className: '_Session',
|
||||
fields: {
|
||||
objectId: { type: 'String' },
|
||||
updatedAt: { type: 'Date' },
|
||||
createdAt: { type: 'Date' },
|
||||
restricted: { type: 'Boolean' },
|
||||
user: { type: 'Pointer', targetClass: '_User' },
|
||||
installationId: { type: 'String' },
|
||||
sessionToken: { type: 'String' },
|
||||
expiresAt: { type: 'Date' },
|
||||
createdWith: { type: 'Object' },
|
||||
ACL: { type: 'ACL' },
|
||||
},
|
||||
classLevelPermissions: {
|
||||
find: { '*': true },
|
||||
get: { '*': true },
|
||||
create: { '*': true },
|
||||
update: { '*': true },
|
||||
delete: { '*': true },
|
||||
addField: { '*': true },
|
||||
},
|
||||
};
|
||||
expect(dd(actualSchema, expectedSchema)).toEqual(undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -583,14 +656,26 @@ describe('Schema', () => {
|
||||
schema.addClassIfNotExists('NewClass', {
|
||||
relationField: {type: 'Relation', targetClass: '_User'}
|
||||
})
|
||||
.then(mongoObj => {
|
||||
expect(mongoObj).toEqual({
|
||||
_id: 'NewClass',
|
||||
objectId: 'string',
|
||||
updatedAt: 'string',
|
||||
createdAt: 'string',
|
||||
relationField: 'relation<_User>',
|
||||
});
|
||||
.then(actualSchema => {
|
||||
const expectedSchema = {
|
||||
className: 'NewClass',
|
||||
fields: {
|
||||
objectId: { type: 'String' },
|
||||
updatedAt: { type: 'Date' },
|
||||
createdAt: { type: 'Date' },
|
||||
ACL: { type: 'ACL' },
|
||||
relationField: { type: 'Relation', targetClass: '_User' },
|
||||
},
|
||||
classLevelPermissions: {
|
||||
find: { '*': true },
|
||||
get: { '*': true },
|
||||
create: { '*': true },
|
||||
update: { '*': true },
|
||||
delete: { '*': true },
|
||||
addField: { '*': true },
|
||||
},
|
||||
};
|
||||
expect(dd(actualSchema, expectedSchema)).toEqual(undefined);
|
||||
})
|
||||
.then(() => config.database.collectionExists('_Join:relationField:NewClass'))
|
||||
.then(exist => {
|
||||
@@ -703,33 +788,4 @@ describe('Schema', () => {
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('handles legacy _client_permissions keys without crashing', done => {
|
||||
Schema.mongoSchemaToSchemaAPIResponse({
|
||||
"_id":"_Installation",
|
||||
"_client_permissions":{
|
||||
"get":true,
|
||||
"find":true,
|
||||
"update":true,
|
||||
"create":true,
|
||||
"delete":true,
|
||||
},
|
||||
"_metadata":{
|
||||
"class_permissions":{
|
||||
"get":{"*":true},
|
||||
"find":{"*":true},
|
||||
"update":{"*":true},
|
||||
"create":{"*":true},
|
||||
"delete":{"*":true},
|
||||
"addField":{"*":true},
|
||||
}
|
||||
},
|
||||
"installationId":"string",
|
||||
"deviceToken":"string",
|
||||
"deviceType":"string",
|
||||
"channels":"array",
|
||||
"user":"*_User",
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user