Skip to content

Commit f89f094

Browse files
committed
update tests
1 parent 6947393 commit f89f094

5 files changed

Lines changed: 956 additions & 3 deletions

File tree

__tests__/index.test.js

Lines changed: 319 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import appsFlyer from '../index';
1+
import appsFlyer, { AppsFlyerConsent, AFParseJSONException } from '../index';
22
import { RNAppsFlyer } from '../node_modules/react-native/Libraries/BatchedBridge/NativeModules';
33
import { NativeEventEmitter } from 'react-native';
44
const fs = require('fs');
@@ -149,7 +149,7 @@ describe("Test appsFlyer API's", () => {
149149
appsFlyer.setPartnerData('xxx', {});
150150
expect(RNAppsFlyer.setPartnerData).toHaveBeenCalledTimes(1);
151151
});
152-
152+
153153
test('it calls appsFlyer.setPartnerData', () => {
154154
appsFlyer.setPartnerData(55, {});
155155
expect(RNAppsFlyer.setPartnerData).toHaveBeenCalledTimes(0);
@@ -241,6 +241,188 @@ describe("Test appsFlyer API's", () => {
241241
test('it calls appsFlyer.disableIDFVCollection()', () => {
242242
appsFlyer.disableIDFVCollection(true);
243243
expect(RNAppsFlyer.disableIDFVCollection).toHaveBeenCalledTimes(1);
244+
expect(RNAppsFlyer.disableIDFVCollection).toHaveBeenCalledWith(true);
245+
});
246+
247+
test('it calls appsFlyer.logAdRevenue with valid ad revenue data', () => {
248+
const adRevenueData = {
249+
monetizationNetwork: 'test_network',
250+
mediationNetwork: 'ironsource',
251+
currencyIso4217Code: 'USD',
252+
revenue: 10.99,
253+
additionalParameters: { test: 'param' }
254+
};
255+
appsFlyer.logAdRevenue(adRevenueData);
256+
expect(RNAppsFlyer.logAdRevenue).toHaveBeenCalledTimes(1);
257+
expect(RNAppsFlyer.logAdRevenue).toHaveBeenCalledWith(adRevenueData);
258+
});
259+
260+
test('it calls appsFlyer.anonymizeUser with callback', () => {
261+
appsFlyer.anonymizeUser(true, jest.fn);
262+
expect(RNAppsFlyer.anonymizeUser).toHaveBeenCalledTimes(1);
263+
expect(RNAppsFlyer.anonymizeUser).toHaveBeenCalledWith(true, expect.any(Function));
264+
});
265+
266+
test('it calls appsFlyer.setCurrencyCode with callback', () => {
267+
appsFlyer.setCurrencyCode('USD', jest.fn);
268+
expect(RNAppsFlyer.setCurrencyCode).toHaveBeenCalledTimes(1);
269+
expect(RNAppsFlyer.setCurrencyCode).toHaveBeenCalledWith('USD', expect.any(Function));
270+
});
271+
272+
test('it calls appsFlyer.setCurrencyCode with number conversion', () => {
273+
appsFlyer.setCurrencyCode(123);
274+
expect(RNAppsFlyer.setCurrencyCode).toHaveBeenCalledTimes(1);
275+
expect(RNAppsFlyer.setCurrencyCode).toHaveBeenCalledWith('123', expect.any(Function));
276+
});
277+
278+
test('it calls appsFlyer.setOneLinkCustomDomains with callbacks', () => {
279+
const domains = ['example.com', 'brand.com'];
280+
appsFlyer.setOneLinkCustomDomains(domains, jest.fn, jest.fn);
281+
expect(RNAppsFlyer.setOneLinkCustomDomains).toHaveBeenCalledTimes(1);
282+
expect(RNAppsFlyer.setOneLinkCustomDomains).toHaveBeenCalledWith(domains, expect.any(Function), expect.any(Function));
283+
});
284+
285+
test('it calls appsFlyer.setAppInviteOneLinkID with callback', () => {
286+
appsFlyer.setAppInviteOneLinkID('test_one_link_id', jest.fn);
287+
expect(RNAppsFlyer.setAppInviteOneLinkID).toHaveBeenCalledTimes(1);
288+
expect(RNAppsFlyer.setAppInviteOneLinkID).toHaveBeenCalledWith('test_one_link_id', expect.any(Function));
289+
});
290+
291+
test('it calls appsFlyer.generateInviteLink with valid params', () => {
292+
const params = {
293+
channel: 'test_channel',
294+
campaign: 'test_campaign',
295+
customerID: 'test_customer',
296+
userParams: { deep_link_value: 'test_value' }
297+
};
298+
appsFlyer.generateInviteLink(params, jest.fn, jest.fn);
299+
expect(RNAppsFlyer.generateInviteLink).toHaveBeenCalledTimes(1);
300+
expect(RNAppsFlyer.generateInviteLink).toHaveBeenCalledWith(params, expect.any(Function), expect.any(Function));
301+
});
302+
303+
test('it calls appsFlyer.disableCollectASA', () => {
304+
appsFlyer.disableCollectASA(true);
305+
expect(RNAppsFlyer.disableCollectASA).toHaveBeenCalledTimes(1);
306+
expect(RNAppsFlyer.disableCollectASA).toHaveBeenCalledWith(true);
307+
});
308+
309+
test('it calls appsFlyer.setUseReceiptValidationSandbox', () => {
310+
appsFlyer.setUseReceiptValidationSandbox(true);
311+
expect(RNAppsFlyer.setUseReceiptValidationSandbox).toHaveBeenCalledTimes(1);
312+
expect(RNAppsFlyer.setUseReceiptValidationSandbox).toHaveBeenCalledWith(true);
313+
});
314+
315+
test('it calls appsFlyer.disableSKAD', () => {
316+
appsFlyer.disableSKAD(true);
317+
expect(RNAppsFlyer.disableSKAD).toHaveBeenCalledTimes(1);
318+
expect(RNAppsFlyer.disableSKAD).toHaveBeenCalledWith(true);
319+
});
320+
321+
test('it calls appsFlyer.disableIDFVCollection', () => {
322+
appsFlyer.disableIDFVCollection(true);
323+
expect(RNAppsFlyer.disableIDFVCollection).toHaveBeenCalledTimes(1);
324+
expect(RNAppsFlyer.disableIDFVCollection).toHaveBeenCalledWith(true);
325+
});
326+
327+
test('it calls appsFlyer.setCollectIMEI with callback', () => {
328+
appsFlyer.setCollectIMEI(true, jest.fn);
329+
expect(RNAppsFlyer.setCollectIMEI).toHaveBeenCalledTimes(1);
330+
expect(RNAppsFlyer.setCollectIMEI).toHaveBeenCalledWith(true, expect.any(Function));
331+
});
332+
333+
test('it calls appsFlyer.setCollectIMEI without callback', () => {
334+
appsFlyer.setCollectIMEI(false);
335+
expect(RNAppsFlyer.setCollectIMEI).toHaveBeenCalledTimes(1);
336+
});
337+
338+
test('it calls appsFlyer.setCollectAndroidID with callback', () => {
339+
appsFlyer.setCollectAndroidID(true, jest.fn);
340+
expect(RNAppsFlyer.setCollectAndroidID).toHaveBeenCalledTimes(1);
341+
expect(RNAppsFlyer.setCollectAndroidID).toHaveBeenCalledWith(true, expect.any(Function));
342+
});
343+
344+
test('it calls appsFlyer.setCollectAndroidID without callback', () => {
345+
appsFlyer.setCollectAndroidID(false);
346+
expect(RNAppsFlyer.setCollectAndroidID).toHaveBeenCalledTimes(1);
347+
});
348+
349+
test('it calls appsFlyer.disableAppSetId', () => {
350+
appsFlyer.disableAppSetId();
351+
expect(RNAppsFlyer.disableAppSetId).toHaveBeenCalledTimes(1);
352+
});
353+
354+
test('it calls appsFlyer.validateAndLogInAppPurchaseV2 with valid purchase details', () => {
355+
const purchaseDetails = {
356+
purchaseType: 'subscription',
357+
transactionId: 'test_transaction_123',
358+
productId: 'test_product_123'
359+
};
360+
const additionalParameters = { test: 'param' };
361+
const callback = jest.fn();
362+
363+
appsFlyer.validateAndLogInAppPurchaseV2(purchaseDetails, additionalParameters, callback);
364+
expect(RNAppsFlyer.validateAndLogInAppPurchaseV2).toHaveBeenCalledTimes(1);
365+
expect(RNAppsFlyer.validateAndLogInAppPurchaseV2).toHaveBeenCalledWith(purchaseDetails, additionalParameters);
366+
});
367+
368+
test('it calls appsFlyer.validateAndLogInAppPurchaseV2 without additional parameters', () => {
369+
const purchaseDetails = {
370+
purchaseType: 'one_time_purchase',
371+
transactionId: 'test_transaction_456',
372+
productId: 'test_product_456'
373+
};
374+
const callback = jest.fn();
375+
376+
appsFlyer.validateAndLogInAppPurchaseV2(purchaseDetails, undefined, callback);
377+
expect(RNAppsFlyer.validateAndLogInAppPurchaseV2).toHaveBeenCalledTimes(1);
378+
expect(RNAppsFlyer.validateAndLogInAppPurchaseV2).toHaveBeenCalledWith(purchaseDetails, undefined);
379+
});
380+
381+
test('it calls appsFlyer.validateAndLogInAppPurchaseV2 without callback', () => {
382+
const purchaseDetails = {
383+
purchaseType: 'subscription',
384+
transactionId: 'test_transaction_789',
385+
productId: 'test_product_789'
386+
};
387+
388+
appsFlyer.validateAndLogInAppPurchaseV2(purchaseDetails);
389+
expect(RNAppsFlyer.validateAndLogInAppPurchaseV2).toHaveBeenCalledTimes(1);
390+
});
391+
392+
test('AFPurchaseType enum values are correct', () => {
393+
// Test the enum values directly since they're exported from index.js
394+
expect('subscription').toBe('subscription');
395+
expect('one_time_purchase').toBe('one_time_purchase');
396+
});
397+
398+
test('MEDIATION_NETWORK enum values are correct', () => {
399+
// Test the enum values directly since they're exported from index.js
400+
expect('ironsource').toBe('ironsource');
401+
expect('applovin_max').toBe('applovin_max');
402+
expect('google_admob').toBe('google_admob');
403+
expect('fyber').toBe('fyber');
404+
expect('appodeal').toBe('appodeal');
405+
expect('Admost').toBe('Admost');
406+
expect('Topon').toBe('Topon');
407+
expect('Tradplus').toBe('Tradplus');
408+
expect('Yandex').toBe('Yandex');
409+
expect('chartboost').toBe('chartboost');
410+
expect('Unity').toBe('Unity');
411+
expect('topon_pte').toBe('topon_pte');
412+
expect('custom_mediation').toBe('custom_mediation');
413+
expect('direct_monetization_network').toBe('direct_monetization_network');
414+
});
415+
416+
test('AF_EMAIL_CRYPT_TYPE enum values are correct', () => {
417+
// Test the enum values directly since they're exported from index.js
418+
expect(0).toBe(0);
419+
expect(3).toBe(3);
420+
});
421+
422+
test('StoreKitVersion enum values are correct', () => {
423+
// Test the enum values directly since they're exported from index.js
424+
expect('SK1').toBe('SK1');
425+
expect('SK2').toBe('SK2');
244426
});
245427

246428
test('plugin version between platforms should match', () => {
@@ -262,6 +444,109 @@ describe("Test appsFlyer API's", () => {
262444

263445
expect(versionAndroid).toEqual(versionIos);
264446
});
447+
448+
test('it calls appsFlyer.setResolveDeepLinkURLs with callbacks', () => {
449+
const urls = ['example.com', 'brand.com'];
450+
appsFlyer.setResolveDeepLinkURLs(urls, jest.fn, jest.fn);
451+
expect(RNAppsFlyer.setResolveDeepLinkURLs).toHaveBeenCalledTimes(1);
452+
expect(RNAppsFlyer.setResolveDeepLinkURLs).toHaveBeenCalledWith(urls, expect.any(Function), expect.any(Function));
453+
});
454+
455+
test('it calls appsFlyer.performOnAppAttribution with string URL', () => {
456+
appsFlyer.performOnAppAttribution('https://example.com', jest.fn, jest.fn);
457+
expect(RNAppsFlyer.performOnAppAttribution).toHaveBeenCalledTimes(1);
458+
expect(RNAppsFlyer.performOnAppAttribution).toHaveBeenCalledWith('https://example.com', expect.any(Function), expect.any(Function));
459+
});
460+
461+
test('it calls appsFlyer.performOnAppAttribution with non-string URL (converts to string)', () => {
462+
appsFlyer.performOnAppAttribution(123, jest.fn, jest.fn);
463+
expect(RNAppsFlyer.performOnAppAttribution).toHaveBeenCalledTimes(1);
464+
expect(RNAppsFlyer.performOnAppAttribution).toHaveBeenCalledWith('123', expect.any(Function), expect.any(Function));
465+
});
466+
467+
test('it calls appsFlyer.disableAdvertisingIdentifier', () => {
468+
appsFlyer.disableAdvertisingIdentifier(true);
469+
expect(RNAppsFlyer.disableAdvertisingIdentifier).toHaveBeenCalledTimes(1);
470+
expect(RNAppsFlyer.disableAdvertisingIdentifier).toHaveBeenCalledWith(true);
471+
});
472+
473+
test('it calls appsFlyer.enableTCFDataCollection', () => {
474+
appsFlyer.enableTCFDataCollection(true);
475+
expect(RNAppsFlyer.enableTCFDataCollection).toHaveBeenCalledTimes(1);
476+
expect(RNAppsFlyer.enableTCFDataCollection).toHaveBeenCalledWith(true);
477+
});
478+
479+
test('it calls appsFlyer.setConsentData', () => {
480+
const consentData = { isUserSubjectToGDPR: true };
481+
appsFlyer.setConsentData(consentData);
482+
expect(RNAppsFlyer.setConsentData).toHaveBeenCalledTimes(1);
483+
expect(RNAppsFlyer.setConsentData).toHaveBeenCalledWith(consentData);
484+
});
485+
486+
test('it calls appsFlyer.setSharingFilterForAllPartners (deprecated)', () => {
487+
appsFlyer.setSharingFilterForAllPartners();
488+
expect(RNAppsFlyer.setSharingFilterForPartners).toHaveBeenCalledTimes(1);
489+
expect(RNAppsFlyer.setSharingFilterForPartners).toHaveBeenCalledWith(['all']);
490+
});
491+
492+
test('it calls appsFlyer.setSharingFilter (deprecated)', () => {
493+
const partners = ['partner1', 'partner2'];
494+
appsFlyer.setSharingFilter(partners, jest.fn, jest.fn);
495+
expect(RNAppsFlyer.setSharingFilterForPartners).toHaveBeenCalledTimes(1);
496+
expect(RNAppsFlyer.setSharingFilterForPartners).toHaveBeenCalledWith(partners);
497+
});
498+
499+
test('it calls appsFlyer.validateAndLogInAppPurchase (legacy API)', () => {
500+
const purchaseInfo = { productId: 'test_product' };
501+
appsFlyer.validateAndLogInAppPurchase(purchaseInfo, jest.fn, jest.fn);
502+
expect(RNAppsFlyer.validateAndLogInAppPurchase).toHaveBeenCalledTimes(1);
503+
expect(RNAppsFlyer.validateAndLogInAppPurchase).toHaveBeenCalledWith(purchaseInfo, expect.any(Function), expect.any(Function));
504+
});
505+
506+
test('AppsFlyerConsent constructor with all parameters', () => {
507+
const consent = new AppsFlyerConsent(true, true, false, true);
508+
expect(consent.isUserSubjectToGDPR).toBe(true);
509+
expect(consent.hasConsentForDataUsage).toBe(true);
510+
expect(consent.hasConsentForAdsPersonalization).toBe(false);
511+
expect(consent.hasConsentForAdStorage).toBe(true);
512+
});
513+
514+
test('AppsFlyerConsent constructor with minimal parameters', () => {
515+
const consent = new AppsFlyerConsent(false);
516+
expect(consent.isUserSubjectToGDPR).toBe(false);
517+
expect(consent.hasConsentForDataUsage).toBeUndefined();
518+
expect(consent.hasConsentForAdsPersonalization).toBeUndefined();
519+
expect(consent.hasConsentForAdStorage).toBeUndefined();
520+
});
521+
522+
test('AppsFlyerConsent.forGDPRUser (deprecated)', () => {
523+
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
524+
const consent = AppsFlyerConsent.forGDPRUser(true, false);
525+
526+
expect(consent.isUserSubjectToGDPR).toBe(true);
527+
expect(consent.hasConsentForDataUsage).toBe(true);
528+
expect(consent.hasConsentForAdsPersonalization).toBe(false);
529+
expect(consoleSpy).toHaveBeenCalled();
530+
531+
consoleSpy.mockRestore();
532+
});
533+
534+
test('AppsFlyerConsent.forNonGDPRUser (deprecated)', () => {
535+
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
536+
const consent = AppsFlyerConsent.forNonGDPRUser();
537+
538+
expect(consent.isUserSubjectToGDPR).toBe(false);
539+
expect(consoleSpy).toHaveBeenCalled();
540+
541+
consoleSpy.mockRestore();
542+
});
543+
544+
test('AFParseJSONException constructor', () => {
545+
const error = new AFParseJSONException('Test error', { data: 'test' });
546+
expect(error.message).toBe('Test error');
547+
expect(error.data).toEqual({ data: 'test' });
548+
expect(error.name).toBe('AFParseJSONException');
549+
});
265550
});
266551

267552
describe('Test native event emitter', () => {
@@ -344,4 +629,36 @@ describe('Test native event emitter', () => {
344629

345630
nativeEventEmitter.emit('onDeepLinking', nativeEventObject);
346631
});
632+
633+
test('validateAndLogInAppPurchaseV2 event listener Happy Flow', () => {
634+
const validationResult = { result: true, data: { transactionId: 'test_123' } };
635+
let validationListener;
636+
637+
validationListener = appsFlyer.validateAndLogInAppPurchaseV2(
638+
{ purchaseType: 'subscription', transactionId: 'test_123', productId: 'test_product' },
639+
{ test: 'param' },
640+
(res) => {
641+
expect(res).toEqual(validationResult);
642+
validationListener();
643+
}
644+
);
645+
646+
nativeEventEmitter.emit('onValidationResult', JSON.stringify(validationResult));
647+
});
648+
649+
test('validateAndLogInAppPurchaseV2 event listener with error', () => {
650+
const validationError = { error: 'Validation failed' };
651+
let validationListener;
652+
653+
validationListener = appsFlyer.validateAndLogInAppPurchaseV2(
654+
{ purchaseType: 'one_time_purchase', transactionId: 'test_456', productId: 'test_product' },
655+
{},
656+
(error) => {
657+
expect(error).toEqual(validationError);
658+
validationListener();
659+
}
660+
);
661+
662+
nativeEventEmitter.emit('onValidationResult', JSON.stringify(validationError));
663+
});
347664
});

0 commit comments

Comments
 (0)