* Start DB runner from tests * Connect GridstoreAdapter only when needed * removes unused package * better test errors reporting * Adds support for __op.Delete * Better test error reporting * Makes sure all tests can run without crashing * Use xdescribe to skip test suite * Removes unused dependencies * Let volatiles classes be created with PG on start * Do not fail if class dont exist * adds index.spec.js to the pg suite * Use a new config each test to prevent side effects * Enable EmailVerificationToken specs with pg * Makes sure failure output is not cut * Reduces number of ignored tests in ParseObject.spec * Inspect reconfiguration errors * Mark GlobalConfig is incompatible with PG - Problem is with nested updates (param.prop = value) * PG: Nested JSON queries and updates - Adds support for nested json and . operator queries - Adds debug support for PG adapter - Adds loglevel support in helper * Enable working specs in ParseUser * Sets default logLevel in tests to undefined * Adds File type support, retores purchaseValidation specs * Adds support for updating jsonb objects - Restores PushController tests * Proper implementation of deleteByQuery and ORs - Adds ParseInstallation spec to the test suite * xit only failing tests * Nit on ParseAPI spec * add sorting operator * properly bound order keys * reverts describe_only_db behavior * Enables passing tests * Adds basic support for relations, upsertOneObject aliased to createObject * progress on queries options * Fix ACL update related problems * Creates relation tables on class creation * Adds Relation tests * remove flaky tests * use promises instead of CB * disable flaky test * nits * Fixes on schema spec - Next thing is to implemenet geopoint and files correctly * fix failues * Basic GeoPoint support * Adds support for $nearSphere/$maxDistance geopoint queries * enable passing tests * drop tables afterEach for PG, clean up relation tables too * Better initialization/dropTables
180 lines
4.5 KiB
JavaScript
180 lines
4.5 KiB
JavaScript
'use strict';
|
||
|
||
let request = require('request');
|
||
|
||
describe('Parse.Push', () => {
|
||
var setup = function() {
|
||
var pushAdapter = {
|
||
send: function(body, installations) {
|
||
var badge = body.data.badge;
|
||
let promises = installations.map((installation) => {
|
||
if (installation.deviceType == "ios") {
|
||
expect(installation.badge).toEqual(badge);
|
||
expect(installation.originalBadge+1).toEqual(installation.badge);
|
||
} else {
|
||
expect(installation.badge).toBeUndefined();
|
||
}
|
||
return Promise.resolve({
|
||
err: null,
|
||
deviceType: installation.deviceType,
|
||
result: true
|
||
})
|
||
});
|
||
return Promise.all(promises);
|
||
},
|
||
getValidPushTypes: function() {
|
||
return ["ios", "android"];
|
||
}
|
||
}
|
||
|
||
return reconfigureServer({
|
||
appId: Parse.applicationId,
|
||
masterKey: Parse.masterKey,
|
||
serverURL: Parse.serverURL,
|
||
push: {
|
||
adapter: pushAdapter
|
||
}
|
||
})
|
||
.then(() => {
|
||
var installations = [];
|
||
while(installations.length != 10) {
|
||
var installation = new Parse.Object("_Installation");
|
||
installation.set("installationId", "installation_"+installations.length);
|
||
installation.set("deviceToken","device_token_"+installations.length)
|
||
installation.set("badge", installations.length);
|
||
installation.set("originalBadge", installations.length);
|
||
installation.set("deviceType", "ios");
|
||
installations.push(installation);
|
||
}
|
||
return Parse.Object.saveAll(installations);
|
||
}).catch((err) => {
|
||
console.error(err);
|
||
})
|
||
}
|
||
|
||
it('should properly send push', (done) => {
|
||
return setup().then(() => {
|
||
return Parse.Push.send({
|
||
where: {
|
||
deviceType: 'ios'
|
||
},
|
||
data: {
|
||
badge: 'Increment',
|
||
alert: 'Hello world!'
|
||
}
|
||
}, {useMasterKey: true})
|
||
})
|
||
.then(() => {
|
||
done();
|
||
}).catch((err) => {
|
||
jfail(err);
|
||
done();
|
||
});
|
||
});
|
||
|
||
it('should properly send push with lowercaseIncrement', (done) => {
|
||
return setup().then(() => {
|
||
return Parse.Push.send({
|
||
where: {
|
||
deviceType: 'ios'
|
||
},
|
||
data: {
|
||
badge: 'increment',
|
||
alert: 'Hello world!'
|
||
}
|
||
}, {useMasterKey: true})
|
||
}).then(() => {
|
||
done();
|
||
}).catch((err) => {
|
||
jfail(err);
|
||
done();
|
||
});
|
||
});
|
||
|
||
it('should not allow clients to query _PushStatus', done => {
|
||
setup()
|
||
.then(() => Parse.Push.send({
|
||
where: {
|
||
deviceType: 'ios'
|
||
},
|
||
data: {
|
||
badge: 'increment',
|
||
alert: 'Hello world!'
|
||
}
|
||
}, {useMasterKey: true}))
|
||
.then(() => {
|
||
request.get({
|
||
url: 'http://localhost:8378/1/classes/_PushStatus',
|
||
json: true,
|
||
headers: {
|
||
'X-Parse-Application-Id': 'test',
|
||
},
|
||
}, (error, response, body) => {
|
||
expect(body.error).toEqual('unauthorized');
|
||
done();
|
||
});
|
||
}).catch((err) => {
|
||
jfail(err);
|
||
done();
|
||
});
|
||
});
|
||
|
||
it('should allow master key to query _PushStatus', done => {
|
||
setup()
|
||
.then(() => Parse.Push.send({
|
||
where: {
|
||
deviceType: 'ios'
|
||
},
|
||
data: {
|
||
badge: 'increment',
|
||
alert: 'Hello world!'
|
||
}
|
||
}, {useMasterKey: true}))
|
||
.then(() => {
|
||
request.get({
|
||
url: 'http://localhost:8378/1/classes/_PushStatus',
|
||
json: true,
|
||
headers: {
|
||
'X-Parse-Application-Id': 'test',
|
||
'X-Parse-Master-Key': 'test',
|
||
},
|
||
}, (error, response, body) => {
|
||
try {
|
||
expect(body.results.length).toEqual(1);
|
||
expect(body.results[0].query).toEqual('{"deviceType":"ios"}');
|
||
expect(body.results[0].payload).toEqual('{"badge":"increment","alert":"Hello world!"}');
|
||
} catch(e) {
|
||
jfail(e);
|
||
}
|
||
done();
|
||
});
|
||
}).catch((err) => {
|
||
jfail(err);
|
||
done();
|
||
});
|
||
});
|
||
|
||
it('should throw error if missing push configuration', done => {
|
||
reconfigureServer({push: null})
|
||
.then(() => {
|
||
return Parse.Push.send({
|
||
where: {
|
||
deviceType: 'ios'
|
||
},
|
||
data: {
|
||
badge: 'increment',
|
||
alert: 'Hello world!'
|
||
}
|
||
}, {useMasterKey: true})
|
||
}).then((response) => {
|
||
fail('should not succeed');
|
||
}, (err) => {
|
||
expect(err.code).toEqual(Parse.Error.PUSH_MISCONFIGURED);
|
||
done();
|
||
}).catch((err) => {
|
||
jfail(err);
|
||
done();
|
||
});
|
||
});
|
||
});
|