2016-02-26 19:50:12 -08:00
'use strict' ;
2016-01-28 10:58:12 -08:00
// These tests check the Installations functionality of the REST API.
// Ported from installation_collection_test.go
2018-07-02 23:30:14 -04:00
const auth = require ( '../lib/Auth' ) ;
const Config = require ( '../lib/Config' ) ;
2016-12-07 15:17:05 -08:00
const Parse = require ( 'parse/node' ) . Parse ;
2018-07-02 23:30:14 -04:00
const rest = require ( '../lib/rest' ) ;
2018-09-24 17:07:51 -04:00
const request = require ( '../lib/request' ) ;
2016-06-04 09:37:15 -07:00
2016-07-23 06:23:59 +02:00
let config ;
let database ;
2020-10-25 15:06:58 -05:00
const defaultColumns = require ( '../lib/Controllers/SchemaController' ) . defaultColumns ;
2016-01-28 10:58:12 -08:00
2017-02-08 10:06:42 -08:00
const delay = function delay ( delay ) {
return new Promise ( resolve => setTimeout ( resolve , delay ) ) ;
2018-09-01 13:58:06 -04:00
} ;
2017-02-08 10:06:42 -08:00
2018-09-01 13:58:06 -04:00
const installationSchema = {
2020-10-25 15:06:58 -05:00
fields : Object . assign ( { } , defaultColumns . _Default , defaultColumns . _Installation ) ,
2018-09-01 13:58:06 -04:00
} ;
2016-01-28 10:58:12 -08:00
2016-05-28 09:25:09 -07:00
describe ( 'Installations' , ( ) => {
2016-11-24 15:47:41 -05:00
beforeEach ( ( ) => {
2017-10-23 08:43:05 -04:00
config = Config . get ( 'test' ) ;
2016-07-23 06:23:59 +02:00
database = config . database ;
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'creates an android installation with ids' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const device = 'android' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : device ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
2018-02-17 09:55:30 -05:00
const obj = results [ 0 ] ;
2017-06-20 09:15:26 -07:00
expect ( obj . installationId ) . toEqual ( installId ) ;
expect ( obj . deviceType ) . toEqual ( device ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
console . log ( error ) ;
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'creates an ios installation with ids' , done => {
2020-10-25 15:06:58 -05:00
const t = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306' ;
2018-02-17 09:55:30 -05:00
const device = 'ios' ;
const input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
deviceType : device ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
2018-02-17 09:55:30 -05:00
const obj = results [ 0 ] ;
2017-06-20 09:15:26 -07:00
expect ( obj . deviceToken ) . toEqual ( t ) ;
expect ( obj . deviceType ) . toEqual ( device ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
console . log ( error ) ;
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'creates an embedded installation with ids' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const device = 'embedded' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : device ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
2018-02-17 09:55:30 -05:00
const obj = results [ 0 ] ;
2017-06-20 09:15:26 -07:00
expect ( obj . installationId ) . toEqual ( installId ) ;
expect ( obj . deviceType ) . toEqual ( device ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
console . log ( error ) ;
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'creates an android installation with all fields' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const device = 'android' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : device ,
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
2018-02-17 09:55:30 -05:00
const obj = results [ 0 ] ;
2017-06-20 09:15:26 -07:00
expect ( obj . installationId ) . toEqual ( installId ) ;
expect ( obj . deviceType ) . toEqual ( device ) ;
expect ( typeof obj . channels ) . toEqual ( 'object' ) ;
expect ( obj . channels . length ) . toEqual ( 2 ) ;
expect ( obj . channels [ 0 ] ) . toEqual ( 'foo' ) ;
expect ( obj . channels [ 1 ] ) . toEqual ( 'bar' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
console . log ( error ) ;
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'creates an ios installation with all fields' , done => {
2020-10-25 15:06:58 -05:00
const t = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306' ;
2018-02-17 09:55:30 -05:00
const device = 'ios' ;
const input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
deviceType : device ,
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
2018-02-17 09:55:30 -05:00
const obj = results [ 0 ] ;
2017-06-20 09:15:26 -07:00
expect ( obj . deviceToken ) . toEqual ( t ) ;
expect ( obj . deviceType ) . toEqual ( device ) ;
expect ( typeof obj . channels ) . toEqual ( 'object' ) ;
expect ( obj . channels . length ) . toEqual ( 2 ) ;
expect ( obj . channels [ 0 ] ) . toEqual ( 'foo' ) ;
expect ( obj . channels [ 1 ] ) . toEqual ( 'bar' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
console . log ( error ) ;
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'should properly fail queying installations' , done => {
2025-11-23 13:51:42 +01:00
const logger = require ( '../lib/logger' ) . default ;
const loggerErrorSpy = spyOn ( logger , 'error' ) . and . callThrough ( ) ;
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const device = 'android' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : device ,
2016-04-05 13:09:40 -04:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( ( ) => {
2025-11-23 13:51:42 +01:00
loggerErrorSpy . calls . reset ( ) ;
2017-06-20 09:15:26 -07:00
const query = new Parse . Query ( Parse . Installation ) ;
2018-09-01 13:58:06 -04:00
return query . find ( ) ;
} )
. then ( ( ) => {
2017-06-20 09:15:26 -07:00
fail ( 'Should not succeed!' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2025-11-23 13:51:42 +01:00
expect ( error . code ) . toBe ( Parse . Error . OPERATION _FORBIDDEN ) ;
2018-09-01 13:58:06 -04:00
expect ( error . message ) . toBe (
2025-11-23 13:51:42 +01:00
'Permission denied'
2018-09-01 13:58:06 -04:00
) ;
2025-11-23 13:51:42 +01:00
expect ( loggerErrorSpy ) . toHaveBeenCalledWith ( 'Sanitized error:' , jasmine . stringContaining ( "Clients aren't allowed to perform the find operation on the installation collection." ) ) ;
2017-06-20 09:15:26 -07:00
done ( ) ;
} ) ;
2016-04-05 13:09:40 -04:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'should properly queying installations with masterKey' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const device = 'android' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : device ,
2016-04-05 13:09:40 -04:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( ( ) => {
const query = new Parse . Query ( Parse . Installation ) ;
2018-09-01 13:58:06 -04:00
return query . find ( { useMasterKey : true } ) ;
} )
. then ( results => {
2017-06-20 09:15:26 -07:00
expect ( results . length ) . toEqual ( 1 ) ;
2018-02-17 09:55:30 -05:00
const obj = results [ 0 ] . toJSON ( ) ;
2017-06-20 09:15:26 -07:00
expect ( obj . installationId ) . toEqual ( installId ) ;
expect ( obj . deviceType ) . toEqual ( device ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( ( ) => {
2017-06-20 09:15:26 -07:00
fail ( 'Should not fail' ) ;
done ( ) ;
} ) ;
2016-04-05 13:09:40 -04:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'fails with missing ids' , done => {
2018-02-17 09:55:30 -05:00
const input = {
2018-09-01 13:58:06 -04:00
deviceType : 'android' ,
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( ( ) => {
fail ( 'Should not have been able to create an Installation.' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
expect ( error . code ) . toEqual ( 135 ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'fails for android with missing type' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( ( ) => {
fail ( 'Should not have been able to create an Installation.' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
expect ( error . code ) . toEqual ( 135 ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'creates an object with custom fields' , done => {
2020-10-25 15:06:58 -05:00
const t = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306' ;
2018-02-17 09:55:30 -05:00
const input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
deviceType : 'ios' ,
channels : [ 'foo' , 'bar' ] ,
custom : 'allowed' ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
2018-02-17 09:55:30 -05:00
const obj = results [ 0 ] ;
2017-06-20 09:15:26 -07:00
expect ( obj . custom ) . toEqual ( 'allowed' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
console . log ( error ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
// Note: did not port test 'TestObjectIDForIdentifiers'
2018-09-01 13:58:06 -04:00
it ( 'merging when installationId already exists' , done => {
2018-02-17 09:55:30 -05:00
const installId1 = '12345678-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306' ;
2018-02-17 09:55:30 -05:00
const input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
deviceType : 'ios' ,
installationId : installId1 ,
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-02-17 09:55:30 -05:00
let firstObject ;
let secondObject ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
firstObject = results [ 0 ] ;
delete input . deviceToken ;
delete input . channels ;
input [ 'foo' ] = 'bar' ;
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
secondObject = results [ 0 ] ;
expect ( firstObject . _id ) . toEqual ( secondObject . _id ) ;
expect ( secondObject . channels . length ) . toEqual ( 2 ) ;
expect ( secondObject . foo ) . toEqual ( 'bar' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
console . log ( error ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'merging when two objects both only have one id' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2018-02-17 09:55:30 -05:00
const input1 = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : 'ios' ,
2016-01-28 10:58:12 -08:00
} ;
2018-02-17 09:55:30 -05:00
const input2 = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
deviceType : 'ios' ,
2016-01-28 10:58:12 -08:00
} ;
2018-02-17 09:55:30 -05:00
const input3 = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
installationId : installId ,
deviceType : 'ios' ,
2016-01-28 10:58:12 -08:00
} ;
2018-02-17 09:55:30 -05:00
let firstObject ;
let secondObject ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input1 )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
firstObject = results [ 0 ] ;
2020-10-25 15:06:58 -05:00
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input2 ) ;
2017-06-20 09:15:26 -07:00
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 2 ) ;
if ( results [ 0 ] [ '_id' ] == firstObject . _id ) {
secondObject = results [ 1 ] ;
} else {
secondObject = results [ 0 ] ;
}
2020-10-25 15:06:58 -05:00
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input3 ) ;
2017-06-20 09:15:26 -07:00
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] [ '_id' ] ) . toEqual ( secondObject . _id ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
xit ( 'creating multiple devices with same device token works' , done => {
2018-02-17 09:55:30 -05:00
const installId1 = '11111111-abcd-abcd-abcd-123456789abc' ;
const installId2 = '22222222-abcd-abcd-abcd-123456789abc' ;
const installId3 = '33333333-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2018-02-17 09:55:30 -05:00
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId1 ,
deviceType : 'ios' ,
deviceToken : t ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( ( ) => {
input . installationId = installId2 ;
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
2018-09-01 13:58:06 -04:00
} )
. then ( ( ) => {
2017-06-20 09:15:26 -07:00
input . installationId = installId3 ;
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
} )
2018-09-01 13:58:06 -04:00
. then ( ( ) =>
database . adapter . find (
'_Installation' ,
{ installationId : installId1 } ,
installationSchema ,
{ }
)
)
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
2018-09-01 13:58:06 -04:00
return database . adapter . find (
'_Installation' ,
{ installationId : installId2 } ,
installationSchema ,
{ }
) ;
} )
. then ( results => {
2017-06-20 09:15:26 -07:00
expect ( results . length ) . toEqual ( 1 ) ;
2018-09-01 13:58:06 -04:00
return database . adapter . find (
'_Installation' ,
{ installationId : installId3 } ,
installationSchema ,
{ }
) ;
} )
. then ( results => {
2017-06-20 09:15:26 -07:00
expect ( results . length ) . toEqual ( 1 ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
console . log ( error ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2024-08-13 22:13:19 +02:00
it _id ( '95955e90-04bc-4437-920e-b84bc30dba01' ) ( it ) ( 'updating with new channels' , done => {
2018-02-17 09:55:30 -05:00
const input = {
2016-05-28 09:25:09 -07:00
installationId : '12345678-abcd-abcd-abcd-123456789abc' ,
deviceType : 'android' ,
2018-09-01 13:58:06 -04:00
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
2018-02-17 09:55:30 -05:00
const objectId = results [ 0 ] . objectId ;
const update = {
2018-09-01 13:58:06 -04:00
channels : [ 'baz' ] ,
2017-06-20 09:15:26 -07:00
} ;
2020-10-25 15:06:58 -05:00
return rest . update ( config , auth . nobody ( config ) , '_Installation' , { objectId } , update ) ;
2017-06-20 09:15:26 -07:00
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] . channels . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] . channels [ 0 ] ) . toEqual ( 'baz' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'update android fails with new installation id' , done => {
2018-02-17 09:55:30 -05:00
const installId1 = '12345678-abcd-abcd-abcd-123456789abc' ;
const installId2 = '87654321-abcd-abcd-abcd-123456789abc' ;
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId1 ,
deviceType : 'android' ,
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
2018-09-01 13:58:06 -04:00
input = { installationId : installId2 } ;
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : results [ 0 ] . objectId } ,
input
) ;
} )
. then ( ( ) => {
2017-06-20 09:15:26 -07:00
fail ( 'Updating the installation should have failed.' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
expect ( error . code ) . toEqual ( 136 ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'update ios fails with new deviceToken and no installationId' , done => {
2020-10-25 15:06:58 -05:00
const a = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306' ;
const b = '91433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306' ;
2018-02-17 09:55:30 -05:00
let input = {
2018-09-01 13:58:06 -04:00
deviceToken : a ,
deviceType : 'ios' ,
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
2018-09-01 13:58:06 -04:00
input = { deviceToken : b } ;
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : results [ 0 ] . objectId } ,
input
) ;
} )
. then ( ( ) => {
2017-06-20 09:15:26 -07:00
fail ( 'Updating the installation should have failed.' ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
expect ( error . code ) . toEqual ( 136 ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'update ios updates device token' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306' ;
const u = '91433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306' ;
2018-02-17 09:55:30 -05:00
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : 'ios' ,
deviceToken : t ,
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceToken : u ,
deviceType : 'ios' ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-01 13:58:06 -04:00
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : results [ 0 ] . objectId } ,
input
) ;
2017-06-20 09:15:26 -07:00
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] . deviceToken ) . toEqual ( u ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( err => {
2017-06-20 09:15:26 -07:00
jfail ( err ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'update fails to change deviceType' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : 'android' ,
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
input = {
2018-09-01 13:58:06 -04:00
deviceType : 'ios' ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-01 13:58:06 -04:00
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : results [ 0 ] . objectId } ,
input
) ;
} )
. then ( ( ) => {
2017-06-20 09:15:26 -07:00
fail ( 'Should not have been able to update Installation.' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
expect ( error . code ) . toEqual ( 136 ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'update android with custom field' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : 'android' ,
channels : [ 'foo' , 'bar' ] ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
input = {
2018-09-01 13:58:06 -04:00
custom : 'allowed' ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-01 13:58:06 -04:00
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : results [ 0 ] . objectId } ,
input
) ;
2017-06-20 09:15:26 -07:00
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] [ 'custom' ] ) . toEqual ( 'allowed' ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2019-05-02 13:59:01 -05:00
it ( 'update android device token with duplicate device token' , async ( ) => {
2018-02-17 09:55:30 -05:00
const installId1 = '11111111-abcd-abcd-abcd-123456789abc' ;
const installId2 = '22222222-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2019-05-02 13:59:01 -05:00
2018-02-17 09:55:30 -05:00
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId1 ,
deviceToken : t ,
deviceType : 'android' ,
2016-02-26 21:05:46 -05:00
} ;
2019-05-02 13:59:01 -05:00
await rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
input = {
installationId : installId2 ,
deviceType : 'android' ,
} ;
await rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
await delay ( 100 ) ;
let results = await database . adapter . find (
'_Installation' ,
installationSchema ,
{ installationId : installId1 } ,
{ }
) ;
expect ( results . length ) . toEqual ( 1 ) ;
const firstObject = results [ 0 ] ;
results = await database . adapter . find (
'_Installation' ,
installationSchema ,
{ installationId : installId2 } ,
{ }
) ;
expect ( results . length ) . toEqual ( 1 ) ;
const secondObject = results [ 0 ] ;
// Update second installation to conflict with first installation
input = {
objectId : secondObject . objectId ,
deviceToken : t ,
} ;
await rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : secondObject . objectId } ,
input
) ;
await delay ( 100 ) ;
results = await database . adapter . find (
'_Installation' ,
installationSchema ,
{ objectId : firstObject . objectId } ,
{ }
) ;
expect ( results . length ) . toEqual ( 0 ) ;
2016-02-26 21:05:46 -05:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'update ios device token with duplicate device token' , done => {
2018-02-17 09:55:30 -05:00
const installId1 = '11111111-abcd-abcd-abcd-123456789abc' ;
const installId2 = '22222222-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2018-02-17 09:55:30 -05:00
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId1 ,
deviceToken : t ,
deviceType : 'ios' ,
2016-01-28 10:58:12 -08:00
} ;
2018-02-17 09:55:30 -05:00
let firstObject ;
let secondObject ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( ( ) => {
input = {
2018-09-01 13:58:06 -04:00
installationId : installId2 ,
deviceType : 'ios' ,
2017-06-20 09:15:26 -07:00
} ;
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
} )
. then ( ( ) => delay ( 100 ) )
2018-09-01 13:58:06 -04:00
. then ( ( ) =>
database . adapter . find (
'_Installation' ,
installationSchema ,
{ installationId : installId1 } ,
{ }
)
)
. then ( results => {
2017-06-20 09:15:26 -07:00
expect ( results . length ) . toEqual ( 1 ) ;
firstObject = results [ 0 ] ;
} )
. then ( ( ) => delay ( 100 ) )
2018-09-01 13:58:06 -04:00
. then ( ( ) =>
database . adapter . find (
'_Installation' ,
installationSchema ,
{ installationId : installId2 } ,
{ }
)
)
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
secondObject = results [ 0 ] ;
// Update second installation to conflict with first installation id
input = {
2018-09-01 13:58:06 -04:00
installationId : installId2 ,
deviceToken : t ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-01 13:58:06 -04:00
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : secondObject . objectId } ,
input
) ;
2017-06-20 09:15:26 -07:00
} )
. then ( ( ) => delay ( 100 ) )
2018-09-01 13:58:06 -04:00
. then ( ( ) =>
database . adapter . find (
'_Installation' ,
installationSchema ,
{ objectId : firstObject . objectId } ,
{ }
)
)
2017-06-20 09:15:26 -07:00
. then ( results => {
2018-09-01 13:58:06 -04:00
// The first object should have been deleted
2017-06-20 09:15:26 -07:00
expect ( results . length ) . toEqual ( 0 ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
xit ( 'update ios device token with duplicate token different app' , done => {
2018-02-17 09:55:30 -05:00
const installId1 = '11111111-abcd-abcd-abcd-123456789abc' ;
const installId2 = '22222222-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2018-02-17 09:55:30 -05:00
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId1 ,
deviceToken : t ,
deviceType : 'ios' ,
appIdentifier : 'foo' ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( ( ) => {
input . installationId = installId2 ;
input . appIdentifier = 'bar' ;
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
2018-09-01 13:58:06 -04:00
// The first object should have been deleted during merge
2017-06-20 09:15:26 -07:00
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] . installationId ) . toEqual ( installId2 ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'update ios token and channels' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2018-02-17 09:55:30 -05:00
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : 'ios' ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
channels : [ ] ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-01 13:58:06 -04:00
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : results [ 0 ] . objectId } ,
input
) ;
2017-06-20 09:15:26 -07:00
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] . installationId ) . toEqual ( installId ) ;
expect ( results [ 0 ] . deviceToken ) . toEqual ( t ) ;
expect ( results [ 0 ] . channels . length ) . toEqual ( 0 ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'update ios linking two existing objects' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2018-02-17 09:55:30 -05:00
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : 'ios' ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( ( ) => {
input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
deviceType : 'ios' ,
2017-06-20 09:15:26 -07:00
} ;
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
} )
2018-09-01 13:58:06 -04:00
. then ( ( ) =>
2020-10-25 15:06:58 -05:00
database . adapter . find ( '_Installation' , installationSchema , { deviceToken : t } , { } )
2018-09-01 13:58:06 -04:00
)
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
installationId : installId ,
deviceType : 'ios' ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-01 13:58:06 -04:00
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : results [ 0 ] . objectId } ,
input
) ;
2017-06-20 09:15:26 -07:00
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] . installationId ) . toEqual ( installId ) ;
expect ( results [ 0 ] . deviceToken ) . toEqual ( t ) ;
expect ( results [ 0 ] . deviceType ) . toEqual ( 'ios' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2024-08-13 22:13:19 +02:00
it _id ( '22311bc7-3f4f-42c1-a958-57083929e80d' ) ( it ) ( 'update is linking two existing objects w/ increment' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2018-02-17 09:55:30 -05:00
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : 'ios' ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( ( ) => {
input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
deviceType : 'ios' ,
2017-06-20 09:15:26 -07:00
} ;
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
} )
2018-09-01 13:58:06 -04:00
. then ( ( ) =>
2020-10-25 15:06:58 -05:00
database . adapter . find ( '_Installation' , installationSchema , { deviceToken : t } , { } )
2018-09-01 13:58:06 -04:00
)
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
installationId : installId ,
deviceType : 'ios' ,
score : {
_ _op : 'Increment' ,
amount : 1 ,
} ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-01 13:58:06 -04:00
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : results [ 0 ] . objectId } ,
input
) ;
2017-06-20 09:15:26 -07:00
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] . installationId ) . toEqual ( installId ) ;
expect ( results [ 0 ] . deviceToken ) . toEqual ( t ) ;
expect ( results [ 0 ] . deviceType ) . toEqual ( 'ios' ) ;
expect ( results [ 0 ] . score ) . toEqual ( 1 ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'update is linking two existing with installation id' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2018-02-17 09:55:30 -05:00
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : 'ios' ,
2016-01-28 10:58:12 -08:00
} ;
2018-02-17 09:55:30 -05:00
let installObj ;
let tokenObj ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
installObj = results [ 0 ] ;
input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
deviceType : 'ios' ,
2017-06-20 09:15:26 -07:00
} ;
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
} )
2018-09-01 13:58:06 -04:00
. then ( ( ) =>
2020-10-25 15:06:58 -05:00
database . adapter . find ( '_Installation' , installationSchema , { deviceToken : t } , { } )
2018-09-01 13:58:06 -04:00
)
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
tokenObj = results [ 0 ] ;
input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceToken : t ,
deviceType : 'ios' ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-01 13:58:06 -04:00
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : installObj . objectId } ,
input
) ;
2017-06-20 09:15:26 -07:00
} )
2018-09-01 13:58:06 -04:00
. then ( ( ) =>
database . adapter . find (
'_Installation' ,
installationSchema ,
{ objectId : tokenObj . objectId } ,
{ }
)
)
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] . installationId ) . toEqual ( installId ) ;
expect ( results [ 0 ] . deviceToken ) . toEqual ( t ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2024-08-13 22:13:19 +02:00
it _id ( 'f2975078-eab7-4287-a932-288842e3cfb9' ) ( it ) ( 'update is linking two existing with installation id w/ op' , done => {
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2018-02-17 09:55:30 -05:00
let input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : 'ios' ,
2016-01-28 10:58:12 -08:00
} ;
2018-02-17 09:55:30 -05:00
let installObj ;
let tokenObj ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
installObj = results [ 0 ] ;
input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
deviceType : 'ios' ,
2017-06-20 09:15:26 -07:00
} ;
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
} )
2018-09-01 13:58:06 -04:00
. then ( ( ) =>
2020-10-25 15:06:58 -05:00
database . adapter . find ( '_Installation' , installationSchema , { deviceToken : t } , { } )
2018-09-01 13:58:06 -04:00
)
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
tokenObj = results [ 0 ] ;
input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceToken : t ,
deviceType : 'ios' ,
score : {
_ _op : 'Increment' ,
amount : 1 ,
} ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-01 13:58:06 -04:00
return rest . update (
config ,
auth . nobody ( config ) ,
'_Installation' ,
{ objectId : installObj . objectId } ,
input
) ;
2017-06-20 09:15:26 -07:00
} )
2018-09-01 13:58:06 -04:00
. then ( ( ) =>
database . adapter . find (
'_Installation' ,
installationSchema ,
{ objectId : tokenObj . objectId } ,
{ }
)
)
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] . installationId ) . toEqual ( installId ) ;
expect ( results [ 0 ] . deviceToken ) . toEqual ( t ) ;
expect ( results [ 0 ] . score ) . toEqual ( 1 ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
jfail ( error ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2018-09-01 13:58:06 -04:00
it ( 'ios merge existing same token no installation id' , done => {
2016-01-28 10:58:12 -08:00
// Test creating installation when there is an existing object with the
// same device token but no installation ID. This is possible when
// developers import device tokens from another push provider; the import
// process does not generate installation IDs. When they later integrate
// the Parse SDK, their app is going to save the installation. This save
// op will have a client-generated installation ID as well as a device
// token. At this point, if the device token matches the originally-
// imported installation, then we should reuse the existing installation
// object in case the developer already added additional fields via Data
// Browser or REST API (e.g. channel targeting info).
2020-10-25 15:06:58 -05:00
const t = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
2018-02-17 09:55:30 -05:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
let input = {
2018-09-01 13:58:06 -04:00
deviceToken : t ,
deviceType : 'ios' ,
2016-01-28 10:58:12 -08:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceToken : t ,
deviceType : 'ios' ,
2017-06-20 09:15:26 -07:00
} ;
return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
} )
2020-10-25 15:06:58 -05:00
. then ( ( ) => database . adapter . find ( '_Installation' , installationSchema , { } , { } ) )
2017-06-20 09:15:26 -07:00
. then ( results => {
expect ( results . length ) . toEqual ( 1 ) ;
expect ( results [ 0 ] . deviceToken ) . toEqual ( t ) ;
expect ( results [ 0 ] . installationId ) . toEqual ( installId ) ;
done ( ) ;
} )
. catch ( error => {
console . log ( error ) ;
fail ( ) ;
done ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
} ) ;
2016-06-04 09:37:15 -07:00
it ( 'allows you to get your own installation (regression test for #1718)' , done => {
2016-12-07 15:17:05 -08:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const device = 'android' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : device ,
2016-06-04 09:37:15 -07:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( createResult => {
const headers = {
'X-Parse-Application-Id' : 'test' ,
2018-09-01 13:58:06 -04:00
'X-Parse-REST-API-Key' : 'rest' ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-24 17:07:51 -04:00
return request ( {
headers : headers ,
2020-10-25 15:06:58 -05:00
url : 'http://localhost:8378/1/installations/' + createResult . response . objectId ,
2018-09-24 17:07:51 -04:00
} ) . then ( response => {
const body = response . data ;
expect ( body . objectId ) . toEqual ( createResult . response . objectId ) ;
done ( ) ;
} ) ;
2017-06-20 09:15:26 -07:00
} )
. catch ( error => {
console . log ( error ) ;
fail ( 'failed' ) ;
2016-06-04 09:37:15 -07:00
done ( ) ;
} ) ;
} ) ;
2016-09-24 13:42:36 -04:00
it ( 'allows you to update installation from header (#2090)' , done => {
2016-12-07 15:17:05 -08:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const device = 'android' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : device ,
2016-09-24 13:42:36 -04:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( ( ) => {
const headers = {
'X-Parse-Application-Id' : 'test' ,
2018-09-01 13:58:06 -04:00
'X-Parse-REST-API-Key' : 'rest' ,
'X-Parse-Installation-Id' : installId ,
2017-06-20 09:15:26 -07:00
} ;
2018-09-24 17:07:51 -04:00
request ( {
method : 'POST' ,
headers : headers ,
url : 'http://localhost:8378/1/classes/_Installation' ,
json : true ,
body : {
date : new Date ( ) ,
2018-09-01 13:58:06 -04:00
} ,
2018-09-24 17:07:51 -04:00
} ) . then ( response => {
const body = response . data ;
expect ( response . status ) . toBe ( 200 ) ;
expect ( body . updatedAt ) . not . toBeUndefined ( ) ;
done ( ) ;
} ) ;
2017-06-20 09:15:26 -07:00
} )
. catch ( error => {
console . log ( error ) ;
fail ( 'failed' ) ;
2016-09-24 13:42:36 -04:00
done ( ) ;
} ) ;
} ) ;
2016-10-19 15:06:19 -04:00
it ( 'allows you to update installation with masterKey' , done => {
2016-12-07 15:17:05 -08:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const device = 'android' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : device ,
2016-10-19 15:06:19 -04:00
} ;
2018-09-01 13:58:06 -04:00
rest
. create ( config , auth . nobody ( config ) , '_Installation' , input )
2017-06-20 09:15:26 -07:00
. then ( createResult => {
2018-09-01 13:58:06 -04:00
const installationObj = Parse . Installation . createWithoutData (
createResult . response . objectId
) ;
2017-06-20 09:15:26 -07:00
installationObj . set ( 'customField' , 'custom value' ) ;
2018-09-01 13:58:06 -04:00
return installationObj . save ( null , { useMasterKey : true } ) ;
} )
. then ( updateResult => {
2017-06-20 09:15:26 -07:00
expect ( updateResult ) . not . toBeUndefined ( ) ;
expect ( updateResult . get ( 'customField' ) ) . toEqual ( 'custom value' ) ;
done ( ) ;
2018-09-01 13:58:06 -04:00
} )
. catch ( error => {
2017-06-20 09:15:26 -07:00
console . log ( error ) ;
fail ( 'failed' ) ;
done ( ) ;
} ) ;
2016-10-19 15:06:19 -04:00
} ) ;
2016-10-19 19:54:19 -04:00
it ( 'should properly handle installation save #2780' , done => {
2016-12-07 15:17:05 -08:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const device = 'android' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : device ,
2016-10-19 19:54:19 -04:00
} ;
2020-10-25 15:06:58 -05:00
rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) . then ( ( ) => {
const query = new Parse . Query ( Parse . Installation ) ;
query . equalTo ( 'installationId' , installId ) ;
query
. first ( { useMasterKey : true } )
. then ( installation => {
return installation . save (
{
key : 'value' ,
2018-09-01 13:58:06 -04:00
} ,
2020-10-25 15:06:58 -05:00
{ useMasterKey : true }
2018-09-01 13:58:06 -04:00
) ;
2020-10-25 15:06:58 -05:00
} )
. then (
( ) => {
done ( ) ;
} ,
err => {
jfail ( err ) ;
done ( ) ;
}
) ;
} ) ;
2016-10-19 19:54:19 -04:00
} ) ;
it ( 'should properly reject updating installationId' , done => {
2016-12-07 15:17:05 -08:00
const installId = '12345678-abcd-abcd-abcd-123456789abc' ;
const device = 'android' ;
const input = {
2018-09-01 13:58:06 -04:00
installationId : installId ,
deviceType : device ,
} ;
2020-10-25 15:06:58 -05:00
rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) . then ( ( ) => {
const query = new Parse . Query ( Parse . Installation ) ;
query . equalTo ( 'installationId' , installId ) ;
query
. first ( { useMasterKey : true } )
. then ( installation => {
return installation . save (
{
key : 'value' ,
installationId : '22222222-abcd-abcd-abcd-123456789abc' ,
2018-09-01 13:58:06 -04:00
} ,
2020-10-25 15:06:58 -05:00
{ useMasterKey : true }
2018-09-01 13:58:06 -04:00
) ;
2020-10-25 15:06:58 -05:00
} )
. then (
( ) => {
fail ( 'should not succeed' ) ;
done ( ) ;
} ,
err => {
expect ( err . code ) . toBe ( 136 ) ;
expect ( err . message ) . toBe ( 'installationId may not be changed in this operation' ) ;
done ( ) ;
}
) ;
} ) ;
2016-10-19 19:54:19 -04:00
} ) ;
2024-08-13 22:13:19 +02:00
it _id ( 'e581faea-c1b4-4c64-af8c-52287ce6cd06' ) ( it ) ( 'can use push with beforeSave' , async ( ) => {
2022-09-17 05:43:03 +10:00
const input = {
deviceToken : '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306' ,
deviceType : 'ios' ,
} ;
2022-10-03 22:55:05 +11:00
await rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
2022-09-17 05:43:03 +10:00
const functions = {
beforeSave ( ) { } ,
2022-10-03 22:55:05 +11:00
afterSave ( ) { } ,
} ;
2022-09-17 05:43:03 +10:00
spyOn ( functions , 'beforeSave' ) . and . callThrough ( ) ;
spyOn ( functions , 'afterSave' ) . and . callThrough ( ) ;
Parse . Cloud . beforeSave ( Parse . Installation , functions . beforeSave ) ;
Parse . Cloud . afterSave ( Parse . Installation , functions . afterSave ) ;
await Parse . Push . send ( {
where : {
deviceType : 'ios' ,
} ,
data : {
badge : 'increment' ,
alert : 'Hello world!' ,
} ,
} ) ;
await Parse . Push . send ( {
where : {
deviceType : 'ios' ,
} ,
data : {
badge : 'increment' ,
alert : 'Hello world!' ,
} ,
} ) ;
await Parse . Push . send ( {
where : {
deviceType : 'ios' ,
} ,
data : {
badge : 'increment' ,
alert : 'Hello world!' ,
} ,
} ) ;
await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
2022-10-03 22:55:05 +11:00
const installation = await new Parse . Query ( Parse . Installation ) . first ( { useMasterKey : true } ) ;
2022-09-17 05:43:03 +10:00
expect ( installation . get ( 'badge' ) ) . toEqual ( 3 ) ;
expect ( functions . beforeSave ) . not . toHaveBeenCalled ( ) ;
expect ( functions . afterSave ) . not . toHaveBeenCalled ( ) ;
} ) ;
2016-01-28 10:58:12 -08:00
// TODO: Look at additional tests from installation_collection_test.go:882
// TODO: Do we need to support _tombstone disabling of installations?
// TODO: Test deletion, badge increments
} ) ;