1import { IOSConfig } from '@expo/config-plugins';
2import plist from '@expo/plist';
3import { vol } from 'memfs';
4
5import { asMock } from '../../../../__tests__/asMock';
6import { simulatorBuildRequiresCodeSigning } from '../simulatorCodeSigning';
7
8jest.mock('fs');
9
10jest.mock('@expo/config-plugins', () => ({
11  IOSConfig: {
12    Entitlements: {
13      getEntitlementsPath: jest.fn(),
14    },
15  },
16}));
17
18describe(simulatorBuildRequiresCodeSigning, () => {
19  const projectRoot = '/';
20  afterEach(() => vol.reset());
21
22  it(`returns false if the entitlements file cannot be found`, () => {
23    asMock(IOSConfig.Entitlements.getEntitlementsPath).mockReturnValue(null);
24    expect(simulatorBuildRequiresCodeSigning(projectRoot)).toBe(false);
25  });
26  it(`returns false if the entitlements file contains values which don't need to be signed`, () => {
27    vol.fromJSON(
28      {
29        'entitlements.xml': plist.build({
30          'aps-environment': 'development',
31        }),
32      },
33      projectRoot
34    );
35
36    asMock(IOSConfig.Entitlements.getEntitlementsPath).mockReturnValue('/entitlements.xml');
37    expect(simulatorBuildRequiresCodeSigning(projectRoot)).toBe(false);
38  });
39  it(`returns true if the entitlements file contains values which require signing`, () => {
40    vol.fromJSON(
41      {
42        'entitlements.xml': plist.build({
43          'com.apple.developer.associated-domains': ['applinks:example.com'],
44        }),
45      },
46      projectRoot
47    );
48
49    asMock(IOSConfig.Entitlements.getEntitlementsPath).mockReturnValue('/entitlements.xml');
50    expect(simulatorBuildRequiresCodeSigning(projectRoot)).toBe(true);
51  });
52});
53