11var REST_REQUESTS_TIMEOUT = 3000 ;
22
3- describe ( 'PushNotifications API' , function ( ) {
3+ describe ( "PushNotifications API" , function ( ) {
4+ var params ;
45
56 beforeAll ( function ( done ) {
67 QB . init ( CREDENTIALS . appId , CREDENTIALS . authKey , CREDENTIALS . authSecret ) ;
@@ -10,54 +11,65 @@ describe('PushNotifications API', function() {
1011 done . fail ( "Create session error: " + JSON . stringify ( err ) ) ;
1112 } else {
1213 expect ( session ) . not . toBeNull ( ) ;
13- token = session . token ;
14- console . log ( token ) ;
1514 done ( ) ;
1615 }
1716 } ) ;
1817 } , REST_REQUESTS_TIMEOUT ) ;
1918
20- describe ( ' Subscriptions' , function ( ) {
19+ describe ( " Subscriptions" , function ( ) {
2120
22- it ( 'can create a subscription' , function ( done ) {
23- var params = { notification_channels : 'apns' } ;
21+ it ( "can create a subscription" , function ( done ) {
22+ params = {
23+ notification_channels : "gcm" ,
24+ device : {
25+ platform : "android" ,
26+ udid : "jasmineUnique"
27+ } ,
28+ push_token : {
29+ environment : "development" ,
30+ client_identification_sequence :"APA91bH91emYD8BYyveyO0C9M--p8xW9yTr1k_Nzr8-SfjCfSIljzYqNIX9fK9JxPsWm3NQ6P-" +
31+ "zCDkdtktVLEYJI5CLfg_3_auErc_29piz2zLHp5OjK0RdFnod-j0Pclo-a57FaKWxvNSr_EBwbP" +
32+ "_oFDuXo1x0ucQ"
33+ }
34+ } ;
2435 QB . pushnotifications . subscriptions . create ( params , function ( err , res ) {
2536 if ( err ) {
2637 done . fail ( "Create a subscription error: " + JSON . stringify ( err ) ) ;
2738 } else {
28- subscription = res ;
29- expect ( subscription ) . not . toBeNull ( ) ;
30- expect ( subscription . token ) . not . toBeNull ( ) ;
31- console . log ( subscription ) ;
39+ expect ( res ) . not . toBeNull ( ) ;
40+ expect ( res [ 0 ] . subscription . device . platform . name ) . toBe ( "android" ) ;
41+ console . info ( "can create a subscription" ) ;
3242 done ( ) ;
3343 }
3444 } ) ;
3545 } ) ;
3646
37- it ( ' can list a subscription' , function ( done ) {
47+ it ( " can list a subscription" , function ( done ) {
3848 QB . pushnotifications . subscriptions . list ( function ( err , result ) {
3949 if ( err ) {
4050 done . fail ( "List a subscription error: " + JSON . stringify ( err ) ) ;
4151 } else {
4252 expect ( result ) . not . toBeNull ( ) ;
43- expect ( result . length ) . not . toBeNull ( ) ;
44- console . log ( result ) ;
53+ expect ( result [ 0 ] . subscription . device . udid ) . toBe ( "jasmineUnique" ) ;
54+ console . info ( "can list a subscription" ) ;
4555 done ( ) ;
4656 }
4757 } ) ;
4858 } ) ;
4959
50- it ( ' can delete subscription' , function ( done ) {
60+ it ( " can delete subscription" , function ( done ) {
5161 QB . pushnotifications . subscriptions . list ( function ( err , result ) {
5262 if ( err ) {
5363 done . fail ( "List a subscription error: " + JSON . stringify ( err ) ) ;
5464 } else {
55- QB . pushnotifications . subscriptions . delete ( id , function ( err , res ) {
65+ var subscriptionId = result [ 0 ] . subscription . id ;
66+ QB . pushnotifications . subscriptions . delete ( subscriptionId , function ( err , res ) {
5667 if ( err ) {
5768 done . fail ( "Delete subscription error: " + JSON . stringify ( err ) ) ;
5869 } else {
59- console . log ( res ) ;
60- expect ( res ) . toBeNull ( ) ;
70+ expect ( res ) . not . toBeNull ( ) ;
71+ expect ( res ) . toBe ( true ) ;
72+ console . info ( "can delete subscription" ) ;
6173 done ( ) ;
6274 }
6375 } ) ;
@@ -67,48 +79,108 @@ describe('PushNotifications API', function() {
6779
6880 } ) ;
6981
70- /*describe('Events', function(){
71- it('can create a pull event', function(){
72- var done, result;
73- runs(function(){
74- done = false;
75- params = {notification_type: 'pull', environment:'production', message: window.btoa('QuickBlox JavaScript SDK Spec Event'),
76- user: { id : [239647, 245530]},
77- end_date: Math.floor((Date.now() / 1000) +(24*60*60)).toString()};
78- QB.pushnotifications.events.create(params, function(err, res){
79- result = res;
80- done = true;
81- expect(err).toBeNull();
82- });
82+ describe ( "Events" , function ( ) {
83+ var eventId ;
84+
85+ beforeAll ( function ( done ) {
86+ QB . pushnotifications . subscriptions . create ( params , function ( err , res ) {
87+ if ( err ) {
88+ done . fail ( "Create a subscription error: " + JSON . stringify ( err ) ) ;
89+ } else {
90+ expect ( res ) . not . toBeNull ( ) ;
91+ done ( ) ;
92+ }
93+ } ) ;
94+ } ) ;
95+
96+ it ( "can create event" , function ( done ) {
97+ var params = {
98+ notification_type : "push" ,
99+ push_type : "gcm" ,
100+ user : { ids : [ QBUser1 . id ] } ,
101+ environment : "development" ,
102+ message : QB . pushnotifications . base64Encode ( "hello QuickBlox!" )
103+ } ;
104+
105+ QB . pushnotifications . events . create ( params , function ( err , response ) {
106+ if ( err ) {
107+ done . fail ( "Create event error: " + JSON . stringify ( err ) ) ;
108+ } else {
109+ expect ( response ) . not . toBeNull ( ) ;
110+ expect ( response . event . message ) . toBe ( "data.message=aGVsbG8rUXVpY2tCbG94JTIx" ) ;
111+ console . info ( "can create event" ) ;
112+ done ( ) ;
113+ }
114+ } ) ;
115+ } ) ;
116+
117+ it ( "can list events" , function ( done ) {
118+ QB . pushnotifications . events . list ( { page : "1" , per_page : "25" } , function ( err , response ) {
119+ if ( err ) {
120+ done . fail ( "List events error: " + JSON . stringify ( err ) ) ;
121+ } else {
122+ eventId = response . items [ 0 ] . event . id ;
123+ expect ( response ) . not . toBeNull ( ) ;
124+ expect ( response . items . length ) . toBeGreaterThan ( 0 ) ;
125+ console . info ( "can list events" ) ;
126+ done ( ) ;
127+ }
128+ } ) ;
129+ } ) ;
130+
131+ it ( "can get event by id" , function ( done ) {
132+ QB . pushnotifications . events . get ( eventId , function ( err , response ) {
133+ if ( err ) {
134+ done . fail ( "Get event by id error: " + JSON . stringify ( err ) ) ;
135+ } else {
136+ expect ( response ) . not . toBeNull ( ) ;
137+ expect ( response . event . id ) . toBe ( eventId ) ;
138+ console . info ( "can get event by id" ) ;
139+ done ( ) ;
140+ }
83141 } ) ;
84- waitsFor(function(){
85- return done;
86- },'create pull event', TIMEOUT * 3);
87- runs(function(){
88- expect(result).not.toBeNull();
89- expect(result.token).not.toBeNull();
142+ } ) ;
143+
144+ it ( "can get event's status by id" , function ( done ) {
145+ QB . pushnotifications . events . status ( eventId , function ( err , response ) {
146+ if ( err ) {
147+ done . fail ( "Get event's status by id error: " + JSON . stringify ( err ) ) ;
148+ } else {
149+ expect ( response ) . not . toBeNull ( ) ;
150+ expect ( response . event . id ) . toBe ( eventId ) ;
151+ console . info ( "can get event's status by id" ) ;
152+ done ( ) ;
153+ }
90154 } ) ;
91155 } ) ;
92156
93- it('can get pull events', function(){
94- var done, result;
95- runs(function(){
96- done = false;
97- QB.pushnotifications.events.pullEvents(function(err, res){
98- result = res;
99- done = true;
100- expect(err).toBeNull();
101- });
157+ it ( "can delete event" , function ( done ) {
158+ QB . pushnotifications . events . delete ( eventId , function ( err , response ) {
159+ expect ( response ) . toBeNull ( ) ;
160+ console . info ( "can delete event" ) ;
161+ done ( ) ;
102162 } ) ;
103- waitsFor(function(){
104- return done;
105- },'get pull events', TIMEOUT * 3);
106- runs(function(){
107- expect(result).not.toBeNull();
108- expect(result.length).not.toBeNull();
163+ } ) ;
164+
165+ afterAll ( function ( done ) {
166+ QB . pushnotifications . subscriptions . list ( function ( err , result ) {
167+ if ( err ) {
168+ done . fail ( "List a subscription error: " + JSON . stringify ( err ) ) ;
169+ } else {
170+ var subscriptionId = result [ 0 ] . subscription . id ;
171+ QB . pushnotifications . subscriptions . delete ( subscriptionId , function ( err , res ) {
172+ if ( err ) {
173+ done . fail ( "Delete subscription error: " + JSON . stringify ( err ) ) ;
174+ } else {
175+ expect ( res ) . not . toBeNull ( ) ;
176+ done ( ) ;
177+ }
178+ } ) ;
179+ }
109180 } ) ;
110181 } ) ;
111- });*/
182+
183+ } ) ;
112184
113185} ) ;
114186
0 commit comments