Skip to content

Commit 929c4e1

Browse files
authored
Do not throw error if user provide a pointer like index onMongo (#6923)
* Do not throw error if user provide a pointer like index on mongo * Add test
1 parent 66f7af9 commit 929c4e1

File tree

2 files changed

+183
-105
lines changed

2 files changed

+183
-105
lines changed

spec/schemas.spec.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ describe('schemas', () => {
25402540

25412541
it('unset field in beforeSave should not stop object creation', done => {
25422542
const hook = {
2543-
method: function(req) {
2543+
method: function (req) {
25442544
if (req.object.get('undesiredField')) {
25452545
req.object.unset('undesiredField');
25462546
}
@@ -3110,6 +3110,77 @@ describe('schemas', () => {
31103110
});
31113111
});
31123112

3113+
it_only_db('mongo')(
3114+
'lets you add index with with pointer like structure',
3115+
done => {
3116+
request({
3117+
url: 'http://localhost:8378/1/schemas/NewClass',
3118+
method: 'POST',
3119+
headers: masterKeyHeaders,
3120+
json: true,
3121+
body: {},
3122+
}).then(() => {
3123+
request({
3124+
url: 'http://localhost:8378/1/schemas/NewClass',
3125+
method: 'PUT',
3126+
headers: masterKeyHeaders,
3127+
json: true,
3128+
body: {
3129+
fields: {
3130+
aPointer: { type: 'Pointer', targetClass: 'NewClass' },
3131+
},
3132+
indexes: {
3133+
pointer: { _p_aPointer: 1 },
3134+
},
3135+
},
3136+
}).then(response => {
3137+
expect(
3138+
dd(response.data, {
3139+
className: 'NewClass',
3140+
fields: {
3141+
ACL: { type: 'ACL' },
3142+
createdAt: { type: 'Date' },
3143+
updatedAt: { type: 'Date' },
3144+
objectId: { type: 'String' },
3145+
aPointer: { type: 'Pointer', targetClass: 'NewClass' },
3146+
},
3147+
classLevelPermissions: defaultClassLevelPermissions,
3148+
indexes: {
3149+
_id_: { _id: 1 },
3150+
pointer: { _p_aPointer: 1 },
3151+
},
3152+
})
3153+
).toEqual(undefined);
3154+
request({
3155+
url: 'http://localhost:8378/1/schemas/NewClass',
3156+
headers: masterKeyHeaders,
3157+
json: true,
3158+
}).then(response => {
3159+
expect(response.data).toEqual({
3160+
className: 'NewClass',
3161+
fields: {
3162+
ACL: { type: 'ACL' },
3163+
createdAt: { type: 'Date' },
3164+
updatedAt: { type: 'Date' },
3165+
objectId: { type: 'String' },
3166+
aPointer: { type: 'Pointer', targetClass: 'NewClass' },
3167+
},
3168+
classLevelPermissions: defaultClassLevelPermissions,
3169+
indexes: {
3170+
_id_: { _id: 1 },
3171+
pointer: { _p_aPointer: 1 },
3172+
},
3173+
});
3174+
config.database.adapter.getIndexes('NewClass').then(indexes => {
3175+
expect(indexes.length).toEqual(2);
3176+
done();
3177+
});
3178+
});
3179+
});
3180+
});
3181+
}
3182+
);
3183+
31133184
it('lets you add multiple indexes', done => {
31143185
request({
31153186
url: 'http://localhost:8378/1/schemas/NewClass',

0 commit comments

Comments
 (0)