Skip to content

The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.

1.5 KB
Raw Blame
// LIN-900: no alert email about your own change while another admin hears of it; keys and impersonation always tell.
import { describe, expect, it } from 'vitest'
import { ownChange, withoutActor } from './admin-alert-actor.ts'

describe('withoutActor', () => {
  const admins = ['[email protected]', '[email protected]']
  it('leaves out the admin who made the change', () => {
    expect(withoutActor(admins, { email: '[email protected]' })).toEqual(['[email protected]'])
  })
  it('keeps everyone for the operator, an unknown actor or none', () => {
    expect(withoutActor(admins, { operator: true })).toEqual(admins)
    expect(withoutActor(admins, { email: null })).toEqual(admins)
    expect(withoutActor(admins, undefined)).toEqual(admins)
  })
  it('keeps the only admin: nobody else would hear of it', () => {
    expect(withoutActor(['[email protected]'], { email: '[email protected]' })).toEqual(['[email protected]'])
  })
})

describe('ownChange', () => {
  const who = { email: '[email protected]' }
  it('is the person in their own session', () => {
    expect(ownChange({ sessionId: 's' }, who)).toBe(who)
  })
  it('is nobody without a session, for a key or an impersonation', () => {
    expect(ownChange({}, who)).toBeUndefined()
    expect(ownChange({ sessionId: 's', setupKeyId: 'k' }, who)).toBeUndefined()
    expect(ownChange({ sessionId: 's', apiKeyId: 'k' }, who)).toBeUndefined()
    expect(ownChange({ sessionId: 's', personalKeyId: 'k' }, who)).toBeUndefined()
    expect(ownChange({ sessionId: 's', impersonation: { by: 'x' } }, who)).toBeUndefined()
  })
})