Skip to content

Commit

Permalink
refactor(formatting): include jest and plugin folder in prettier scope
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr authored and mikehardy committed May 13, 2022
1 parent de3d0ae commit 847feea
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 147 deletions.
1 change: 0 additions & 1 deletion jest/mocks/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env jest */
const LoginButton = require('../../lib/commonjs/FBLoginButton').default;


export const mockAppEvents = {
AchievedLevel: 'fb_mobile_level_achieved',
AdClick: 'AdClick',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"lint": "eslint ./src",
"test": "yarn validate:prettier && yarn validate:eslint && yarn jest",
"validate:eslint": "eslint \"src/**/*\"",
"validate:prettier": "prettier \"src/**/*.{ts,tsx}\" --check",
"validate:prettier": "prettier \"{src,jest,plugin/src}/**/*.{js,ts,tsx}\" --check",
"validate:ts": "tsc --noEmit",
"example:start": "cd ./RNFBSDKExample && yarn start",
"example:ios": "cd ./RNFBSDKExample/ios && rm -f Podfile.lock && pod install && yarn ios",
Expand Down
79 changes: 37 additions & 42 deletions plugin/src/__tests__/withFacebookAndroid-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { AndroidConfig } from '@expo/config-plugins';
import { resolve } from 'path';
import { Parser } from 'xml2js';

import {
getFacebookAdvertiserIDCollection,
getFacebookAppId,
Expand All @@ -10,14 +6,17 @@ import {
getFacebookDisplayName,
getFacebookScheme,
} from '../config';
import { setFacebookConfig } from '../withFacebookAndroid';
import {setFacebookConfig} from '../withFacebookAndroid';
import {AndroidConfig} from '@expo/config-plugins';
import {resolve} from 'path';
import {Parser} from 'xml2js';

const { getMainApplication, readAndroidManifestAsync } = AndroidConfig.Manifest;
const {getMainApplication, readAndroidManifestAsync} = AndroidConfig.Manifest;

const fixturesPath = resolve(__dirname, 'fixtures');
const sampleManifestPath = resolve(
fixturesPath,
'react-native-AndroidManifest.xml'
'react-native-AndroidManifest.xml',
);

const filledManifest = `<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.expo.mycoolapp">
Expand Down Expand Up @@ -75,31 +74,25 @@ describe('Android facebook config', () => {
});

it(`returns correct value from all getters if value provided`, () => {
expect(getFacebookScheme({ scheme: 'fbmyscheme' })).toMatch(
'fbmyscheme'
);
expect(getFacebookAppId({ appID: 'my-app-id' })).toMatch(
'my-app-id'
expect(getFacebookScheme({scheme: 'fbmyscheme'})).toMatch('fbmyscheme');
expect(getFacebookAppId({appID: 'my-app-id'})).toMatch('my-app-id');
expect(getFacebookDisplayName({displayName: 'my-display-name'})).toMatch(
'my-display-name',
);
expect(
getFacebookDisplayName({ displayName: 'my-display-name' })
).toMatch('my-display-name');
expect(
getFacebookAutoLogAppEvents({ autoLogAppEventsEnabled: false })
).toBe(false);
expect(getFacebookAutoInitEnabled({ isAutoInitEnabled: true })).toBe(
true
expect(getFacebookAutoLogAppEvents({autoLogAppEventsEnabled: false})).toBe(
false,
);
expect(getFacebookAutoInitEnabled({isAutoInitEnabled: true})).toBe(true);
expect(
getFacebookAdvertiserIDCollection({
advertiserIDCollectionEnabled: false,
})
}),
).toBe(false);
});

it('adds scheme, appid, display name, autolog events, auto init, advertiser id collection to androidmanifest.xml', async () => {
let androidManifestJson = await readAndroidManifestAsync(
sampleManifestPath
sampleManifestPath,
);
const facebookConfig = {
appID: 'my-app-id',
Expand All @@ -111,12 +104,12 @@ describe('Android facebook config', () => {
};
androidManifestJson = setFacebookConfig(
facebookConfig,
androidManifestJson
androidManifestJson,
);
// Run this twice to ensure copies don't get added.
androidManifestJson = setFacebookConfig(
facebookConfig,
androidManifestJson
androidManifestJson,
);

const mainApplication = getMainApplication(androidManifestJson);
Expand All @@ -125,49 +118,50 @@ describe('Android facebook config', () => {
}

const facebookActivity = mainApplication.activity?.filter(
(e) => e.$['android:name'] === 'com.facebook.CustomTabActivity'
(e) => e.$['android:name'] === 'com.facebook.CustomTabActivity',
);
expect(facebookActivity).toHaveLength(1);

const applicationId = mainApplication['meta-data']?.filter(
(e) => e.$['android:name'] === 'com.facebook.sdk.ApplicationId'
(e) => e.$['android:name'] === 'com.facebook.sdk.ApplicationId',
);
expect(applicationId).toHaveLength(1);
expect(applicationId?.[0].$['android:value']).toMatch(
'@string/facebook_app_id'
'@string/facebook_app_id',
);

const displayName = mainApplication['meta-data']?.filter(
(e) => e.$['android:name'] === 'com.facebook.sdk.ApplicationName'
(e) => e.$['android:name'] === 'com.facebook.sdk.ApplicationName',
);
expect(displayName).toHaveLength(1);
expect(displayName?.[0].$['android:value']).toMatch(
facebookConfig.displayName
facebookConfig.displayName,
);

const autoLogAppEventsEnabled = mainApplication['meta-data']?.filter(
(e) => e.$['android:name'] === 'com.facebook.sdk.AutoLogAppEventsEnabled'
(e) => e.$['android:name'] === 'com.facebook.sdk.AutoLogAppEventsEnabled',
);
expect(autoLogAppEventsEnabled).toHaveLength(1);
expect(autoLogAppEventsEnabled?.[0].$['android:value']).toMatch(
facebookConfig.autoLogAppEventsEnabled.toString()
facebookConfig.autoLogAppEventsEnabled.toString(),
);

const advertiserIDCollectionEnabled = mainApplication['meta-data']?.filter(
(e) =>
e.$['android:name'] === 'com.facebook.sdk.AdvertiserIDCollectionEnabled'
e.$['android:name'] ===
'com.facebook.sdk.AdvertiserIDCollectionEnabled',
);
expect(advertiserIDCollectionEnabled).toHaveLength(1);
expect(advertiserIDCollectionEnabled?.[0].$['android:value']).toMatch(
facebookConfig.advertiserIDCollectionEnabled.toString()
facebookConfig.advertiserIDCollectionEnabled.toString(),
);

const autoInitEnabled = mainApplication['meta-data']?.filter(
(e) => e.$['android:name'] === 'com.facebook.sdk.AutoInitEnabled'
(e) => e.$['android:name'] === 'com.facebook.sdk.AutoInitEnabled',
);
expect(autoInitEnabled).toHaveLength(1);
expect(autoInitEnabled?.[0].$['android:value']).toMatch(
facebookConfig.isAutoInitEnabled.toString()
facebookConfig.isAutoInitEnabled.toString(),
);
});

Expand All @@ -178,7 +172,7 @@ describe('Android facebook config', () => {
const facebookConfig = {};
androidManifestJson = setFacebookConfig(
facebookConfig,
androidManifestJson
androidManifestJson,
);

const mainApplication = getMainApplication(androidManifestJson);
Expand All @@ -187,32 +181,33 @@ describe('Android facebook config', () => {
}

const facebookActivity = mainApplication.activity?.filter(
(e) => e.$['android:name'] === 'com.facebook.CustomTabActivity'
(e) => e.$['android:name'] === 'com.facebook.CustomTabActivity',
);
expect(facebookActivity).toHaveLength(0);
const applicationId = mainApplication['meta-data']?.filter(
(e) => e.$['android:name'] === 'com.facebook.sdk.ApplicationId'
(e) => e.$['android:name'] === 'com.facebook.sdk.ApplicationId',
);
expect(applicationId).toHaveLength(0);

const displayName = mainApplication['meta-data']?.filter(
(e) => e.$['android:name'] === 'com.facebook.sdk.ApplicationName'
(e) => e.$['android:name'] === 'com.facebook.sdk.ApplicationName',
);
expect(displayName).toHaveLength(0);

const autoLogAppEventsEnabled = mainApplication['meta-data']?.filter(
(e) => e.$['android:name'] === 'com.facebook.sdk.AutoLogAppEventsEnabled'
(e) => e.$['android:name'] === 'com.facebook.sdk.AutoLogAppEventsEnabled',
);
expect(autoLogAppEventsEnabled).toHaveLength(0);

const advertiserIDCollectionEnabled = mainApplication['meta-data']?.filter(
(e) =>
e.$['android:name'] === 'com.facebook.sdk.AdvertiserIDCollectionEnabled'
e.$['android:name'] ===
'com.facebook.sdk.AdvertiserIDCollectionEnabled',
);
expect(advertiserIDCollectionEnabled).toHaveLength(0);

const autoInitEnabled = mainApplication['meta-data']?.filter(
(e) => e.$['android:name'] === 'com.facebook.sdk.AutoInitEnabled'
(e) => e.$['android:name'] === 'com.facebook.sdk.AutoInitEnabled',
);
expect(autoInitEnabled).toHaveLength(0);
});
Expand Down
41 changes: 18 additions & 23 deletions plugin/src/__tests__/withFacebookIOS-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
setFacebookAutoInitEnabled,
setFacebookConfig,
} from '../withFacebookIOS';

describe('ios facebook config', () => {
it(`returns null from all getters if no value provided`, () => {
expect(getFacebookScheme({})).toBe(null);
Expand All @@ -24,43 +25,37 @@ describe('ios facebook config', () => {
});

it(`returns correct value from all getters if value provided`, () => {
expect(getFacebookScheme({ scheme: 'fbscheme' })).toMatch(
'fbscheme'
);
expect(getFacebookAppId({ appID: 'my-app-id' })).toMatch(
'my-app-id'
expect(getFacebookScheme({scheme: 'fbscheme'})).toMatch('fbscheme');
expect(getFacebookAppId({appID: 'my-app-id'})).toMatch('my-app-id');
expect(getFacebookDisplayName({displayName: 'my-display-name'})).toMatch(
'my-display-name',
);
expect(
getFacebookDisplayName({ displayName: 'my-display-name' })
).toMatch('my-display-name');
expect(
getFacebookAutoLogAppEvents({ autoLogAppEventsEnabled: false })
).toBe(false);
expect(getFacebookAutoInitEnabled({ isAutoInitEnabled: true })).toBe(
true
expect(getFacebookAutoLogAppEvents({autoLogAppEventsEnabled: false})).toBe(
false,
);
expect(getFacebookAutoInitEnabled({isAutoInitEnabled: true})).toBe(true);
expect(
getFacebookAdvertiserIDCollection({
advertiserIDCollectionEnabled: false,
})
}),
).toBe(false);
});

it('sets the facebook app id config', () => {
expect(setFacebookAppId({ appID: 'abc' }, {})).toStrictEqual({
expect(setFacebookAppId({appID: 'abc'}, {})).toStrictEqual({
FacebookAppID: 'abc',
});
});

it('sets the facebook client token config', () => {
expect(setFacebookClientToken({ clientToken: 'abc' }, {})).toStrictEqual({
expect(setFacebookClientToken({clientToken: 'abc'}, {})).toStrictEqual({
FacebookClientToken: 'abc',
});
});

it('sets the facebook auto init config', () => {
expect(
setFacebookAutoInitEnabled({ isAutoInitEnabled: true }, {})
setFacebookAutoInitEnabled({isAutoInitEnabled: true}, {}),
).toStrictEqual({
FacebookAutoInitEnabled: true,
});
Expand All @@ -69,9 +64,9 @@ describe('ios facebook config', () => {
it('sets the facebook advertising id enabled config', () => {
expect(
setFacebookAdvertiserIDCollectionEnabled(
{ advertiserIDCollectionEnabled: true },
{}
)
{advertiserIDCollectionEnabled: true},
{},
),
).toStrictEqual({
FacebookAdvertiserIDCollectionEnabled: true,
});
Expand All @@ -94,8 +89,8 @@ describe('ios facebook config', () => {
'fbauth2',
'fbshareextension',
],
}
)
},
),
).toStrictEqual({});
});
it('preserves the existing LSApplicationQueriesSchemes after removing the facebook schemes', () => {
Expand All @@ -109,7 +104,7 @@ describe('ios facebook config', () => {
'fbauth2',
'fbshareextension',
],
}
},
);
// Test that running the command twice doesn't cause duplicates
expect(setFacebookConfig({}, plist)).toStrictEqual({
Expand Down
19 changes: 12 additions & 7 deletions plugin/src/__tests__/withSKAdNetworkIdentifiers-test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { withSKAdNetworkIdentifiers } from '../withSKAdNetworkIdentifiers';
import {withSKAdNetworkIdentifiers} from '../withSKAdNetworkIdentifiers';

describe(withSKAdNetworkIdentifiers, () => {
it(`adds ids to the Info.plist`, () => {
expect(withSKAdNetworkIdentifiers({
name: 'foo',
slug: 'bar',
}, ['FOOBAR', 'other'])).toStrictEqual({
expect(
withSKAdNetworkIdentifiers(
{
name: 'foo',
slug: 'bar',
},
['FOOBAR', 'other'],
),
).toStrictEqual({
name: 'foo',
slug: 'bar',
ios: {
Expand Down Expand Up @@ -38,8 +43,8 @@ describe(withSKAdNetworkIdentifiers, () => {
},
},
},
['foobar', 'other']
)
['foobar', 'other'],
),
).toStrictEqual({
name: 'foo',
slug: 'bar',
Expand Down
7 changes: 4 additions & 3 deletions plugin/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExpoConfig } from '@expo/config-types';
import {ExpoConfig} from '@expo/config-types';

export type ExpoConfigFacebook = Pick<
ExpoConfig,
Expand Down Expand Up @@ -48,7 +48,7 @@ export type ConfigProps = {

export function getMergePropsWithConfig(
config: ExpoConfigFacebook,
props: ConfigProps | void
props: ConfigProps | void,
): ConfigProps {
const {
facebookAppId,
Expand All @@ -65,7 +65,8 @@ export function getMergePropsWithConfig(
scheme = facebookScheme ?? (appID ? `fb${appID}` : undefined),
isAutoInitEnabled = facebookAutoInitEnabled ?? false,
autoLogAppEventsEnabled = facebookAutoLogAppEventsEnabled ?? false,
advertiserIDCollectionEnabled = facebookAdvertiserIDCollectionEnabled ?? false,
advertiserIDCollectionEnabled = facebookAdvertiserIDCollectionEnabled ??
false,
iosUserTrackingPermission,
} = (props ?? {}) as ConfigProps;

Expand Down
9 changes: 4 additions & 5 deletions plugin/src/withFacebook.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';
import { ConfigProps, getMergePropsWithConfig } from './config';

import {ConfigProps, getMergePropsWithConfig} from './config';
import {
withAndroidPermissions,
withFacebookAppIdString,
withFacebookManifest,
} from './withFacebookAndroid';
import { withFacebookIOS, withUserTrackingPermission } from './withFacebookIOS';
import { withSKAdNetworkIdentifiers } from './withSKAdNetworkIdentifiers';
import {withFacebookIOS, withUserTrackingPermission} from './withFacebookIOS';
import {withSKAdNetworkIdentifiers} from './withSKAdNetworkIdentifiers';
import {ConfigPlugin, createRunOncePlugin} from '@expo/config-plugins';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('react-native-fbsdk-next/package.json');
Expand Down
Loading

0 comments on commit 847feea

Please sign in to comment.