Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Cloud function afterLiveQueryEvent #6859

Merged
merged 34 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
edaf032
Before Connect + Before Subscribe #1
dblythy Jul 13, 2020
0efa36a
Merge branch 'master' into master
dplewis Jul 14, 2020
24cc493
Cleanup and Documentation
dplewis Jul 14, 2020
718a871
Add E2E tests
dplewis Jul 15, 2020
97c08b2
Bump parse to 2.15.0
dplewis Jul 16, 2020
828c678
Create afterLiveQueryEvent
dblythy Aug 12, 2020
281926e
Revert "Create afterLiveQueryEvent"
dblythy Aug 12, 2020
5fd6393
afterLiveQueryEvent
dblythy Aug 12, 2020
55ac6cb
Add delete event
dblythy Aug 12, 2020
8a977d1
Fix failing tests
dblythy Aug 12, 2020
9f21935
Merge branch 'master' into afterLiveQueryEvent
dblythy Aug 12, 2020
442e14b
Fix lint
dblythy Aug 12, 2020
75f99a8
Update ParseLiveQueryServer.js
dblythy Aug 12, 2020
a0ac8e0
Remove Facebook AccountKit auth (#6870)
dplewis Aug 20, 2020
dd419e8
fix: upgrade uuid from 8.2.0 to 8.3.0 (#6865)
snyk-bot Aug 20, 2020
603cbe5
fix: package.json & package-lock.json to reduce vulnerabilities (#6864)
snyk-bot Aug 20, 2020
cdd1afd
fix: upgrade ldapjs from 2.0.0 to 2.1.0 (#6857)
snyk-bot Aug 20, 2020
1b8b1e9
fix: upgrade apollo-server-express from 2.15.1 to 2.16.0 (#6851)
snyk-bot Aug 20, 2020
e6d69f9
fix: upgrade @graphql-tools/stitch from 6.0.12 to 6.0.13 (#6845)
snyk-bot Aug 20, 2020
d87dac1
fix: upgrade @graphql-tools/utils from 6.0.12 to 6.0.13 (#6846)
snyk-bot Aug 20, 2020
bff0ea9
[Snyk] Upgrade winston from 3.2.1 to 3.3.2 (#6799)
snyk-bot Aug 20, 2020
0ed5e8a
afterLiveQueryEvent
dblythy Aug 12, 2020
5ed6af2
Add delete event
dblythy Aug 12, 2020
85319e1
Fix failing tests
dblythy Aug 12, 2020
a51cfaa
Before Connect + Before Subscribe #1
dblythy Jul 13, 2020
3eb11b5
Cleanup and Documentation
dplewis Jul 14, 2020
ac80539
Create afterLiveQueryEvent
dblythy Aug 12, 2020
cca07d9
Revert "Create afterLiveQueryEvent"
dblythy Aug 12, 2020
58a401e
Update ParseLiveQueryServer.js
dblythy Aug 12, 2020
8401065
Rebase
dblythy Aug 21, 2020
e38afed
Merge branch 'afterLiveQueryEvent' of https://github.com/dblythy/pars…
dblythy Aug 21, 2020
ee836e6
Remove return value / deduplicate tests
dblythy Oct 14, 2020
de291ab
Add docs
dblythy Oct 19, 2020
16fbca8
Add additional data to trigger
dblythy Oct 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
281 changes: 279 additions & 2 deletions spec/ParseLiveQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,287 @@ describe('ParseLiveQuery', function () {
const query = new Parse.Query(TestObject);
query.equalTo('objectId', object.id);
const subscription = await query.subscribe();
subscription.on('update', async object => {
subscription.on('update', object => {
expect(object.get('foo')).toBe('bar');
done();
});
object.set({ foo: 'bar' });
await object.save();
});
it('expect afterEvent create', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
expect(req.event).toBe('Create');
expect(req.user).toBeUndefined();
expect(req.object.get('foo')).toBe('bar');
});

const query = new Parse.Query(TestObject);
const subscription = await query.subscribe();
subscription.on('create', object => {
expect(object.get('foo')).toBe('bar');
done();
});

const object = new TestObject();
object.set('foo', 'bar');
await object.save();
});

it('expect afterEvent payload', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
const object = new TestObject();
await object.save();

Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
expect(req.event).toBe('Update');
expect(req.user).toBeUndefined();
expect(req.object.get('foo')).toBe('bar');
expect(req.original.get('foo')).toBeUndefined();
done();
});

const query = new Parse.Query(TestObject);
query.equalTo('objectId', object.id);
await query.subscribe();
object.set({ foo: 'bar' });
await object.save();
});

it('expect afterEvent enter', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
expect(req.event).toBe('Enter');
expect(req.user).toBeUndefined();
expect(req.object.get('foo')).toBe('bar');
expect(req.original.get('foo')).toBeUndefined();
});

const object = new TestObject();
await object.save();

const query = new Parse.Query(TestObject);
query.equalTo('foo', 'bar');
const subscription = await query.subscribe();
subscription.on('enter', object => {
expect(object.get('foo')).toBe('bar');
done();
});

object.set('foo', 'bar');
await object.save();
});

it('expect afterEvent leave', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
expect(req.event).toBe('Leave');
expect(req.user).toBeUndefined();
expect(req.object.get('foo')).toBeUndefined();
expect(req.original.get('foo')).toBe('bar');
});

