All files / src/lib/types api-user.ts

91.67% Statements 11/12
66.67% Branches 4/6
100% Functions 1/1
91.67% Lines 11/12

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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  65x                     65x 18x                                       18x     18x 18x 18x 18x 18x 11x   7x        
import { ApiTokenType } from './models/api-token';
import { CLIENT } from './permissions';
 
interface IApiUserData {
    username: string;
    permissions?: string[];
    projects?: string[];
    project?: string;
    environment: string;
    type: ApiTokenType;
}
 
export default class ApiUser {
    readonly isAPI: boolean = true;
 
    readonly username: string;
 
    readonly permissions: string[];
 
    readonly projects: string[];
 
    readonly environment: string;
 
    readonly type: ApiTokenType;
 
    constructor({
        username,
        permissions = [CLIENT],
        projects,
        project,
        environment,
        type,
    }: IApiUserData) {
        Iif (!username) {
            throw new TypeError('username is required');
        }
        this.username = username;
        this.permissions = permissions;
        this.environment = environment;
        this.type = type;
        if (projects && projects.length > 0) {
            this.projects = projects;
        } else {
            this.projects = [project];
        }
    }
}