From 83a9fa96b12d28cd90a273e0e7f93d7c80aa08c5 Mon Sep 17 00:00:00 2001 From: dblythy Date: Wed, 25 Nov 2020 07:38:00 +1100 Subject: [PATCH] fix: consistent casing for afterLiveQueryEvent --- spec/ParseLiveQuery.spec.js | 20 ++++++++++---------- src/LiveQuery/ParseLiveQueryServer.js | 13 +++++++------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index 870e05528a..dcbde3fb55 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -38,7 +38,7 @@ describe('ParseLiveQuery', function () { silent: true, }); Parse.Cloud.afterLiveQueryEvent('TestObject', req => { - expect(req.event).toBe('Create'); + expect(req.event).toBe('create'); expect(req.user).toBeUndefined(); expect(req.object.get('foo')).toBe('bar'); }); @@ -68,7 +68,7 @@ describe('ParseLiveQuery', function () { await object.save(); Parse.Cloud.afterLiveQueryEvent('TestObject', req => { - expect(req.event).toBe('Update'); + expect(req.event).toBe('update'); expect(req.user).toBeUndefined(); expect(req.object.get('foo')).toBe('bar'); expect(req.original.get('foo')).toBeUndefined(); @@ -92,7 +92,7 @@ describe('ParseLiveQuery', function () { silent: true, }); Parse.Cloud.afterLiveQueryEvent('TestObject', req => { - expect(req.event).toBe('Enter'); + expect(req.event).toBe('enter'); expect(req.user).toBeUndefined(); expect(req.object.get('foo')).toBe('bar'); expect(req.original.get('foo')).toBeUndefined(); @@ -123,7 +123,7 @@ describe('ParseLiveQuery', function () { silent: true, }); Parse.Cloud.afterLiveQueryEvent('TestObject', req => { - expect(req.event).toBe('Leave'); + expect(req.event).toBe('leave'); expect(req.user).toBeUndefined(); expect(req.object.get('foo')).toBeUndefined(); expect(req.original.get('foo')).toBe('bar'); @@ -155,7 +155,7 @@ describe('ParseLiveQuery', function () { silent: true, }); Parse.Cloud.afterLiveQueryEvent('TestObject', req => { - expect(req.event).toBe('Delete'); + expect(req.event).toBe('delete'); expect(req.user).toBeUndefined(); req.object.set('foo', 'bar'); }); @@ -315,7 +315,7 @@ describe('ParseLiveQuery', function () { silent: true, }); Parse.Cloud.afterLiveQueryEvent('TestObject', req => { - expect(req.event).toBe('Create'); + expect(req.event).toBe('create'); expect(req.user).toBeUndefined(); expect(req.object.get('foo')).toBe('bar'); }); @@ -345,7 +345,7 @@ describe('ParseLiveQuery', function () { await object.save(); Parse.Cloud.afterLiveQueryEvent('TestObject', req => { - expect(req.event).toBe('Update'); + expect(req.event).toBe('update'); expect(req.user).toBeUndefined(); expect(req.object.get('foo')).toBe('bar'); expect(req.original.get('foo')).toBeUndefined(); @@ -369,7 +369,7 @@ describe('ParseLiveQuery', function () { silent: true, }); Parse.Cloud.afterLiveQueryEvent('TestObject', req => { - expect(req.event).toBe('Enter'); + expect(req.event).toBe('enter'); expect(req.user).toBeUndefined(); expect(req.object.get('foo')).toBe('bar'); expect(req.original.get('foo')).toBeUndefined(); @@ -400,7 +400,7 @@ describe('ParseLiveQuery', function () { silent: true, }); Parse.Cloud.afterLiveQueryEvent('TestObject', req => { - expect(req.event).toBe('Leave'); + expect(req.event).toBe('leave'); expect(req.user).toBeUndefined(); expect(req.object.get('foo')).toBeUndefined(); expect(req.original.get('foo')).toBe('bar'); @@ -432,7 +432,7 @@ describe('ParseLiveQuery', function () { silent: true, }); Parse.Cloud.afterLiveQueryEvent('TestObject', req => { - expect(req.event).toBe('Delete'); + expect(req.event).toBe('delete'); expect(req.user).toBeUndefined(); req.object.set('foo', 'bar'); }); diff --git a/src/LiveQuery/ParseLiveQueryServer.js b/src/LiveQuery/ParseLiveQueryServer.js index 34a1756c40..fc31df46b8 100644 --- a/src/LiveQuery/ParseLiveQueryServer.js +++ b/src/LiveQuery/ParseLiveQueryServer.js @@ -160,7 +160,7 @@ class ParseLiveQueryServer { return null; } res = { - event: 'Delete', + event: 'delete', sessionToken: client.sessionToken, object: deletedParseObject, clients: this.clients.size, @@ -275,14 +275,14 @@ class ParseLiveQueryServer { // Decide event type let type; if (isOriginalMatched && isCurrentMatched) { - type = 'Update'; + type = 'update'; } else if (isOriginalMatched && !isCurrentMatched) { - type = 'Leave'; + type = 'leave'; } else if (!isOriginalMatched && isCurrentMatched) { if (originalParseObject) { - type = 'Enter'; + type = 'enter'; } else { - type = 'Create'; + type = 'create'; } } else { return null; @@ -315,7 +315,8 @@ class ParseLiveQueryServer { originalParseObject = res.original.toJSON(); originalParseObject.className = res.original.className || className; } - const functionName = 'push' + message.event; + const functionName = + 'push' + message.event.charAt(0).toUpperCase() + message.event.slice(1); if (client[functionName]) { client[functionName](requestId, currentParseObject, originalParseObject); }