Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

2.6 KB
Raw Blame
import { describe, expect, it } from 'vitest';

import type { AuthSession } from './session';

import { getCapabilities } from './capabilities';

const session = (overrides: Partial<AuthSession>): AuthSession => ({
  accountEpoch: 0,
  expiredUserId: null,
  hasSingleUserWork: false,
  multiuserEnabled: true,
  phase: 'ready',
  sessionExpired: false,
  setupRequired: false,
  strictPasswordChecking: false,
  switchingAccount: false,
  user: null,
  ...overrides,
});

describe('Identity route capabilities', () => {
  it.each(['unknown', 'unavailable'] as const)('grants nothing while auth mode is %s', (phase) => {
    expect(getCapabilities(session({ multiuserEnabled: false, phase }))).toEqual({
      canManageAppConfig: false,
      canManageImageMapVocabulary: false,
      canManageModels: false,
      canManageNodes: false,
      canManageSharedFonts: false,
      canManagePromptTemplates: false,
      canManageSharedSystemPrompts: false,
      canManageUsers: false,
      canClearOthersIntermediates: false,
    });
  });

  it('allows all local management in single-user mode', () => {
    expect(getCapabilities(session({ multiuserEnabled: false }))).toEqual({
      canManageAppConfig: true,
      canManageImageMapVocabulary: true,
      canManageModels: true,
      canManageNodes: true,
      canManageSharedFonts: true,
      canManagePromptTemplates: true,
      canManageSharedSystemPrompts: true,
      canManageUsers: false,
      canClearOthersIntermediates: false,
    });
  });

  it('limits multi-user administration to admins', () => {
    const baseUser = {
      created_at: '',
      display_name: null,
      email: '[email protected]',
      is_active: true,
      last_login_at: null,
      updated_at: '',
      user_id: 'user',
    };

    expect(getCapabilities(session({ user: { ...baseUser, is_admin: false } }))).toEqual({
      canManageAppConfig: false,
      canManageImageMapVocabulary: false,
      canManageModels: false,
      canManageNodes: false,
      canManageSharedFonts: false,
      canManagePromptTemplates: false,
      canManageSharedSystemPrompts: false,
      canManageUsers: false,
      canClearOthersIntermediates: false,
    });
    expect(getCapabilities(session({ user: { ...baseUser, is_admin: true } }))).toEqual({
      canManageAppConfig: true,
      canManageImageMapVocabulary: true,
      canManageModels: true,
      canManageNodes: true,
      canManageSharedFonts: true,
      canManagePromptTemplates: true,
      canManageSharedSystemPrompts: true,
      canManageUsers: true,
      canClearOthersIntermediates: true,
    });
  });
});