๐Ÿ“ฆ ionic-team / trapeze

๐Ÿ“„ android.json.test.ts ยท 76 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76import { copy } from '@ionic/utils-fs';
import { JsonFile } from '@trapezedev/project';
import { join } from 'path';
import { temporaryDirectory } from 'tempy';

import { Context, loadContext } from '../../src/ctx';
import { AndroidJsonOperation, Operation } from '../../src/definitions';
import Op from '../../src/operations/android/json';

describe('op: android.json', () => {
  let dir: string;
  let ctx: Context;

  beforeEach(async () => {
    dir = temporaryDirectory();

    await copy('../common/test/fixtures/ios-and-android', dir);

    ctx = await loadContext(dir);
    ctx.args.quiet = true;
  });

  it('should set android.json', async () => {
    const op: AndroidJsonOperation = {
      value: [
        {
          file: 'google-services.json',
          set: {
            project_info: {
              project_id: 'my-id',
            },
          },
        },
      ],
    };

    await Op(ctx, op as Operation);

    const file = ctx.project.vfs.get<JsonFile>(join(dir, 'android/google-services.json'));
    expect(file?.getData()?.getDocument()).toEqual({
      client: [],
      project_info: {
        project_id: 'my-id',
      },
    });
  });

  it('should merge android.json', async () => {
    const op: AndroidJsonOperation = {
      value: [
        {
          file: 'google-services.json',
          merge: {
            project_info: {
              project_id: 'my-id',
            },
          },
        },
      ],
    };

    await Op(ctx, op as Operation);

    const file = ctx.project.vfs.get<JsonFile>(join(dir, 'android/google-services.json'));
    expect(file?.getData()?.getDocument()).toEqual({
      client: [],
      project_info: {
        firebase_url: '',
        name: '1234',
        project_id: 'my-id',
        project_number: '1234',
      },
    });
  });
});