forked from FlowwStar/FlowStar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.test.ts
More file actions
84 lines (74 loc) · 2.65 KB
/
Copy pathexport.test.ts
File metadata and controls
84 lines (74 loc) · 2.65 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
81
82
83
84
import { describe, it, expect } from 'vitest'
import { streamsToCSV } from '@/lib/export'
import type { StreamData } from '@/types/stream'
const TOKEN = { address: 'CUSDC', symbol: 'USDC', decimals: 7 }
function makeStream(overrides?: Partial<StreamData>): StreamData {
return {
id: 'stream-1',
sender: 'GSEND123',
recipient: 'GRCPT456',
token: TOKEN,
depositedAmount: 100_000_000n, // 10 USDC
withdrawnAmount: 50_000_000n, // 5 USDC
startTime: 1_700_000_000n,
endTime: 1_700_086_400n,
cliffTime: 1_700_000_000n,
cliffAmount: 0n,
amountPerSecond: 1_157n,
linearAmount: 100_000_000n,
duration: 86_400n,
cancelled: false,
...overrides,
}
}
describe('streamsToCSV', () => {
it('includes a header row', () => {
const csv = streamsToCSV([makeStream()])
const first = csv.split('\n')[0]
expect(first).toContain('Stream ID')
expect(first).toContain('Sender')
expect(first).toContain('Recipient')
expect(first).toContain('Token')
})
it('includes stream data in rows', () => {
const csv = streamsToCSV([makeStream()])
expect(csv).toContain('stream-1')
expect(csv).toContain('GSEND123')
expect(csv).toContain('GRCPT456')
expect(csv).toContain('USDC')
})
it('returns only header for empty array', () => {
const csv = streamsToCSV([])
const lines = csv.split('\n').filter(Boolean)
expect(lines).toHaveLength(1)
})
it('generates one row per stream', () => {
const csv = streamsToCSV([makeStream(), makeStream({ id: 'stream-2' })])
const lines = csv.split('\n').filter(Boolean)
expect(lines).toHaveLength(3) // header + 2 data rows
})
it('shows "cancelled" status for cancelled stream', () => {
const csv = streamsToCSV([makeStream({ cancelled: true })], 1_700_043_200)
expect(csv).toContain('cancelled')
})
it('omits cliff date when cliffTime equals startTime', () => {
const s = makeStream({ cliffTime: 1_700_000_000n, startTime: 1_700_000_000n })
const csv = streamsToCSV([s])
const dataRow = csv.split('\n')[1]
// cliff column should be empty string
const cols = dataRow.split(',')
const cliffIdx = csv.split('\n')[0].split(',').indexOf('Cliff Date')
expect(cols[cliffIdx]).toBe('')
})
it('escapes values containing commas', () => {
const s = makeStream({ id: 'id,with,commas' })
const csv = streamsToCSV([s])
expect(csv).toContain('"id,with,commas"')
})
it('formats rate per day and per month columns', () => {
const csv = streamsToCSV([makeStream()])
const header = csv.split('\n')[0]
expect(header).toContain('Rate (per day)')
expect(header).toContain('Rate (per month)')
})
})