or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

api

features

charts

charts.mdconditional-formatting.mdvisualizations.md
authorization.mdchangesets.mdcharts-as-code.mdcompiler.mddashboards.mddbt.mdee-features.mdformatting.mdparameters.mdpivot.mdprojects-spaces.mdsql-runner.mdtemplating.mdwarehouse.md
index.md
tile.json

test-fixtures.mddocs/api/utilities/specialized/

Test Fixtures and Seed Data

Predefined seed data constants for testing and development. These constants provide consistent test data for organizations, users, projects, spaces, and groups.

Organization Seed Data

const SEED_ORG_1: {
  organization_uuid: string;
  organization_name: string;
};

const SEED_ORG_2: {
  organization_uuid: string;
  organization_name: string;
};

User Seed Data

Organization 1 Users

// Admin user
const SEED_ORG_1_ADMIN: {
  user_uuid: string;
  first_name: string;
  last_name: string;
  is_marketing_opted_in: boolean;
  is_tracking_anonymized: boolean;
  is_setup_complete: boolean;
  is_active: boolean;
};

const SEED_ORG_1_ADMIN_EMAIL: {
  email: string;
  is_primary: boolean;
};

const SEED_ORG_1_ADMIN_PASSWORD: {
  password: string;
};

const SEED_ORG_1_ADMIN_ROLE: OrganizationMemberRole;

// Editor user
const SEED_ORG_1_EDITOR: {
  user_uuid: string;
  first_name: string;
  last_name: string;
  is_marketing_opted_in: boolean;
  is_tracking_anonymized: boolean;
  is_setup_complete: boolean;
  is_active: boolean;
};

const SEED_ORG_1_EDITOR_EMAIL: {
  email: string;
  is_primary: boolean;
};

const SEED_ORG_1_EDITOR_PASSWORD: {
  password: string;
};

const SEED_ORG_1_EDITOR_ROLE: OrganizationMemberRole;

// Viewer user
const SEED_ORG_1_VIEWER: {
  user_uuid: string;
  first_name: string;
  last_name: string;
  is_marketing_opted_in: boolean;
  is_tracking_anonymized: boolean;
  is_setup_complete: boolean;
  is_active: boolean;
};

const SEED_ORG_1_VIEWER_EMAIL: {
  email: string;
  is_primary: boolean;
};

const SEED_ORG_1_VIEWER_PASSWORD: {
  password: string;
};

const SEED_ORG_1_VIEWER_ROLE: OrganizationMemberRole;

Organization 2 Users

const SEED_ORG_2_ADMIN: {
  user_uuid: string;
  first_name: string;
  last_name: string;
  is_marketing_opted_in: boolean;
  is_tracking_anonymized: boolean;
  is_setup_complete: boolean;
  is_active: boolean;
};

const SEED_ORG_2_ADMIN_EMAIL: {
  email: string;
  is_primary: boolean;
};

const SEED_ORG_2_ADMIN_PASSWORD: {
  password: string;
};

const SEED_ORG_2_ADMIN_ROLE: OrganizationMemberRole;

Project and Space Seed Data

const SEED_PROJECT: {
  project_uuid: string;
  name: string;
  project_type: ProjectType;
  dbt_connection_type: DbtProjectType;
  dbt_connection: null;
  copied_from_project_uuid: null;
  organization_warehouse_credentials_uuid: null;
};

const SEED_SPACE: {
  name: string;
};

const SEED_GROUP: {
  groupUuid: string;
  name: string;
};

const SEED_GROUP_2: {
  groupUuid: string;
  name: string;
};

const SEED_EMBED_SECRET: string;

Space Hierarchy Seed Data

type TreeCreateSpace = CreateSpace & {
  children?: TreeCreateSpace[];
  groupAccess?: {
    groupUuid: string;
    role: SpaceMemberRole;
  }[];
};

const SPACE_TREE_1: readonly TreeCreateSpace[];
const SPACE_TREE_2: readonly TreeCreateSpace[];

Example Values

The seed data contains these example values:

// Organization
SEED_ORG_1 = {
  organization_uuid: '172a2270-000f-42be-9c68-c4752c23ae51',
  organization_name: 'Jaffle Shop'
}

// Admin credentials
SEED_ORG_1_ADMIN_EMAIL.email = 'demo@lightdash.com'
SEED_ORG_1_ADMIN_PASSWORD.password = 'demo_password!'

Usage Examples

In Tests

import {
  SEED_ORG_1,
  SEED_ORG_1_ADMIN,
  SEED_ORG_1_ADMIN_EMAIL,
  SEED_ORG_1_ADMIN_PASSWORD,
  SEED_PROJECT,
  SEED_SPACE,
  SPACE_TREE_1,
} from '@lightdash/common';

// Use in tests
describe('Organization tests', () => {
  it('should create organization with admin', () => {
    const org = createOrganization({
      uuid: SEED_ORG_1.organization_uuid,
      name: SEED_ORG_1.organization_name,
    });

    const admin = createUser({
      ...SEED_ORG_1_ADMIN,
      ...SEED_ORG_1_ADMIN_EMAIL,
    });

    expect(org.uuid).toBe(SEED_ORG_1.organization_uuid);
    expect(admin.user_uuid).toBe(SEED_ORG_1_ADMIN.user_uuid);
  });

  it('should create space hierarchy', () => {
    const spaces = createSpaceTree(SEED_PROJECT.project_uuid, SPACE_TREE_1);
    expect(spaces).toHaveLength(3); // 3 parent spaces
    expect(spaces[0].children).toBeDefined();
  });
});

