(
rows: {
userId: string
role: string
currentPeriodCost: string | number | null
departedMemberUsage: string | number | null
}[]
)
| 587 | } |
| 588 | |
| 589 | function buildOrganizationUsageSnapshot( |
| 590 | rows: { |
| 591 | userId: string |
| 592 | role: string |
| 593 | currentPeriodCost: string | number | null |
| 594 | departedMemberUsage: string | number | null |
| 595 | }[] |
| 596 | ): OrganizationUsageSnapshot | null { |
| 597 | const owner = rows.find((row) => row.role === 'owner') |
| 598 | if (!owner) return null |
| 599 | |
| 600 | const sortedRows = [...rows].sort((a, b) => a.userId.localeCompare(b.userId)) |
| 601 | let pooledCurrentPeriodCost = 0 |
| 602 | for (const row of sortedRows) { |
| 603 | pooledCurrentPeriodCost += toNumber(toDecimal(row.currentPeriodCost)) |
| 604 | } |
| 605 | |
| 606 | return { |
| 607 | memberIds: sortedRows.map((row) => row.userId), |
| 608 | ownerId: owner.userId, |
| 609 | memberSignature: sortedRows |
| 610 | .map( |
| 611 | (row) => |
| 612 | `${row.userId}:${row.role}:${toNumber(toDecimal(row.currentPeriodCost)).toFixed(6)}` |
| 613 | ) |
| 614 | .join('|'), |
| 615 | pooledCurrentPeriodCost, |
| 616 | departedMemberUsage: toNumber(toDecimal(owner.departedMemberUsage)), |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | function organizationUsageSnapshotMatches( |
| 621 | expected: OrganizationUsageSnapshot, |
no test coverage detected