1import { resolve } from 'path';
2
3import { getAllowBackup, getAllowBackupFromManifest, setAllowBackup } from '../AllowBackup';
4import { readAndroidManifestAsync } from '../Manifest';
5
6const fixturesPath = resolve(__dirname, 'fixtures');
7const sampleManifestPath = resolve(fixturesPath, 'react-native-AndroidManifest.xml');
8
9describe('allowBackup', () => {
10  it(`defaults to true`, () => {
11    expect(getAllowBackup({})).toBe(true);
12    expect(getAllowBackup({ android: { allowBackup: false } })).toBe(false);
13  });
14
15  it('sets the allowBackup property to true', async () => {
16    const androidManifestJsonUnaltered = await readAndroidManifestAsync(sampleManifestPath);
17    let androidManifestJson = await readAndroidManifestAsync(sampleManifestPath);
18    androidManifestJson = await setAllowBackup({}, { ...androidManifestJson });
19
20    const result = getAllowBackupFromManifest(androidManifestJson);
21    expect(androidManifestJsonUnaltered).toEqual(androidManifestJson);
22    // Sanity check `getAllowBackupFromManifest` works as expected.
23    expect(result).toBe(true);
24  });
25  it('sets the allowBackup property to false', async () => {
26    const androidManifestJsonUnaltered = await readAndroidManifestAsync(sampleManifestPath);
27    let androidManifestJson = await readAndroidManifestAsync(sampleManifestPath);
28    androidManifestJson = await setAllowBackup(
29      { android: { allowBackup: false } },
30      androidManifestJson
31    );
32
33    const result = getAllowBackupFromManifest(androidManifestJson);
34    // The fixture has `android:allowBackup="true"`, lets test that it did in fact get modified.
35    expect(getAllowBackupFromManifest(androidManifestJsonUnaltered)).not.toEqual(result);
36    expect(result).toBe(false);
37  });
38});
39