1import { validateConfig } from '../pluginConfig';
2
3describe(validateConfig, () => {
4  it('should throw error from invalid config type', () => {
5    expect(() => {
6      validateConfig(undefined);
7    }).toThrow();
8    expect(() => {
9      validateConfig(null);
10    }).toThrow();
11    expect(() => {
12      validateConfig('foo');
13    }).toThrow();
14    expect(() => {
15      validateConfig({ android: { compileSdkVersion: 'aString' } });
16    }).toThrow();
17  });
18
19  it('should throw error from unsupported android versions', () => {
20    expect(() =>
21      validateConfig({ android: { minSdkVersion: 14 } })
22    ).toThrowErrorMatchingInlineSnapshot(
23      `"\`android.minSdkVersion\` needs to be at least version 21."`
24    );
25    expect(() =>
26      validateConfig({ android: { compileSdkVersion: 14 } })
27    ).toThrowErrorMatchingInlineSnapshot(
28      `"\`android.compileSdkVersion\` needs to be at least version 31."`
29    );
30    expect(() =>
31      validateConfig({ android: { targetSdkVersion: 14 } })
32    ).toThrowErrorMatchingInlineSnapshot(
33      `"\`android.targetSdkVersion\` needs to be at least version 31."`
34    );
35    expect(() =>
36      validateConfig({ android: { kotlinVersion: '1.3.0' } })
37    ).toThrowErrorMatchingInlineSnapshot(
38      `"\`android.kotlinVersion\` needs to be at least version 1.6.10."`
39    );
40    expect(() =>
41      validateConfig({ ios: { deploymentTarget: '9.0' } })
42    ).toThrowErrorMatchingInlineSnapshot(
43      `"\`ios.deploymentTarget\` needs to be at least version 13.0."`
44    );
45  });
46
47  it('should not allow ios.flipper=true and ios.useFrameworks at the same time', () => {
48    expect(() =>
49      validateConfig({ ios: { flipper: true, useFrameworks: 'static' } })
50    ).toThrowErrorMatchingInlineSnapshot(
51      `"\`ios.flipper\` cannot be enabled when \`ios.useFrameworks\` is set."`
52    );
53  });
54
55  it(`should not allow ios.flipper='0.999.0' and ios.useFrameworks at the same time`, () => {
56    expect(() =>
57      validateConfig({ ios: { flipper: '0.999.0', useFrameworks: 'static' } })
58    ).toThrowErrorMatchingInlineSnapshot(
59      `"\`ios.flipper\` cannot be enabled when \`ios.useFrameworks\` is set."`
60    );
61  });
62
63  it('should allow ios.flipper=false and ios.useFrameworks at the same time', () => {
64    expect(() =>
65      validateConfig({ ios: { flipper: false, useFrameworks: 'static' } })
66    ).not.toThrow();
67  });
68
69  it('should use `enableShrinkResourcesInReleaseBuilds` with `enableProguardInReleaseBuilds`', () => {
70    expect(() =>
71      validateConfig({ android: { enableShrinkResourcesInReleaseBuilds: true } })
72    ).toThrow();
73
74    expect(() =>
75      validateConfig({
76        android: {
77          enableShrinkResourcesInReleaseBuilds: true,
78          enableProguardInReleaseBuilds: true,
79        },
80      })
81    ).not.toThrow();
82
83    expect(() =>
84      validateConfig({
85        android: {
86          enableShrinkResourcesInReleaseBuilds: true,
87          enableProguardInReleaseBuilds: false,
88        },
89      })
90    ).toThrow();
91  });
92
93  it('should validate ios.extraPods', () => {
94    expect(() => {
95      validateConfig({ ios: { extraPods: [{ name: 'Protobuf' }] } });
96    }).not.toThrow();
97
98    expect(() => {
99      validateConfig({ ios: { extraPods: [{ name: 'Protobuf', version: '~> 0.1.2' }] } });
100    }).not.toThrow();
101
102    expect(() => {
103      validateConfig({ ios: { extraPods: [{}] } });
104    }).toThrow();
105  });
106});
107