Database Seeding

import {
  SEED_ORG_1,
  SEED_ORG_1_ADMIN,
  SEED_ORG_1_ADMIN_EMAIL,
  SEED_PROJECT,
  SEED_SPACE,
  SEED_GROUP,
  SPACE_TREE_1,
} from '@lightdash/common';

// Use for development and seeding databases
async function seedDatabase() {
  // Create organization
  await db.insert(organizations).values(SEED_ORG_1);

  // Create admin user
  await db.insert(users).values({
    ...SEED_ORG_1_ADMIN,
    email: SEED_ORG_1_ADMIN_EMAIL.email,
  });

  // Create project
  await db.insert(projects).values(SEED_PROJECT);

  // Create space hierarchy
  for (const space of SPACE_TREE_1) {
    await createSpaceTree(space);
  }
}

// Alternative direct approach
async function seedDatabaseDirect() {
  await createOrganization(SEED_ORG_1);

  await createUser({
    ...SEED_ORG_1_ADMIN,
    email: SEED_ORG_1_ADMIN_EMAIL.email,
  });

  await createProject({
    ...SEED_PROJECT,
    organizationUuid: SEED_ORG_1.organization_uuid,
  });
}

Multi-Organization Testing

import {
  SEED_ORG_1,
  SEED_ORG_2,
  SEED_ORG_1_ADMIN,
  SEED_ORG_2_ADMIN,
} from '@lightdash/common';

describe('Multi-organization tests', () => {
  beforeEach(async () => {
    // Setup two organizations
    await createOrganization(SEED_ORG_1);
    await createOrganization(SEED_ORG_2);

    // Create admins for each
    await createUser({
      ...SEED_ORG_1_ADMIN,
      organizationUuid: SEED_ORG_1.organization_uuid,
    });

    await createUser({
      ...SEED_ORG_2_ADMIN,
      organizationUuid: SEED_ORG_2.organization_uuid,
    });
  });

  it('should isolate data between organizations', () => {
    // Test cross-organization data isolation
  });
});

Role-Based Testing

import {
  SEED_ORG_1_ADMIN,
  SEED_ORG_1_EDITOR,
  SEED_ORG_1_VIEWER,
  SEED_ORG_1_ADMIN_ROLE,
  SEED_ORG_1_EDITOR_ROLE,
  SEED_ORG_1_VIEWER_ROLE,
} from '@lightdash/common';

describe('Permission tests', () => {
  it('should enforce admin permissions', async () => {
    const admin = await createUser(SEED_ORG_1_ADMIN);
    expect(admin.role).toBe(SEED_ORG_1_ADMIN_ROLE);
    // Test admin-only operations
  });

  it('should enforce editor permissions', async () => {
    const editor = await createUser(SEED_ORG_1_EDITOR);
    expect(editor.role).toBe(SEED_ORG_1_EDITOR_ROLE);
    // Test editor operations
  });

  it('should enforce viewer permissions', async () => {
    const viewer = await createUser(SEED_ORG_1_VIEWER);
    expect(viewer.role).toBe(SEED_ORG_1_VIEWER_ROLE);
    // Test read-only operations
  });
});

Space Hierarchy Testing

import {
  SEED_PROJECT,
  SPACE_TREE_1,
  SPACE_TREE_2,
} from '@lightdash/common';

describe('Space hierarchy tests', () => {
  it('should create nested space structure', async () => {
    const spaces = await createSpaceTree(
      SEED_PROJECT.project_uuid,
      SPACE_TREE_1
    );

    // Verify parent-child relationships
    expect(spaces[0].children).toBeDefined();
    expect(spaces[0].children.length).toBeGreaterThan(0);
  });

  it('should handle multiple space trees', async () => {
    const tree1 = await createSpaceTree(
      SEED_PROJECT.project_uuid,
      SPACE_TREE_1
    );

    const tree2 = await createSpaceTree(
      SEED_PROJECT.project_uuid,
      SPACE_TREE_2
    );

    expect(tree1).not.toEqual(tree2);
  });
});

Authentication Testing

import {
  SEED_ORG_1_ADMIN_EMAIL,
  SEED_ORG_1_ADMIN_PASSWORD,
} from '@lightdash/common';

describe('Authentication tests', () => {
  it('should authenticate with valid credentials', async () => {
    const token = await authenticate(
      SEED_ORG_1_ADMIN_EMAIL.email,
      SEED_ORG_1_ADMIN_PASSWORD.password
    );

    expect(token).toBeDefined();
  });

  it('should reject invalid credentials', async () => {
    await expect(
      authenticate(
        SEED_ORG_1_ADMIN_EMAIL.email,
        'wrong_password'
      )
    ).rejects.toThrow();
  });
});

Use Cases

  • Unit Tests: Consistent test data across test suites
  • Integration Tests: Full organization setup with users and projects
  • Development: Quick database seeding for local development
  • Demo Environments: Realistic demo data for presentations
  • E2E Tests: Complete user flows with predefined accounts
  • Permission Testing: Test different role capabilities
  • Multi-Tenancy: Test organization isolation

Best Practices

  1. Consistency: Always use seed constants instead of hardcoding test data
  2. Isolation: Clean up seed data between tests
  3. Completeness: Use provided credentials and roles for realistic testing
  4. Hierarchies: Use space trees to test nested structures
  5. Roles: Test all permission levels (admin, editor, viewer)

Related Constants

  • See constants.md for application-wide constants
  • These seed values are specifically for testing/development
  • Production systems should never use these hardcoded values