* Add unique indexing * Add unique indexing for username/email * WIP * Finish unique indexes * Notes on how to upgrade to 2.3.0 safely * index on unique-indexes: c454180 Revert "Log objects rather than JSON stringified objects (#1922)" * reconfigure username/email tests * Start dealing with test shittyness * Remove tests for files that we are removing * most tests passing * fix failing test * Make specific server config for tests async * Fix more tests * fix more tests * Fix another test * fix more tests * Fix email validation * move some stuff around * Destroy server to ensure all connections are gone * Fix broken cloud code * Save callback to variable * no need to delete non existant cloud * undo * Fix all tests where connections are left open after server closes. * Fix issues caused by missing gridstore adapter * Update guide for 2.3.0 and fix final tests * use strict * don't use features that won't work in node 4 * Fix syntax error * Fix typos * Add duplicate finding command * Update 2.3.0.md
148 lines
3.8 KiB
JavaScript
148 lines
3.8 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);
|
||
});
|
||
}
|
||
|
||
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();
|
||
}, (err) => {
|
||
console.error();
|
||
fail('should not fail sending push')
|
||
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();
|
||
}, (err) => {
|
||
console.error();
|
||
fail('should not fail sending push')
|
||
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();
|
||
});
|
||
});
|
||
});
|
||
|
||
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) => {
|
||
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!"}');
|
||
done();
|
||
});
|
||
});
|
||
});
|
||
});
|