@@ -37,6 +37,16 @@ async function isAPNSCapableSimulator() {
37
37
}
38
38
39
39
describe ( 'messaging()' , function ( ) {
40
+ before ( async function ( ) {
41
+ // our device registration tests require permissions. Set them up
42
+ await firebase . messaging ( ) . requestPermission ( {
43
+ alert : true ,
44
+ badge : true ,
45
+ sound : true ,
46
+ provisional : true ,
47
+ } ) ;
48
+ } ) ;
49
+
40
50
describe ( 'firebase v8 compatibility' , function ( ) {
41
51
describe ( 'namespace' , function ( ) {
42
52
it ( 'accessible from firebase.app()' , function ( ) {
@@ -98,8 +108,6 @@ describe('messaging()', function () {
98
108
if ( device . getPlatform ( ) === 'ios' ) {
99
109
await firebase . messaging ( ) . unregisterDeviceForRemoteMessages ( ) ;
100
110
should . equal ( firebase . messaging ( ) . isDeviceRegisteredForRemoteMessages , false ) ;
101
- // did this happen in logs?
102
- // 2024-02-02 18:35:26.277 Df testing[26266:18d3f] (Detox) 10.20.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
103
111
tryToRegister = await isAPNSCapableSimulator ( ) ;
104
112
if ( tryToRegister ) {
105
113
await firebase . messaging ( ) . registerDeviceForRemoteMessages ( ) ;
@@ -112,27 +120,21 @@ describe('messaging()', function () {
112
120
} ) ;
113
121
114
122
describe ( 'hasPermission' , function ( ) {
115
- it ( 'returns true android (default)' , async function ( ) {
116
- if ( device . getPlatform ( ) === 'android' ) {
117
- should . equal ( await firebase . messaging ( ) . hasPermission ( ) , true ) ;
118
- } else {
119
- this . skip ( ) ;
120
- }
121
- } ) ;
122
-
123
- it ( 'returns -1 on ios (default)' , async function ( ) {
124
- if ( device . getPlatform ( ) === 'ios' ) {
125
- should . equal ( await firebase . messaging ( ) . hasPermission ( ) , - 1 ) ;
126
- }
123
+ // we request permission in a before block, so both should be truthy
124
+ it ( 'returns truthy' , async function ( ) {
125
+ should . equal ( ! ! ( await firebase . messaging ( ) . hasPermission ( ) ) , true ) ;
127
126
} ) ;
128
127
} ) ;
129
128
130
129
describe ( 'requestPermission' , function ( ) {
131
- it ( 'resolves 1 on android' , async function ( ) {
130
+ // we request permission in a before block
131
+ it ( 'resolves correctly for default request' , async function ( ) {
132
132
if ( device . getPlatform ( ) === 'android' ) {
133
- should . equal ( await firebase . messaging ( ) . requestPermission ( ) , 1 ) ;
133
+ // our default resolve on android is "authorized"
134
+ should . equal ( await firebase . messaging ( ) . requestPermission ( { provisional : true } ) , 1 ) ;
134
135
} else {
135
- this . skip ( ) ;
136
+ // our default request on iOS results in "provisional"
137
+ should . equal ( await firebase . messaging ( ) . requestPermission ( { provisional : true } ) , 2 ) ;
136
138
}
137
139
} ) ;
138
140
} ) ;
@@ -585,30 +587,22 @@ describe('messaging()', function () {
585
587
} ) ;
586
588
587
589
describe ( 'hasPermission' , function ( ) {
588
- it ( 'returns true android (default)' , async function ( ) {
590
+ it ( 'returns true' , async function ( ) {
591
+ // our before block requests permission, so both should be truthy
589
592
const { getMessaging, hasPermission } = messagingModular ;
590
- if ( device . getPlatform ( ) === 'android' ) {
591
- should . equal ( await hasPermission ( getMessaging ( ) ) , true ) ;
592
- } else {
593
- this . skip ( ) ;
594
- }
595
- } ) ;
596
-
597
- it ( 'returns -1 on ios (default)' , async function ( ) {
598
- const { getMessaging, hasPermission } = messagingModular ;
599
- if ( device . getPlatform ( ) === 'ios' ) {
600
- should . equal ( await hasPermission ( getMessaging ( ) ) , - 1 ) ;
601
- }
593
+ should . equal ( ! ! ( await hasPermission ( getMessaging ( ) ) ) , true ) ;
602
594
} ) ;
603
595
} ) ;
604
596
605
597
describe ( 'requestPermission' , function ( ) {
606
- it ( 'resolves 1 on android ' , async function ( ) {
598
+ it ( 'resolves correctly for default request ' , async function ( ) {
607
599
const { getMessaging, requestPermission } = messagingModular ;
600
+ // our before block requests, android will always be 1
608
601
if ( device . getPlatform ( ) === 'android' ) {
609
602
should . equal ( await requestPermission ( getMessaging ( ) ) , 1 ) ;
610
603
} else {
611
- this . skip ( ) ;
604
+ // ... and iOS should always be 2 (provisional)
605
+ should . equal ( await requestPermission ( getMessaging ( ) , { provisional : true } ) , 2 ) ;
612
606
}
613
607
} ) ;
614
608
} ) ;
0 commit comments