Browse Source

[+Jordi] #163 - Add environment handling for external devices

Elena Cristina Raffay Iglesias 1 year ago
parent
commit
8c0750d90b
2 changed files with 19 additions and 3 deletions
  1. 5 0
      apps/wallet/config.js
  2. 14 3
      apps/wallet/test/unit/config.test.js

+ 5 - 0
apps/wallet/config.js

@@ -1,8 +1,13 @@
1
+import { Constants } from 'expo';
2
+import urlParse from 'url-parse';
3
+
1 4
 export default function getWalletProxyUrl(environment) {
2 5
   const walletProxyUrl = {
3 6
     dev: 'http://localhost:5010',
4 7
     production: 'http://ec2-54-194-123-109.eu-west-1.compute.amazonaws.com',
5 8
   };
9
+  const hostName = urlParse(Constants.linkingUri, true).hostname;
10
+  walletProxyUrl.dev = walletProxyUrl.dev.replace('localhost', hostName);
6 11
 
7 12
   return environment === 'production' ? walletProxyUrl.production : walletProxyUrl.dev;
8 13
 }

+ 14 - 3
apps/wallet/test/unit/config.test.js

@@ -1,10 +1,21 @@
1
+import { Constants } from 'expo';
1 2
 import getWalletProxyUrl from '../../config';
2 3
 
3 4
 describe('getWalletProxyUrl', () => {
4
-  it('should return dev url if passed nothing', () => {
5
+  const originalUri = Constants.linkingUri;
6
+
7
+  beforeEach(() => {
8
+    Constants.linkingUri = 'http://someurl.com';
9
+  });
10
+
11
+  afterEach(() => {
12
+    Constants.linkingUri = originalUri;
13
+  });
14
+
15
+  it('should return url in the current host if passed nothing', () => {
5 16
     const walletProxyUrl = getWalletProxyUrl();
6 17
 
7
-    const walletProxyUrlDev = 'http://localhost:5010';
18
+    const walletProxyUrlDev = 'http://someurl.com:5010';
8 19
 
9 20
     expect(walletProxyUrl).toEqual(walletProxyUrlDev);
10 21
   });
@@ -20,7 +31,7 @@ describe('getWalletProxyUrl', () => {
20 31
   it('should return dev url if passed garbage', () => {
21 32
     const walletProxyUrl = getWalletProxyUrl('garbage');
22 33
 
23
-    const walletProxyUrlDev = 'http://localhost:5010';
34
+    const walletProxyUrlDev = 'http://someurl.com:5010';
24 35
 
25 36
     expect(walletProxyUrl).toEqual(walletProxyUrlDev);
26 37
   });