@@ -12,7 +12,9 @@ function runtimeSource(relativePath: string): string {
1212 return new Bun . Transpiler ( { loader : 'ts' } ) . transformSync ( source ) ;
1313}
1414
15- const storeSource = runtimeSource ( '../../harmony/pushy/src/main/ets/UpdateContext.ts' ) ;
15+ const storeSource = runtimeSource (
16+ '../../harmony/pushy/src/main/ets/UpdateContext.ts'
17+ ) ;
1618const clientSource = runtimeSource ( '../client.ts' ) ;
1719
1820interface ConfigStore {
@@ -45,6 +47,7 @@ function storeHarness() {
4547 `${ storeSource } \nconst store = Object.create(UpdateContext.prototype); store.preferences = preferences; store.flushBatchDepth = 0; store;` ,
4648 {
4749 preferences,
50+ util : { generateRandomUUID : ( ) => 'native-installation-id' } ,
4851 KEY_CONFIG : 'nativeConfig' ,
4952 KEY_RESP_CACHE : 'nativeCheckResp' ,
5053 markJsCheckCompleted : ( config : string ) => clearedSignals . push ( config ) ,
@@ -53,8 +56,12 @@ function storeHarness() {
5356 }
5457 ) as ConfigStore ;
5558 return {
56- store, values, clearedSignals,
57- fail : ( value : boolean ) => { shouldFail = value ; } ,
59+ store,
60+ values,
61+ clearedSignals,
62+ fail : ( value : boolean ) => {
63+ shouldFail = value ;
64+ } ,
5865 flushes : ( ) => flushes ,
5966 } ;
6067}
@@ -77,7 +84,9 @@ function clientHarness(native: boolean) {
7784 i18n : { setLocale ( ) { } } ,
7885 dedupeEndpoints : ( urls : string [ ] ) => [ ...new Set ( urls ) ] ,
7986 PushyModule : {
80- syncNativeConfig : async ( config : string ) => { writes . push ( config ) ; } ,
87+ syncNativeConfig : async ( config : string ) => {
88+ writes . push ( config ) ;
89+ } ,
8190 } ,
8291 }
8392 ) as { setOptions : ( options : Record < string , unknown > ) => void } ;
@@ -86,9 +95,12 @@ function clientHarness(native: boolean) {
8695
8796describe ( 'native configuration normalization' , ( ) => {
8897 test ( 'appKey alone supplies Pushy endpoints without automatically activating' , ( ) => {
89- const config = JSON . parse ( normalizeNativeUpdateConfig ( { appKey : 'test-app' } ) ) ;
98+ const config = JSON . parse (
99+ normalizeNativeUpdateConfig ( { appKey : 'test-app' } )
100+ ) ;
90101 expect ( config . endpoints ) . toEqual ( [
91- 'https://update.react-native.cn/api' , 'https://update.reactnative.cn/api' ,
102+ 'https://update.react-native.cn/api' ,
103+ 'https://update.reactnative.cn/api' ,
92104 ] ) ;
93105 expect ( config . queryUrls ) . toHaveLength ( 2 ) ;
94106 expect ( config . afterDownload ) . toBe ( 'none' ) ;
@@ -99,7 +111,10 @@ describe('native configuration normalization', () => {
99111 test ( 'custom endpoints do not inherit public discovery, and are deduplicated' , ( ) => {
100112 const options : NativeUpdateConfig = {
101113 appKey : 'test-app' ,
102- endpoints : [ 'https://updates.example/api/' , 'https://updates.example/api' ] ,
114+ endpoints : [
115+ 'https://updates.example/api/' ,
116+ 'https://updates.example/api' ,
117+ ] ,
103118 afterDownload : 'setNeedUpdate' ,
104119 } ;
105120 const original = JSON . stringify ( options ) ;
@@ -111,24 +126,34 @@ describe('native configuration normalization', () => {
111126 } ) ;
112127
113128 test ( 'allows explicit discovery URLs and version identity overrides' , ( ) => {
114- const config = JSON . parse ( normalizeNativeUpdateConfig ( {
115- appKey : 'test-app' , endpoints : [ 'http://localhost:8080/api' ] ,
116- queryUrls : [ 'https://updates.example/endpoints.json?v=1' ] ,
117- packageVersion : '2.0' , rn : '0.77.3' , rnu : 'test-sdk' , disabled : true ,
118- } ) ) ;
129+ const config = JSON . parse (
130+ normalizeNativeUpdateConfig ( {
131+ appKey : 'test-app' ,
132+ endpoints : [ 'http://localhost:8080/api' ] ,
133+ queryUrls : [ 'https://updates.example/endpoints.json?v=1' ] ,
134+ packageVersion : '2.0' ,
135+ rn : '0.77.3' ,
136+ rnu : 'test-sdk' ,
137+ disabled : true ,
138+ } )
139+ ) ;
119140 expect ( config . packageVersion ) . toBe ( '2.0' ) ;
120141 expect ( config . disabled ) . toBe ( true ) ;
121142 expect ( config . queryUrls [ 0 ] ) . toContain ( '?v=1' ) ;
122143 } ) ;
123144
124145 for ( const [ name , options ] of [
125- [ 'missing key' , { } ] , [ 'blank key' , { appKey : ' ' } ] ,
146+ [ 'missing key' , { } ] ,
147+ [ 'blank key' , { appKey : ' ' } ] ,
126148 [ 'wrong key type' , { appKey : 12 } ] ,
127149 [ 'empty endpoints' , { appKey : 'a' , endpoints : [ ] } ] ,
128150 [ 'null endpoints' , { appKey : 'a' , endpoints : null } ] ,
129151 [ 'non-array endpoints' , { appKey : 'a' , endpoints : 'https://example.com' } ] ,
130152 [ 'unsafe scheme' , { appKey : 'a' , endpoints : [ 'file:///tmp/update' ] } ] ,
131- [ 'credentials' , { appKey : 'a' , endpoints : [ 'https://user:pass@example.com' ] } ] ,
153+ [
154+ 'credentials' ,
155+ { appKey : 'a' , endpoints : [ 'https://user:pass@example.com' ] } ,
156+ ] ,
132157 [ 'relative URL' , { appKey : 'a' , endpoints : [ '/api' ] } ] ,
133158 [ 'base query' , { appKey : 'a' , endpoints : [ 'https://example.com/api?x=1' ] } ] ,
134159 [ 'wrong discovery type' , { appKey : 'a' , queryUrls : [ 42 ] } ] ,
@@ -138,7 +163,9 @@ describe('native configuration normalization', () => {
138163 [ 'unknown option' , { appKey : 'a' , endponts : [ 'https://example.com' ] } ] ,
139164 ] as const ) {
140165 test ( `rejects ${ name } before storage is touched` , ( ) => {
141- expect ( ( ) => normalizeNativeUpdateConfig ( options as unknown as NativeUpdateConfig ) ) . toThrow ( ) ;
166+ expect ( ( ) =>
167+ normalizeNativeUpdateConfig ( options as unknown as NativeUpdateConfig )
168+ ) . toThrow ( ) ;
142169 } ) ;
143170 }
144171} ) ;
@@ -153,8 +180,17 @@ describe('actual native configuration store', () => {
153180 expect ( h . values . has ( 'nativeCheckResp' ) ) . toBe ( false ) ;
154181 await h . store . setNativeConfig ( 'A' ) ;
155182 expect ( h . store . getResetGeneration ( ) ) . toBe ( oldGeneration + 2 ) ;
156- expect ( await h . store . commitNativeCheckResult ( oldGeneration , 'old' , '{}' , true , 'stale' ) ) . toBe ( false ) ;
183+ expect (
184+ await h . store . commitNativeCheckResult (
185+ oldGeneration ,
186+ 'old' ,
187+ '{}' ,
188+ true ,
189+ 'stale'
190+ )
191+ ) . toBe ( false ) ;
157192 expect ( h . values . has ( 'hash_old' ) ) . toBe ( false ) ;
193+ expect ( h . values . get ( 'uuid' ) ) . toBe ( 'native-installation-id' ) ;
158194 expect ( h . clearedSignals ) . toEqual ( [ '' , '' , '' ] ) ;
159195 } ) ;
160196
@@ -170,7 +206,9 @@ describe('actual native configuration store', () => {
170206 test ( 'storage errors reject and an equal-value retry can recover' , async ( ) => {
171207 const h = storeHarness ( ) ;
172208 h . fail ( true ) ;
173- await expect ( h . store . setNativeConfig ( 'A' ) ) . rejects . toThrow ( 'storage unavailable' ) ;
209+ await expect ( h . store . setNativeConfig ( 'A' ) ) . rejects . toThrow (
210+ 'storage unavailable'
211+ ) ;
174212 h . fail ( false ) ;
175213 await h . store . setNativeConfig ( 'A' ) ;
176214 expect ( h . flushes ( ) ) . toBe ( 2 ) ;
0 commit comments