import { DatabaseManager } from '../src'; export default class Database { public name; constructor(name) { this.name = name; } public createUser() { return this.name; } public findUserById() { return this.name; } public findUserByEmail() { return this.name; } public findUserByUsername() { return this.name; } public findPasswordHash() { return this.name; } public findUserByEmailVerificationToken() { return this.name; } public findUserByResetPasswordToken() { return this.name; } public findUserByServiceId() { return this.name; } public addEmail() { return this.name; } public removeEmail() { return this.name; } public verifyEmail() { return this.name; } public setUsername() { return this.name; } public setPassword() { return this.name; } public setProfile() { return this.name; } public setService() { return this.name; } public unsetService() { return this.name; } public createSession() { return this.name; } public updateSession() { return this.name; } public invalidateSession() { return this.name; } public invalidateAllSessions() { return this.name; } public findSessionByToken() { return this.name; } public findSessionById() { return this.name; } public addEmailVerificationToken() { return this.name; } public addResetPasswordToken() { return this.name; } public setResetPassword() { return this.name; } } const databaseManager = new DatabaseManager({ userStorage: new Database('userStorage'), sessionStorage: new Database('sessionStorage'), }); describe('DatabaseManager configuration', () => { it('should throw if no configuration object specified', () => { expect(() => databaseManager.validateConfiguration()).toThrow(); }); it('should throw if no userStorage specified', () => { expect(() => databaseManager.validateConfiguration({ sessionStorage: true })).toThrow(); }); it('should throw if no sessionStorage specified', () => { expect(() => databaseManager.validateConfiguration({ userStorage: true })).toThrow(); }); it('should throw if no sessionStorage specified', () => { expect(() => databaseManager.validateConfiguration({ userStorage: true, sessionStorage: true, }) ).not.toThrow(); }); }); describe('DatabaseManager', () => { it('createUser should be called on userStorage', () => { expect(databaseManager.createUser()).toBe('userStorage'); }); it('findUserById should be called on userStorage', () => { expect(databaseManager.findUserById()).toBe('userStorage'); }); it('findUserByEmail should be called on userStorage', () => { expect(databaseManager.findUserByEmail()).toBe('userStorage'); }); it('findUserByUsername should be called on userStorage', () => { expect(databaseManager.findUserByUsername()).toBe('userStorage'); }); it('findPasswordHash should be called on userStorage', () => { expect(databaseManager.findPasswordHash()).toBe('userStorage'); }); it('findUserByEmailVerificationToken should be called on userStorage', () => { expect(databaseManager.findUserByEmailVerificationToken()).toBe('userStorage'); }); it('findUserByResetPasswordToken should be called on userStorage', () => { expect(databaseManager.findUserByResetPasswordToken()).toBe('userStorage'); }); it('findUserByServiceId should be called on userStorage', () => { expect(databaseManager.findUserByServiceId()).toBe('userStorage'); }); it('addEmail should be called on userStorage', () => { expect(databaseManager.addEmail()).toBe('userStorage'); }); it('removeEmail should be called on userStorage', () => { expect(databaseManager.removeEmail()).toBe('userStorage'); }); it('verifyEmail should be called on userStorage', () => { expect(databaseManager.verifyEmail()).toBe('userStorage'); }); it('setUsername should be called on userStorage', () => { expect(databaseManager.setUsername()).toBe('userStorage'); }); it('setPassword should be called on userStorage', () => { expect(databaseManager.setPassword()).toBe('userStorage'); }); it('setProfile should be called on userStorage', () => { expect(databaseManager.setProfile()).toBe('userStorage'); }); it('setService should be called on userStorage', () => { expect(databaseManager.setService()).toBe('userStorage'); }); it('unsetService should be called on userStorage', () => { expect(databaseManager.unsetService()).toBe('userStorage'); }); it('createSession should be called on sessionStorage', () => { expect(databaseManager.createSession()).toBe('sessionStorage'); }); it('updateSession should be called on sessionStorage', () => { expect(databaseManager.updateSession()).toBe('sessionStorage'); }); it('invalidateSession should be called on sessionStorage', () => { expect(databaseManager.invalidateSession()).toBe('sessionStorage'); }); it('invalidateAllSessions should be called on sessionStorage', () => { expect(databaseManager.invalidateAllSessions()).toBe('sessionStorage'); }); it('findSessionByToken should be called on sessionStorage', () => { expect(databaseManager.findSessionByToken()).toBe('sessionStorage'); }); it('findSessionById should be called on sessionStorage', () => { expect(databaseManager.findSessionById()).toBe('sessionStorage'); }); it('addEmailVerificationToken should be called on sessionStorage', () => { expect(databaseManager.addEmailVerificationToken()).toBe('userStorage'); }); it('addResetPasswordToken should be called on sessionStorage', () => { expect(databaseManager.addResetPasswordToken()).toBe('userStorage'); }); it('setResetPassword should be called on sessionStorage', () => { expect(databaseManager.setResetPassword()).toBe('userStorage'); }); });