Files
supabase/apps/studio/tests/components/AuditLogs/OrgAuditLogs.utils.test.ts
David Camacho Cateura 1a483ab255 feat: Show all partner audit logs fields (#49305)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Changes to the audit logs UI

## What is the current behavior?

Partner related fields in the audit logs are not shown

## What is the new behavior?

- Shows all partner related fields in the audit logs
- Also uses the new fields to compute the user name



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Audit log entries now display partner names, installation IDs, user
emails, and user IDs when available.
* Partner identity and email are shown when standard actor details are
unavailable.
  * Partner names are consistently formatted for clearer display.
* Entries without partner information continue to display cleanly
without blank or confusing actor details.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-20 14:39:38 +02:00

109 lines
3.1 KiB
TypeScript

import dayjs from 'dayjs'
import { afterEach, describe, expect, test, vi } from 'vitest'
import {
formatPartnerIfExists,
formatSelectedDateRange,
} from '@/components/interfaces/Organization/AuditLogs/AuditLogs.utils'
// Pin "now" to a fixed point so date comparisons are deterministic
const NOW = dayjs('2024-06-15T14:30:00')
afterEach(() => {
vi.useRealTimers()
})
function fakeNow() {
vi.setSystemTime(NOW.toDate())
}
describe('formatSelectedDateRange', () => {
test('two different dates: preserves current time on both ends', () => {
fakeNow()
const result = formatSelectedDateRange({
from: '2024-06-10',
to: '2024-06-14',
})
const from = dayjs(result.from)
const to = dayjs(result.to)
expect(from.date()).toBe(10)
expect(to.date()).toBe(14)
// Both should carry current H:M:S
expect(from.hour()).toBe(NOW.hour())
expect(to.hour()).toBe(NOW.hour())
})
test('single date matching today: from is set to 00:00:00', () => {
fakeNow()
const today = NOW.format('YYYY-MM-DD')
const result = formatSelectedDateRange({ from: today, to: today })
const from = dayjs(result.from)
expect(from.hour()).toBe(0)
expect(from.minute()).toBe(0)
expect(from.second()).toBe(0)
})
test('single date matching today: to keeps current time', () => {
fakeNow()
const today = NOW.format('YYYY-MM-DD')
const result = formatSelectedDateRange({ from: today, to: today })
const to = dayjs(result.to)
expect(to.hour()).toBe(NOW.hour())
expect(to.minute()).toBe(NOW.minute())
})
test('single date in the past: to is set to 23:59:59', () => {
fakeNow()
const result = formatSelectedDateRange({
from: '2024-06-01',
to: '2024-06-01',
})
const to = dayjs(result.to)
expect(to.hour()).toBe(23)
expect(to.minute()).toBe(59)
expect(to.second()).toBe(59)
})
test('single date in the past: from keeps current time', () => {
fakeNow()
const result = formatSelectedDateRange({
from: '2024-06-01',
to: '2024-06-01',
})
const from = dayjs(result.from)
expect(from.hour()).toBe(NOW.hour())
})
test('output is in UTC ISO format', () => {
fakeNow()
const result = formatSelectedDateRange({
from: '2024-06-10',
to: '2024-06-14',
})
expect(result.from).toMatch(/Z$/)
expect(result.to).toMatch(/Z$/)
})
})
describe('formatPartnerIfExists', () => {
test('capitalizes the partner name', () => {
expect(formatPartnerIfExists('github', undefined)).toBe('Github')
})
test('prefixes with the partner email when provided', () => {
expect(formatPartnerIfExists('github', 'a@b.com')).toBe('a@b.com (Github)')
})
test('normalizes casing regardless of input case', () => {
expect(formatPartnerIfExists('GITHUB', undefined)).toBe('Github')
})
test('returns undefined when partner is undefined', () => {
expect(formatPartnerIfExists(undefined, 'a@b.com')).toBeUndefined()
})
test('returns undefined when partner is an empty string', () => {
expect(formatPartnerIfExists('', 'a@b.com')).toBeUndefined()
})
})