@@ -119,4 +119,79 @@ describe("AptabaseClient", () => {
119119 expect ( sessionId3 ) . toBeDefined ( ) ;
120120 expect ( sessionId3 ) . not . toBe ( sessionId1 ) ;
121121 } ) ;
122+
123+ describe ( "Web tracking" , ( ) => {
124+ const webEnv : EnvironmentInfo = {
125+ ...env ,
126+ osName : "web" ,
127+ osVersion : "web" ,
128+ } ;
129+
130+ it ( "should not track events when web tracking is disabled" , async ( ) => {
131+ const client = new AptabaseClient ( "A-DEV-000" , webEnv ) ;
132+ client . trackEvent ( "test_event" ) ;
133+ await client . flush ( ) ;
134+ expect ( fetchMock . requests ( ) . length ) . toEqual ( 0 ) ;
135+ } ) ;
136+
137+ it ( "should track events when web tracking is enabled" , async ( ) => {
138+ const client = new AptabaseClient ( "A-DEV-000" , webEnv , {
139+ enableWeb : true ,
140+ } ) ;
141+ client . trackEvent ( "test_event" ) ;
142+ await client . flush ( ) ;
143+ expect ( fetchMock . requests ( ) . length ) . toEqual ( 1 ) ;
144+ const body = await fetchMock . requests ( ) . at ( 0 ) ?. json ( ) ;
145+ expect ( body . eventName ) . toEqual ( "test_event" ) ;
146+ expect ( body . systemProps . osName ) . toBeUndefined ( ) ;
147+ expect ( body . systemProps . osVersion ) . toBeUndefined ( ) ;
148+ } ) ;
149+
150+ it ( "should use correct endpoint for web events" , async ( ) => {
151+ const client = new AptabaseClient ( "A-DEV-000" , webEnv , {
152+ enableWeb : true ,
153+ } ) ;
154+ client . trackEvent ( "test_event" ) ;
155+ await client . flush ( ) ;
156+ const request = fetchMock . requests ( ) . at ( 0 ) ;
157+ expect ( request ?. url ) . toContain ( "/api/v0/event" ) ;
158+ } ) ;
159+
160+ it ( "should use correct endpoint for native events" , async ( ) => {
161+ const client = new AptabaseClient ( "A-DEV-000" , env ) ;
162+ client . trackEvent ( "test_event" ) ;
163+ await client . flush ( ) ;
164+ const request = fetchMock . requests ( ) . at ( 0 ) ;
165+ expect ( request ?. url ) . toContain ( "/api/v0/events" ) ;
166+ } ) ;
167+ } ) ;
168+
169+ describe ( "Native tracking" , ( ) => {
170+ it ( "should track events on iOS" , async ( ) => {
171+ const client = new AptabaseClient ( "A-DEV-000" , env ) ;
172+ client . trackEvent ( "test_event" ) ;
173+ await client . flush ( ) ;
174+ expect ( fetchMock . requests ( ) . length ) . toEqual ( 1 ) ;
175+ const body = await fetchMock . requests ( ) . at ( 0 ) ?. json ( ) ;
176+ expect ( body [ 0 ] . eventName ) . toEqual ( "test_event" ) ;
177+ expect ( body [ 0 ] . systemProps . osName ) . toEqual ( "iOS" ) ;
178+ expect ( body [ 0 ] . systemProps . osVersion ) . toEqual ( "14.3" ) ;
179+ } ) ;
180+
181+ it ( "should track events on Android" , async ( ) => {
182+ const androidEnv : EnvironmentInfo = {
183+ ...env ,
184+ osName : "Android" ,
185+ osVersion : "13" ,
186+ } ;
187+ const client = new AptabaseClient ( "A-DEV-000" , androidEnv ) ;
188+ client . trackEvent ( "test_event" ) ;
189+ await client . flush ( ) ;
190+ expect ( fetchMock . requests ( ) . length ) . toEqual ( 1 ) ;
191+ const body = await fetchMock . requests ( ) . at ( 0 ) ?. json ( ) ;
192+ expect ( body [ 0 ] . eventName ) . toEqual ( "test_event" ) ;
193+ expect ( body [ 0 ] . systemProps . osName ) . toEqual ( "Android" ) ;
194+ expect ( body [ 0 ] . systemProps . osVersion ) . toEqual ( "13" ) ;
195+ } ) ;
196+ } ) ;
122197} ) ;
0 commit comments