1import {
2  appendScheme,
3  getScheme,
4  getSchemesFromPlist,
5  hasScheme,
6  removeScheme,
7  setScheme,
8} from '../Scheme';
9
10describe('scheme', () => {
11  it(`returns empty array if no scheme is provided`, () => {
12    expect(getScheme({})).toStrictEqual([]);
13  });
14
15  it(`returns the scheme if provided`, () => {
16    expect(getScheme({ scheme: 'myapp' })).toStrictEqual(['myapp']);
17    expect(
18      getScheme({
19        scheme: ['myapp', 'other', null],
20      })
21    ).toStrictEqual(['myapp', 'other']);
22  });
23
24  it(`sets the CFBundleUrlTypes if scheme is given`, () => {
25    expect(
26      setScheme(
27        {
28          // @ts-ignore: TODO -- add this to the ExpoConfig type
29          scheme: ['myapp', 'more'],
30          ios: {
31            // @ts-ignore: TODO -- add this to the ExpoConfig type
32            scheme: ['ios-only'],
33            bundleIdentifier: 'com.demo.value',
34          },
35        },
36        {}
37      )
38    ).toMatchObject({
39      CFBundleURLTypes: [{ CFBundleURLSchemes: ['myapp', 'more', 'ios-only', 'com.demo.value'] }],
40    });
41  });
42
43  it(`makes no changes to the infoPlist no scheme is provided`, () => {
44    expect(setScheme({}, {})).toMatchObject({});
45  });
46
47  it(`verifies that a scheme exists`, () => {
48    const infoPlist = {
49      CFBundleURLTypes: [{ CFBundleURLSchemes: ['myapp'] }],
50    };
51    expect(hasScheme('myapp', infoPlist)).toBe(true);
52    expect(hasScheme('myapp2', infoPlist)).toBe(false);
53  });
54
55  it(`lists all of the schemes`, () => {
56    const infoPlist = {
57      CFBundleURLTypes: [
58        { CFBundleURLSchemes: ['myapp1', 'myapp2'] },
59        { CFBundleURLSchemes: ['myapp3'] },
60      ],
61    };
62    expect(getSchemesFromPlist(infoPlist).length).toBe(3);
63  });
64
65  it(`append a scheme`, () => {
66    const infoPlist = {
67      CFBundleURLTypes: [
68        { CFBundleURLSchemes: ['myapp1', 'myapp2'] },
69        { CFBundleURLSchemes: ['myapp3'] },
70      ],
71    };
72    expect(appendScheme('myapp3', infoPlist)).toStrictEqual({
73      CFBundleURLTypes: [
74        { CFBundleURLSchemes: ['myapp1', 'myapp2'] },
75        { CFBundleURLSchemes: ['myapp3'] },
76      ],
77    });
78    expect(appendScheme('myapp4', infoPlist)).toStrictEqual({
79      CFBundleURLTypes: [
80        { CFBundleURLSchemes: ['myapp1', 'myapp2'] },
81        { CFBundleURLSchemes: ['myapp3'] },
82        { CFBundleURLSchemes: ['myapp4'] },
83      ],
84    });
85  });
86
87  it(`removes a scheme`, () => {
88    const infoPlist = {
89      CFBundleURLTypes: [
90        { CFBundleURLSchemes: ['myapp1', 'myapp2'] },
91        { CFBundleURLSchemes: ['myapp3'] },
92      ],
93    };
94    expect(removeScheme('myapp3', infoPlist)).toStrictEqual({
95      CFBundleURLTypes: [{ CFBundleURLSchemes: ['myapp1', 'myapp2'] }],
96    });
97  });
98});
99