src/app/utils/test-utils/TestEventEntity.ts

Description

Basic event entity type for unit tests, to avoid coupling tests to the deprecated EventNote class.

Has date, title, and attendance fields — the minimal structure needed for attendance-related tests.

Extends

Entity

Relationships

Used by

No results matching.

Depends on

Index

Properties
Methods

Properties

attendance
Type : AttendanceItem[]
Default value : []
Decorators :
@DatabaseField({dataType: 'attendance', isArray: true})
date
Type : Date
Decorators :
@DatabaseField({dataType: 'date-only'})
Static Readonly ENTITY_TYPE
Type : string
Default value : "TestEventEntity"
Inherited from Entity
Static Readonly icon
Type : IconName
Default value : "calendar"
Inherited from Entity
Static Readonly label
Type : string
Default value : "Test Event Entity"
Inherited from Entity
Static Readonly labelPlural
Type : string
Default value : "Test Event Entities"
relatesTo
Type : string
Decorators :
@DatabaseField()
title
Type : string
Decorators :
@DatabaseField()
Static Optional _isCustomizedType
todo: This property is no longer used and will be removed in future versions.
Type : boolean
Inherited from Entity

True if this type's schema has been customized dynamically from the config.

_rev
Type : string
Decorators :
@DatabaseField({anonymize: 'retain', isInternalField: true})
Inherited from Entity

internal database doc revision, used to detect conflicts by PouchDB/CouchDB

anonymized
Type : boolean
Decorators :
@DatabaseField({anonymize: 'retain', isInternalField: true})
Inherited from Entity

Whether this entity has been anonymized and therefore cannot be re-activated.

Static color
Type : string | ColorMapping[]
Inherited from Entity

color used for to highlight this entity type across the app.

Can be either:

  • A simple string (hex color code) for a single color
  • An array of ColorMapping objects for conditional colors based on entity properties
created
Type : UpdateMetadata
Decorators :
@DatabaseField({anonymize: 'retain', isInternalField: true})
Inherited from Entity
Static DATABASE
Type : string
Default value : "app"
Inherited from Entity

The database where these entities are stored.

Static Optional enableUserAccounts
Type : boolean
Inherited from Entity

Whether to enable user account creation for this entity type. When true, the UI will allow management of user accounts associated with this entity.

Static hasPII
Type : boolean
Default value : false
Inherited from Entity

whether this entity type can contain "personally identifiable information" (PII) and therefore should follow strict data protection requirements and offer a function to anonymize records.

inactive
Type : boolean
Decorators :
@DatabaseField({anonymize: 'retain', isInternalField: true})
Inherited from Entity
Static Optional isInternalEntity
Type : boolean
Inherited from Entity

if this entity type is an internal entity, i.e. only defined in the code base to store internal system data and not visible to the user for customization.

Static schema
Type : EntitySchema
Inherited from Entity

EntitySchema defining property transformations from/to the database. This is auto-generated from the property annotations @DatabaseField().

see /additional-documentation/how-to-guides/create-a-new-entity-type.html

Static Optional toBlockDetailsAttributes
Type : EntityBlockConfig
Inherited from Entity

Defining which attributes will be displayed in a tooltip on hover when the record is displayed as an entity-block.

Static toStringAttributes
Type : []
Default value : ["entityId"]
Inherited from Entity

Defining which attribute values of an entity should be shown in the .toString() method.

The default is the ID of the entity (entityId). This can be overwritten in subclasses or through the config.

updated
Type : UpdateMetadata
Decorators :
@DatabaseField({anonymize: 'retain', isInternalField: true})
Inherited from Entity

Methods

Static create
create(data: Partial | Date)
Parameters :
Name Type Optional Default value
data Partial<TestEventEntity> | Date No new Date()
Returns : TestEventEntity
Static generateEventWithAttendance
generateEventWithAttendance(participating: (unknown | unknown)[], date: unknown, activity?: Entity)

Generate an event with participants for the given attendance status array.

This is particularly useful to generate simple data for demo or test purposes.

Parameters :
Name Type Optional Default value Description
participating (unknown | unknown)[] No

Tuples of [childId, AttendanceLogicalStatus] or [childId, AttendanceLogicalStatus, remarks]

date unknown No new Date()

(Optional) date of the event; if not given today's date is used

activity Entity Yes

(Optional) reference to the connected activity entity

assertValid
assertValid()
Inherited from Entity

Checks if the entity is valid and if the check fails, throws an error explaining the failed check.

Returns : void
Public copy
copy(newId: string | boolean)
Inherited from Entity

Deep copy of the entity. The resulting entity will be of the same type as this (taking into account subclassing). All schema field values that are objects or arrays are deep-cloned to avoid shared mutable state between original and copy.

Parameters :
Name Type Optional Default value Description
newId string | boolean No false

if true, a new entityId will be generated; if a string, that value is used as new entityId

