@@ -37,6 +37,16 @@ const clearSafariWindow = () => {
3737 } ) ;
3838} ;
3939
40+ const mockVapidSupport = ( ) => {
41+ ( globalThis as any ) . PushSubscriptionOptions = {
42+ prototype : { applicationServerKey : undefined } ,
43+ } ;
44+ } ;
45+
46+ const clearVapidSupport = ( ) => {
47+ delete ( globalThis as any ) . PushSubscriptionOptions ;
48+ } ;
49+
4050describe ( "Environment Helper" , ( ) => {
4151 test ( "can get api url " , async ( ) => {
4252 // staging
@@ -78,6 +88,11 @@ describe("useSafariLegacyPush", () => {
7888 beforeEach ( ( ) => {
7989 TestEnvironment . initialize ( ) ;
8090 clearSafariWindow ( ) ;
91+ mockVapidSupport ( ) ;
92+ } ) ;
93+
94+ afterEach ( ( ) => {
95+ clearVapidSupport ( ) ;
8196 } ) ;
8297
8398 test ( "returns false when window.safari is undefined" , ( ) => {
@@ -99,7 +114,7 @@ describe("useSafariLegacyPush", () => {
99114 expect ( useSafariLegacyPush ( ) ) . toBe ( false ) ;
100115 } ) ;
101116
102- test ( 'returns false when legacy permission is "default" (new user)' , ( ) => {
117+ test ( 'returns false when legacy permission is "default" (new user on Safari 16.4+ )' , ( ) => {
103118 mockSafariPushNotification ( "default" , null ) ;
104119 OneSignal . config ! . safariWebId = FAKE_SAFARI_WEB_ID ;
105120 expect ( useSafariLegacyPush ( ) ) . toBe ( false ) ;
@@ -122,12 +137,24 @@ describe("useSafariLegacyPush", () => {
122137 OneSignal . config ! . safariWebId = FAKE_SAFARI_WEB_ID ;
123138 expect ( useSafariLegacyPush ( ) ) . toBe ( true ) ;
124139 } ) ;
140+
141+ test ( "returns true on Safari < 16.4 (no VAPID support) even for new users" , ( ) => {
142+ clearVapidSupport ( ) ;
143+ mockSafariPushNotification ( "default" , null ) ;
144+ OneSignal . config ! . safariWebId = FAKE_SAFARI_WEB_ID ;
145+ expect ( useSafariLegacyPush ( ) ) . toBe ( true ) ;
146+ } ) ;
125147} ) ;
126148
127149describe ( "getSubscriptionType" , ( ) => {
128150 beforeEach ( ( ) => {
129151 TestEnvironment . initialize ( ) ;
130152 clearSafariWindow ( ) ;
153+ mockVapidSupport ( ) ;
154+ } ) ;
155+
156+ afterEach ( ( ) => {
157+ clearVapidSupport ( ) ;
131158 } ) ;
132159
133160 test ( "returns SafariLegacyPush for existing legacy Safari subscribers" , ( ) => {
@@ -147,4 +174,11 @@ describe("getSubscriptionType", () => {
147174 OneSignal . config ! . safariWebId = FAKE_SAFARI_WEB_ID ;
148175 expect ( getSubscriptionType ( ) ) . not . toBe ( SubscriptionType . _SafariLegacyPush ) ;
149176 } ) ;
177+
178+ test ( "returns SafariLegacyPush on Safari < 16.4 (no VAPID support)" , ( ) => {
179+ clearVapidSupport ( ) ;
180+ mockSafariPushNotification ( "default" , null ) ;
181+ OneSignal . config ! . safariWebId = FAKE_SAFARI_WEB_ID ;
182+ expect ( getSubscriptionType ( ) ) . toBe ( SubscriptionType . _SafariLegacyPush ) ;
183+ } ) ;
150184} ) ;
0 commit comments