import { IProjectHealthUpdate, IProjectInsert, IProjectStore, } from '../../lib/types/stores/project-store'; import { IEnvironment, IProject, IProjectWithCount, } from '../../lib/types/model'; import NotFoundError from '../../lib/error/notfound-error'; import { IEnvironmentProjectLink, IProjectMembersCount, } from 'lib/db/project-store'; export default class FakeProjectStore implements IProjectStore { projects: IProject[] = []; projectEnvironment: Map> = new Map(); getEnvironmentsForProject(): Promise { throw new Error('Method not implemented.'); } getProjectLinksForEnvironments( // eslint-disable-next-line @typescript-eslint/no-unused-vars environments: string[], ): Promise { throw new Error('Method not implemented.'); } async addEnvironmentToProject( // eslint-disable-next-line @typescript-eslint/no-unused-vars id: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars environment: string, ): Promise { const environments = this.projectEnvironment.get(id) || new Set(); environments.add(environment); this.projectEnvironment.set(id, environments); } async getProjectsWithCounts(): Promise { return this.projects.map((p) => { return { ...p, memberCount: 0, featureCount: 0 }; }); } private createInternal(project: IProjectInsert): IProject { const newProj: IProject = { ...project, health: 100, createdAt: new Date(), }; this.projects.push(newProj); return newProj; } async create(project: IProjectInsert): Promise { return this.createInternal(project); } async delete(key: string): Promise { this.projects.splice( this.projects.findIndex((p) => p.id === key), 1, ); } async deleteAll(): Promise { this.projects = []; } async deleteEnvironmentForProject( id: string, environment: string, ): Promise { const environments = this.projectEnvironment.get(id); if (environments) { environments.delete(environment); this.projectEnvironment.set(id, environments); } } destroy(): void {} async count(): Promise { return this.projects.length; } async exists(key: string): Promise { return this.projects.some((p) => p.id === key); } async get(key: string): Promise { const project = this.projects.find((p) => p.id === key); if (project) { return project; } throw new NotFoundError(`Could not find project with id: ${key}`); } async getAll(): Promise { return this.projects; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async getMembersCountByProject(projectId: string): Promise { return Promise.resolve(0); } async hasProject(id: string): Promise { return this.exists(id); } async importProjects( // eslint-disable-next-line @typescript-eslint/no-unused-vars projects: IProjectInsert[], // eslint-disable-next-line @typescript-eslint/no-unused-vars environments?: IEnvironment[], ): Promise { return projects.map((p) => this.createInternal(p)); } async update(update: IProjectInsert): Promise { await this.delete(update.id); this.createInternal(update); } async updateHealth(healthUpdate: IProjectHealthUpdate): Promise { this.projects.find((p) => p.id === healthUpdate.id).health = healthUpdate.health; } getMembersCount(): Promise { throw new Error('Method not implemented.'); } // eslint-disable-next-line @typescript-eslint/no-unused-vars getProjectsByUser(userId: number): Promise { throw new Error('Method not implemented.'); } addEnvironmentToProjects( // eslint-disable-next-line @typescript-eslint/no-unused-vars environment: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars projects: string[], ): Promise { throw new Error('Method not implemented.'); } getMembersCountByProjectAfterDate( // eslint-disable-next-line @typescript-eslint/no-unused-vars projectId: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars date: string, ): Promise { throw new Error('Method not implemented'); } }