1import { AppOwnership, ExecutionEnvironment } from 'expo-constants';
2
3import { describeManifest, mockConstants } from './ManifestTestUtils';
4
5beforeEach(() => {
6  jest.resetModules();
7  jest.resetAllMocks();
8});
9
10describe('bare', () => {
11  const originalWarn = console.warn;
12  beforeEach(() => {
13    console.warn = jest.fn();
14  });
15  afterEach(() => (console.warn = originalWarn));
16
17  describeManifest({ id: 'fake-uuid' })((manifestObj) => {
18    it(`uses native value`, () => {
19      mockConstants({ executionEnvironment: ExecutionEnvironment.Bare }, manifestObj);
20      const { makeRedirectUri } = require('../AuthSession');
21      // Test that the path is omitted
22      expect(makeRedirectUri({ path: 'bacon', native: 'value:/somn' })).toBe('value:/somn');
23    });
24  });
25});
26
27describe('Managed', () => {
28  describe('Standalone', () => {
29    describeManifest({
30      extra: {
31        expoClient: {
32          name: 'wat',
33          slug: 'wat',
34          scheme: 'demo',
35        },
36      },
37    })((manifestObj) => {
38      it(`creates a redirect URL`, () => {
39        mockConstants(
40          {
41            linkingUri: 'exp://exp.host/@test/test',
42            appOwnership: AppOwnership.Standalone,
43            executionEnvironment: ExecutionEnvironment.Standalone,
44          },
45          manifestObj
46        );
47        const { makeRedirectUri } = require('../AuthSession');
48        expect(makeRedirectUri()).toBe('demo://');
49      });
50    });
51
52    describeManifest({
53      extra: {
54        expoClient: {
55          name: 'wat',
56          slug: 'wat',
57          scheme: 'demo',
58        },
59      },
60    })((manifestObj) => {
61      it(`creates a redirect URL with a custom path`, () => {
62        mockConstants(
63          {
64            linkingUri: 'exp://exp.host/@test/test',
65            appOwnership: AppOwnership.Standalone,
66            executionEnvironment: ExecutionEnvironment.Standalone,
67          },
68          manifestObj
69        );
70        const { makeRedirectUri } = require('../AuthSession');
71        expect(makeRedirectUri({ path: 'bacon' })).toBe('demo://bacon');
72      });
73    });
74
75    describeManifest({
76      extra: {
77        expoClient: {
78          name: 'wat',
79          slug: 'wat',
80          scheme: 'demo',
81        },
82      },
83    })((manifestObj) => {
84      it(`uses native instead of generating a value`, () => {
85        mockConstants(
86          {
87            linkingUri: 'exp://exp.host/@test/test',
88            appOwnership: AppOwnership.Standalone,
89            executionEnvironment: ExecutionEnvironment.Standalone,
90          },
91          manifestObj
92        );
93        const { makeRedirectUri } = require('../AuthSession');
94        expect(
95          makeRedirectUri({
96            native: 'native.thing://somn',
97          })
98        ).toBe('native.thing://somn');
99      });
100    });
101
102    describe('Production', () => {
103      describeManifest({
104        extra: {
105          expoClient: {
106            name: 'wat',
107            slug: 'wat',
108            scheme: 'demo',
109          },
110        },
111      })((manifestObj) => {
112        it(`creates a redirect URL`, () => {
113          mockConstants(
114            {
115              linkingUri: 'exp://exp.host/@test/test',
116              appOwnership: AppOwnership.Expo,
117              executionEnvironment: ExecutionEnvironment.StoreClient,
118            },
119            manifestObj
120          );
121          const { makeRedirectUri } = require('../AuthSession');
122
123          expect(makeRedirectUri()).toBe('exp://exp.host/@test/test');
124        });
125      });
126
127      describeManifest({
128        extra: {
129          expoClient: {
130            name: 'wat',
131            slug: 'wat',
132            scheme: 'demo',
133          },
134        },
135      })((manifestObj) => {
136        it(`creates a redirect URL with a custom path`, () => {
137          mockConstants(
138            {
139              linkingUri: 'exp://exp.host/@test/test',
140              appOwnership: AppOwnership.Expo,
141              executionEnvironment: ExecutionEnvironment.StoreClient,
142            },
143            manifestObj
144          );
145
146          const { makeRedirectUri } = require('../AuthSession');
147
148          expect(makeRedirectUri({ path: 'bacon' })).toBe('exp://exp.host/@test/test/--/bacon');
149        });
150      });
151    });
152
153    describe('Development', () => {
154      describeManifest({
155        extra: {
156          expoClient: {
157            name: 'wat',
158            slug: 'wat',
159            scheme: 'demo',
160            hostUri: '192.168.1.4:8081',
161          },
162          expoGo: {
163            developer: {
164              projectRoot: '/Users/person/myapp',
165              tool: 'expo-cli',
166            },
167          },
168        },
169      })((manifestObj) => {
170        const devConstants = {
171          linkingUri: 'exp://192.168.1.4:8081/',
172          experienceUrl: 'exp://192.168.1.4:8081',
173          appOwnership: AppOwnership.Expo,
174          executionEnvironment: ExecutionEnvironment.StoreClient,
175        };
176
177        it(`creates a redirect URL`, () => {
178          mockConstants(devConstants, manifestObj);
179          const { makeRedirectUri } = require('../AuthSession');
180          expect(makeRedirectUri()).toBe('exp://192.168.1.4:8081');
181        });
182        it(`prefers localhost`, () => {
183          mockConstants(devConstants, manifestObj);
184          const { makeRedirectUri } = require('../AuthSession');
185          expect(makeRedirectUri({ preferLocalhost: true })).toBe('exp://localhost:8081');
186        });
187        it(`creates a redirect URL with a custom path`, () => {
188          mockConstants(devConstants, manifestObj);
189          const { makeRedirectUri } = require('../AuthSession');
190          expect(makeRedirectUri({ path: 'bacon' })).toBe('exp://192.168.1.4:8081/--/bacon');
191        });
192      });
193    });
194  });
195});
196