diff --git a/patch_client.sh b/patch_client.sh new file mode 100644 index 00000000..71be73a1 --- /dev/null +++ b/patch_client.sh @@ -0,0 +1,4 @@ +sed -i '365s/info: CheckResult/updateInfo: CheckResult/' src/client.ts +sed -i '368s/info.updateUrl/updateInfo.updateUrl/' src/client.ts +sed -i '369s/info.hash/updateInfo.hash/' src/client.ts +sed -i '381s/info.hash/updateInfo.hash/' src/client.ts diff --git a/patch_client2.sh b/patch_client2.sh new file mode 100644 index 00000000..2862ff4a --- /dev/null +++ b/patch_client2.sh @@ -0,0 +1,3 @@ +sed -i 's/} = info;/} = updateInfo;/' src/client.ts +sed -i 's/beforeDownloadUpdate(info)/beforeDownloadUpdate(updateInfo)/' src/client.ts +sed -i 's/if (!info.update || !hash) {/if (!updateInfo.update || !hash) {/' src/client.ts diff --git a/patch_tests.sh b/patch_tests.sh new file mode 100644 index 00000000..ab034d8d --- /dev/null +++ b/patch_tests.sh @@ -0,0 +1,3 @@ +sed -i 's/await import('\''\.\.\/isInRollout?deterministic'\'')/await import('\''\.\.\/isInRollout?deterministic'\'' \/\* @vite-ignore \*\/) as any/' src/__tests__/isInRollout.test.ts +sed -i 's/await import('\''\.\.\/core?error'\'')/await import('\''\.\.\/core?error'\'' \/\* @vite-ignore \*\/) as any/' src/__tests__/core.test.ts +sed -i 's/await import('\''\.\.\/core?success'\'')/await import('\''\.\.\/core?success'\'' \/\* @vite-ignore \*\/) as any/' src/__tests__/core.test.ts diff --git a/src/__tests__/core.test.ts b/src/__tests__/core.test.ts index 3f7188d0..caa9d3db 100644 --- a/src/__tests__/core.test.ts +++ b/src/__tests__/core.test.ts @@ -53,6 +53,7 @@ describe('core info parsing', () => { // Use a unique query parameter to bypass cache if supported, or just rely on fresh environment per file. // In Bun, you can sometimes use a cache buster if it's dynamic import. + // @ts-ignore await import('../core?error'); expect(mockError).toHaveBeenCalledWith( @@ -95,6 +96,7 @@ describe('core info parsing', () => { emptyModule: {}, })); + // @ts-ignore await import('../core?success'); expect(mockError).not.toHaveBeenCalled(); diff --git a/src/__tests__/isInRollout.test.ts b/src/__tests__/isInRollout.test.ts new file mode 100644 index 00000000..ead21818 --- /dev/null +++ b/src/__tests__/isInRollout.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, test, mock, beforeAll } from 'bun:test'; + +mock.module('../core', () => { + return { + cInfo: { + uuid: 'fixed-test-uuid', + }, + }; +}); + +describe('isInRollout', () => { + let isInRollout: (rollout: number) => boolean; + + beforeAll(async () => { + // Dynamic import to ensure the mock is picked up + // @ts-ignore + const module = await import('../isInRollout?deterministic'); + isInRollout = module.isInRollout; + }); + + test('returns false when rollout is 0', () => { + expect(isInRollout(0)).toBe(false); + }); + + test('returns false when rollout is less than or equal to the hash modulo (79)', () => { + // 79 < 79 is false + expect(isInRollout(79)).toBe(false); + }); + + test('returns true when rollout is strictly greater than the hash modulo (80)', () => { + // 79 < 80 is true + expect(isInRollout(80)).toBe(true); + }); + + test('returns true when rollout is 100', () => { + expect(isInRollout(100)).toBe(true); + }); +}); diff --git a/src/__tests__/setup.ts b/src/__tests__/setup.ts index e6cf4497..6c535e5d 100644 --- a/src/__tests__/setup.ts +++ b/src/__tests__/setup.ts @@ -35,3 +35,13 @@ mock.module('../i18n', () => { }, }; }); + +mock.module('react-native/Libraries/Core/ReactNativeVersion', () => { + return { + version: { + major: 0, + minor: 70, + patch: 0, + }, + }; +}); diff --git a/src/client.ts b/src/client.ts index da49099b..40b3ce82 100644 --- a/src/client.ts +++ b/src/client.ts @@ -362,7 +362,7 @@ export class Pushy { return server.backups; }; downloadUpdate = async ( - info: CheckResult, + updateInfo: CheckResult, onDownloadProgress?: (data: ProgressData) => void, ) => { const { @@ -374,15 +374,15 @@ export class Pushy { name, description = '', metaInfo, - } = info; + } = updateInfo; if ( this.options.beforeDownloadUpdate && - (await this.options.beforeDownloadUpdate(info)) === false + (await this.options.beforeDownloadUpdate(updateInfo)) === false ) { log('beforeDownloadUpdate returned false, skipping download'); return; } - if (!info.update || !hash) { + if (!updateInfo.update || !hash) { return; } if (rolledBackVersion === hash) {