const object = new TestObject();
object.set('foo', 'bar');
await object.save();

const query = new Parse.Query(TestObject);
query.equalTo('foo', 'bar');
const subscription = await query.subscribe();
subscription.on('leave', object => {
expect(object.get('foo')).toBeUndefined();
done();
});

object.unset('foo');
await object.save();
});

it('expect afterEvent delete', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
expect(req.event).toBe('Delete');
expect(req.user).toBeUndefined();
req.object.set('foo', 'bar');
});

const object = new TestObject();
await object.save();

const query = new Parse.Query(TestObject);
query.equalTo('objectId', object.id);

const subscription = await query.subscribe();
subscription.on('delete', object => {
expect(object.get('foo')).toBe('bar');
done();
});

await object.destroy();
});

it('can handle afterEvent modification', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
const object = new TestObject();
await object.save();

Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
const current = req.object;
current.set('foo', 'yolo');

const original = req.original;
original.set('yolo', 'foo');
});

const query = new Parse.Query(TestObject);
query.equalTo('objectId', object.id);
const subscription = await query.subscribe();
subscription.on('update', (object, original) => {
expect(object.get('foo')).toBe('yolo');
expect(original.get('yolo')).toBe('foo');
done();
});
object.set({ foo: 'bar' });
await object.save();
});

it('can return different object in afterEvent', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
const object = new TestObject();
await object.save();

Parse.Cloud.afterLiveQueryEvent('TestObject', () => {
const object = new Parse.Object('Yolo');
return object;
});

const query = new Parse.Query(TestObject);
query.equalTo('objectId', object.id);
const subscription = await query.subscribe();
subscription.on('update', object => {
expect(object.className).toBe('Yolo');
done();
});
object.set({ foo: 'bar' });
await object.save();
});

it('can handle async afterEvent modification', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
const parent = new TestObject();
const child = new TestObject();
child.set('bar', 'foo');
await Parse.Object.saveAll([parent, child]);

Parse.Cloud.afterLiveQueryEvent('TestObject', async req => {
const current = req.object;
const pointer = current.get('child');
await pointer.fetch();
});

const query = new Parse.Query(TestObject);
query.equalTo('objectId', parent.id);
const subscription = await query.subscribe();
subscription.on('update', object => {
expect(object.get('child')).toBeDefined();
expect(object.get('child').get('bar')).toBe('foo');
done();
});
parent.set('child', child);
await parent.save();
});

it('can handle afterEvent throw', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});

const object = new TestObject();
await object.save();

Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
const current = req.object;
const original = req.original;

setTimeout(() => {
done();
}, 2000);

if (current.get('foo') != original.get('foo')) {
throw "Don't pass an update trigger, or message";
}
});

const query = new Parse.Query(TestObject);
query.equalTo('objectId', object.id);
const subscription = await query.subscribe();
subscription.on('update', () => {
fail('update should not have been called.');
});
subscription.on('error', () => {
fail('error should not have been called.');
});
object.set({ foo: 'bar' });
await object.save();
});
Expand Down Expand Up @@ -56,7 +333,7 @@ describe('ParseLiveQuery', function () {
const query = new Parse.Query(TestObject);
query.equalTo('objectId', object.id);
const subscription = await query.subscribe();
subscription.on('update', async object => {
subscription.on('update', object => {
expect(object.get('foo')).toBe('bar');
done();
});
Expand Down
Loading