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
76
77
78
79
80import { 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 { JsonOperation, Operation } from '../../src/definitions';
import Op from '../../src/operations/project/json';
describe('op: project.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 project.json', async () => {
const op: JsonOperation = {
value: [
{
file: 'project-json.json',
set: {
project_info: {
project_id: 'my-id',
},
},
},
],
};
await Op(ctx, op as Operation);
const file = ctx.project.vfs.get<JsonFile>(
join(dir, 'project-json.json'),
);
expect(file?.getData()?.getDocument()).toEqual({
client: [],
project_info: {
project_id: 'my-id',
},
});
});
it('should merge project.json', async () => {
const op: JsonOperation = {
value: [
{
file: 'project-json.json',
merge: {
project_info: {
project_id: 'my-id',
},
},
},
],
};
await Op(ctx, op as Operation);
const file = ctx.project.vfs.get<JsonFile>(
join(dir, 'project-json.json'),
);
expect(file?.getData()?.getDocument()).toEqual({
client: [],
project_info: {
firebase_url: '',
name: '1234',
project_id: 'my-id',
project_number: '1234',
},
});
});
});