forked from MergeFi/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescrow-response.mapper.spec.ts
More file actions
80 lines (70 loc) · 2.08 KB
/
Copy pathescrow-response.mapper.spec.ts
File metadata and controls
80 lines (70 loc) · 2.08 KB
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
80
import { Escrow } from '../common/entities';
import { AssetType, EscrowStatus } from '../common/enums';
import { toPublicEscrow } from './escrow-response.mapper';
function makeEscrow(overrides: Partial<Escrow> = {}): Escrow {
return {
id: 'esc_1',
bounty: null,
bountyId: 'bounty_1',
milestone: null,
milestoneId: null,
maintenancePool: null,
maintenancePoolId: null,
sponsorId: 'sponsor_1',
contractId: null,
amount: '100.0000000',
asset: AssetType.USDC,
status: EscrowStatus.FAILED,
fundedByAddress: 'GFUNDER',
fundTxHash: null,
releaseTxHash: null,
refundTxHash: null,
metadata: {
error:
'Soroban simulation failed: HostError: Error(Contract, #1), account GABC...SECRET keypair mismatch',
},
payments: [],
lockedAt: null,
releasedAt: null,
refundedAt: null,
createdAt: new Date(),
updatedAt: new Date(),
...overrides,
};
}
describe('toPublicEscrow', () => {
it('strips metadata from the returned object', () => {
const escrow = makeEscrow();
const publicEscrow = toPublicEscrow(escrow);
expect(publicEscrow).not.toHaveProperty('metadata');
expect(JSON.stringify(publicEscrow)).not.toContain('SECRET');
expect(JSON.stringify(publicEscrow)).not.toContain('HostError');
});
it('preserves every other field unchanged', () => {
const escrow = makeEscrow();
const publicEscrow = toPublicEscrow(escrow);
expect(publicEscrow).toMatchObject({
id: 'esc_1',
bountyId: 'bounty_1',
sponsorId: 'sponsor_1',
amount: '100.0000000',
status: EscrowStatus.FAILED,
fundedByAddress: 'GFUNDER',
});
});
it('strips metadata even when it contains successful Soroban result data', () => {
const escrow = makeEscrow({
status: EscrowStatus.LOCKED,
metadata: {
fund: {
txHash: 'abc',
ledger: 42,
returnValue: null,
status: 'SUCCESS',
},
},
});
const publicEscrow = toPublicEscrow(escrow);
expect(publicEscrow).not.toHaveProperty('metadata');
});
});