Returns : unknown
Static createPrefixedId
createPrefixedId(type: string, id: string)
Inherited from Entity

Create a prefixed id by adding the type prefix if it isn't already part of the given id.

Parameters :
Name Type Optional Description
type string No

The type prefix to be added.

id string No

The id to be extended with a prefix.

Returns : string
Static extractEntityIdFromId
extractEntityIdFromId(id: string)
Inherited from Entity

Extract entityId without prefix.

Parameters :
Name Type Optional Description
id string No

An entity's id including prefix.

Returns : string
Static extractTypeFromId
extractTypeFromId(id: string)
Inherited from Entity

Extract the ENTITY_TYPE from an id.

Parameters :
Name Type Optional Description
id string No

An entity's id including prefix.

Returns : string
Public getColor
getColor()
Inherited from Entity

Used by some generic UI components to set the color for the entity instance. Override this method as needed.

Returns : string
Static getColorWithConditions
getColorWithConditions(entity: Entity)
Inherited from Entity

Static method to evaluate conditional colors for an entity based on ColorMapping configuration.

Parameters :
Name Type Optional
entity Entity No
Returns : string
getConstructor
getConstructor()
Inherited from Entity

Get the class (Entity or the actual subclass of the instance) to call static methods on the correct class considering inheritance

Public getId
getId(withoutPrefix: unknown)
Inherited from Entity

Returns the id of this entity.

Note that an id is final and can't be changed after the object has been instantiated, hence there is no setId() method.

Parameters :
Name Type Optional Default value
withoutPrefix unknown No false
Returns : string

the unique id of this entity

getSchema
getSchema()
Inherited from Entity

Get the entity schema of this class

Returns : EntitySchema
Public getType
getType()
Inherited from Entity

Returns the type which is used to categorize this entity in the database.

Important: Do not overwrite this method! Types are handled internally.

Returns : string

the entity's type (which is the class name).

Public getWarningLevel
getWarningLevel()
Inherited from Entity

Override getWarningLevel() to define when the entity is in a critical condition and should be color-coded and highlighted in generic components of the UI.

Returns : WarningLevel
import { DatabaseEntity } from "../../core/entity/database-entity.decorator";
import { Entity } from "../../core/entity/model/entity";
import { DatabaseField } from "../../core/entity/database-field.decorator";
import { AttendanceItem } from "../../features/attendance/model/attendance-item";
import { AttendanceLogicalStatus } from "../../features/attendance/model/attendance-status";
import { defaultAttendanceStatusTypes } from "../../core/config/default-config/default-attendance-status-types";
import { EventWithAttendance } from "../../features/attendance/model/event-with-attendance";
import { IconName } from "@fortawesome/fontawesome-svg-core";

/**
 * Basic event entity type for unit tests, to avoid coupling tests to the deprecated EventNote class.
 *
 * Has date, title, and attendance fields — the minimal structure needed for attendance-related tests.
 */
@DatabaseEntity("TestEventEntity")
export class TestEventEntity extends Entity {
  static override readonly ENTITY_TYPE = "TestEventEntity";
  static override readonly label = "Test Event Entity";
  static override readonly labelPlural = "Test Event Entities";
  static override readonly icon: IconName = "calendar";

  @DatabaseField({ dataType: "date-only" })
  date: Date;

  @DatabaseField()
  title: string;

  @DatabaseField({ dataType: "attendance", isArray: true })
  attendance: AttendanceItem[] = [];

  @DatabaseField()
  relatesTo: string;

  static create(
    data: Partial<TestEventEntity> | Date = new Date(),
  ): TestEventEntity {
    if (data instanceof Date) {
      data = { date: data };
    }
    return Object.assign(new TestEventEntity(), data);
  }

  /**
   * Generate an event with participants for the given attendance status array.
   *
   * This is particularly useful to generate simple data for demo or test purposes.
   *
   * @param participating Tuples of [childId, AttendanceLogicalStatus] or [childId, AttendanceLogicalStatus, remarks]
   * @param date (Optional) date of the event; if not given today's date is used
   * @param activity (Optional) reference to the connected activity entity
   */
  static generateEventWithAttendance(
    participating: (
      | [string, AttendanceLogicalStatus]
      | [string, AttendanceLogicalStatus, string]
    )[],
    date = new Date(),
    activity?: Entity,
  ): EventWithAttendance {
    const event = TestEventEntity.create(date);
    for (const att of participating) {
      const item = new AttendanceItem();
      item.participant = att[0];
      item.status = defaultAttendanceStatusTypes.find(
        (t) => t.countAs === att[1],
      );
      if (att.length === 3) {
        item.remarks = att[2];
      }
      event.attendance.push(item);
    }
    event.relatesTo = activity?.getId();
    return new EventWithAttendance(
      event,
      "attendance",
      "date",
      "relatesTo",
      "authors",
      undefined,
    );
  }
}

results matching ""

    No results matching ""