diff --git a/src/android/__tests__/config.test.ts b/src/android/__tests__/config.test.ts new file mode 100644 index 0000000..108db51 --- /dev/null +++ b/src/android/__tests__/config.test.ts @@ -0,0 +1,40 @@ +import type { ExpoConfig } from "expo/config"; + +import { withAndroidStringsDependency } from "../strings-dependency"; + +const config = { name: "test", slug: "test" } as ExpoConfig; + +describe("Android config", () => { + it.each([undefined, ""])( + "rejects a missing CodePush server URL", + (CodePushServerURL) => { + expect(() => + withAndroidStringsDependency(config, { + android: { + CodePushDeploymentKey: "android-key", + CodePushServerURL: CodePushServerURL as string, + }, + ios: { + CodePushDeploymentKey: "ios-key", + CodePushServerURL: "https://updates.example.com", + }, + }), + ).toThrow(/App Center is retired/); + }, + ); + + it("rejects a missing deployment key", () => { + expect(() => + withAndroidStringsDependency(config, { + android: { + CodePushDeploymentKey: "", + CodePushServerURL: "https://updates.example.com", + }, + ios: { + CodePushDeploymentKey: "ios-key", + CodePushServerURL: "https://updates.example.com", + }, + }), + ).toThrow(/CodePushDeploymentKey/); + }); +}); diff --git a/src/android/strings-dependency.ts b/src/android/strings-dependency.ts index f9c9b50..43ebd88 100644 --- a/src/android/strings-dependency.ts +++ b/src/android/strings-dependency.ts @@ -26,26 +26,24 @@ export const withAndroidStringsDependency: ConfigPlugin = ( config, props, ) => { - // if (!props?.android?.CodePushServerURL) { - // throw new Error( - // "You need to provide the `CodePushServerURL` Android property for the @config-plugins/react-native-code-push plugin to work." - // ); - // } + if (!props?.android?.CodePushServerURL) { + throw new Error( + "You need to provide the `CodePushServerURL` Android property for react-native-code-push-plugin to work. App Center is retired, so the default server no longer works.", + ); + } if (!props?.android?.CodePushDeploymentKey) { throw new Error( - "You need to provide the `CodePushDeploymentKey` Android property for the @config-plugins/react-native-code-push plugin to work.", + "You need to provide the `CodePushDeploymentKey` Android property for react-native-code-push-plugin to work.", ); } return withStringsXml(config, (xmlProps) => { - if (props?.android?.CodePushServerURL) { - xmlProps.modResults = setStrings( - xmlProps.modResults, - "CodePushServerURL", - props?.android?.CodePushServerURL, - ); - } + xmlProps.modResults = setStrings( + xmlProps.modResults, + "CodePushServerURL", + props.android.CodePushServerURL, + ); xmlProps.modResults = setStrings( xmlProps.modResults, diff --git a/src/ios/__tests__/config.test.ts b/src/ios/__tests__/config.test.ts new file mode 100644 index 0000000..e8fe160 --- /dev/null +++ b/src/ios/__tests__/config.test.ts @@ -0,0 +1,40 @@ +import type { ExpoConfig } from "expo/config"; + +import { withIosInfoPlistDependency } from "../info-plist-dependency"; + +const config = { name: "test", slug: "test" } as ExpoConfig; + +describe("iOS config", () => { + it.each([undefined, ""])( + "rejects a missing CodePush server URL", + (CodePushServerURL) => { + expect(() => + withIosInfoPlistDependency(config, { + android: { + CodePushDeploymentKey: "android-key", + CodePushServerURL: "https://updates.example.com", + }, + ios: { + CodePushDeploymentKey: "ios-key", + CodePushServerURL: CodePushServerURL as string, + }, + }), + ).toThrow(/App Center is retired/); + }, + ); + + it("rejects a missing deployment key", () => { + expect(() => + withIosInfoPlistDependency(config, { + android: { + CodePushDeploymentKey: "android-key", + CodePushServerURL: "https://updates.example.com", + }, + ios: { + CodePushDeploymentKey: "", + CodePushServerURL: "https://updates.example.com", + }, + }), + ).toThrow(/CodePushDeploymentKey/); + }); +}); diff --git a/src/ios/info-plist-dependency.ts b/src/ios/info-plist-dependency.ts index be8357e..eb20681 100644 --- a/src/ios/info-plist-dependency.ts +++ b/src/ios/info-plist-dependency.ts @@ -11,23 +11,20 @@ export const withIosInfoPlistDependency: ConfigPlugin = ( config, props, ) => { - // if (!props?.ios?.CodePushServerURL) { - // throw new Error( - // "You need to provide the `CodePushServerURL` IOS property for the @config-plugins/react-native-code-push plugin to work." - // ); - // } + if (!props?.ios?.CodePushServerURL) { + throw new Error( + "You need to provide the `CodePushServerURL` iOS property for react-native-code-push-plugin to work. App Center is retired, so the default server no longer works.", + ); + } if (!props?.ios?.CodePushDeploymentKey) { throw new Error( - "You need to provide the `CodePushDeploymentKey` IOS property for the @config-plugins/react-native-code-push plugin to work.", + "You need to provide the `CodePushDeploymentKey` iOS property for react-native-code-push-plugin to work.", ); } return withInfoPlist(config, (infoPlistProps) => { - if (props?.ios?.CodePushServerURL) { - infoPlistProps.modResults.CodePushServerURL = - props?.ios?.CodePushServerURL; - } + infoPlistProps.modResults.CodePushServerURL = props.ios.CodePushServerURL; infoPlistProps.modResults.CodePushDeploymentKey = props.ios.CodePushDeploymentKey; diff --git a/src/plugin-config.ts b/src/plugin-config.ts index 0406046..66702b0 100644 --- a/src/plugin-config.ts +++ b/src/plugin-config.ts @@ -3,11 +3,11 @@ */ export type PluginConfigType = { ios: { - CodePushServerURL?: string; + CodePushServerURL: string; CodePushDeploymentKey: string; }; android: { - CodePushServerURL?: string; + CodePushServerURL: string; CodePushDeploymentKey: string; CodePushPublicKey?: string; };