@augment-vir/common
Version:
A collection of augments, helpers types, functions, and classes for any JavaScript environment.
59 lines (58 loc) • 1.92 kB
JavaScript
/**
* Use this to define mock entries that _shouldn't_ be saved to the database so that we can easily
* write tests for missing data.
*
* @category Prisma : Common
* @category Package : @augment-vir/common
* @example
*
* ```ts
* import {type PrismaClient} from '@prisma/client';
* import {prismaModelCreateExclude, PrismaKeyedModelCreate} from '@augment-vir/common';
*
* export const mockUsers = {
* user1: {
* id: 1,
* authRole: 'admin',
* },
* missingUser: {
* id: -1,
* authRole: 'user',
* [prismaModelCreateExclude]: true,
* },
* } as const satisfies PrismaKeyedModelCreate<PrismaClient, 'User'>;
* ```
*
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export const prismaModelCreateExclude = Symbol('prisma-model-create-exclude');
/**
* Use this to prevent the id property from being included when creating a mock record, allowing the
* database's internal auto-increment functionality to generate one. This is necessary when testing
* creation of new records because manually specified ids do not increment the auto incrementor.
*
* @category Prisma : Common
* @category Package : @augment-vir/common
* @example
*
* ```ts
* import {type PrismaClient} from '@prisma/client';
* import {prismaModelCreateOmitId, PrismaKeyedModelCreate} from '@augment-vir/common';
*
* export const mockUsers = {
* user1: {
* id: 1,
* authRole: 'admin',
* [prismaModelCreateOmitId]: true,
* },
* user2: {
* id: 2,
* authRole: 'admin',
* [prismaModelCreateOmitId]: true,
* },
* } as const satisfies PrismaKeyedModelCreate<PrismaClient, 'User'>;
* ```
*
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export const prismaModelCreateOmitId = Symbol('prisma-model-create-exclude-id');