All files / src/auth/session/storage memory.ts

67.57% Statements 25/37
75% Branches 3/4
57.89% Functions 11/19
71.43% Lines 25/35

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  24x 24x 24x 24x 24x   224x   24x 29x 29x 29x 29x       24x 37x 37x 37x       24x 5x 5x 5x 5x   5x       24x      
import {SessionInterface} from '../types';
import {SessionStorage} from '../session_storage';
import {sanitizeShop} from '../../../utils/shop-validator';
 
export class MemorySessionStorage implements SessionStorage {
  private sessions: {[id: string]: SessionInterface} = {};
 
  public async storeSession(session: SessionInterface): Promise<boolean> {
    this.sessions[session.id] = session;
    return true;
  }
 
  public async loadSession(id: string): Promise<SessionInterface | undefined> {
    return this.sessions[id] || undefined;
  }
 
  public async deleteSession(id: string): Promise<boolean> {
    if (this.sessions[id]) {
      delete this.sessions[id];
    }
    return true;
  }
 
  public async deleteSessions(ids: string[]): Promise<boolean> {
    ids.forEach((id) => delete this.sessions[id]);
    return true;
  }
E
  public async findSessionsByShop(shop: string): Promise<SessionInterface[]> {
    const cleanShop = sanitizeShop(shop, true)!;
 
    const results = Object.values(this.sessions).filter(
      (session) => session.shop === cleanShop,
    );
    return results;
  }
}