All files / src/lib/schema api-token-schema.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 0/0
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2860x 60x 60x   60x                                              
import joi from 'joi';
import { ALL, ApiTokenType } from '../types/models/api-token';
import { DEFAULT_ENV } from '../util/constants';
 
export const createApiToken = joi
    .object()
    .keys({
        username: joi.string().required(),
        type: joi
            .string()
            .lowercase()
            .required()
            .valid(ApiTokenType.ADMIN, ApiTokenType.CLIENT),
        expiresAt: joi.date().optional(),
        project: joi.when('projects', {
            not: joi.required(),
            then: joi.string().optional().default(ALL),
        }),
        projects: joi.array().min(0).optional(),
        environment: joi.when('type', {
            is: joi.string().valid(ApiTokenType.CLIENT),
            then: joi.string().optional().default(DEFAULT_ENV),
            otherwise: joi.string().optional().default(ALL),
        }),
    })
    .nand('project', 'projects')
    .options({ stripUnknown: true, allowUnknown: false, abortEarly: false });