import type { ISession, ISessionStore, } from '../../lib/types/stores/session-store'; export default class FakeSessionStore implements ISessionStore { private sessions: ISession[] = []; async getActiveSessions(): Promise { return this.sessions.filter((session) => session.expired != null); } destroy(): void {} async exists(key: string): Promise { return this.sessions.some((s) => s.sid === key); } async getAll(): Promise { return this.sessions; } async getSessionsForUser(userId: number): Promise { return this.sessions.filter( (session) => session.sess.user.id === userId, ); } async deleteSessionsForUser(userId: number): Promise { this.sessions = this.sessions.filter( (session) => session.sess.user.id !== userId, ); } async deleteAll(): Promise { this.sessions = []; } async delete(sid: string): Promise { this.sessions.splice( this.sessions.findIndex((s) => s.sid === sid), 1, ); } async get(sid: string): Promise { return this.sessions.find((s) => s.sid === sid); } async insertSession(data: Omit): Promise { const session = { ...data, createdAt: new Date() }; this.sessions.push(session); return session; } }