import { PasswordToHashInterceptor } from './password-to-hash.interceptor'; describe('PasswordToHashInterceptor', () => { it('should be defined', () => { expect(new PasswordToHashInterceptor()).toBeDefined(); }); it('should filter passwordHash from response', () => { const dataWithHash = { key: 'value', passwordHash: 'hash', }; const dataWithoutHash = { key: 'value', }; expect( new PasswordToHashInterceptor().filterPasswordHashFromResponse( dataWithHash, ), ).toEqual(dataWithoutHash); expect( new PasswordToHashInterceptor().filterPasswordHashFromResponse( dataWithoutHash, ), ).toEqual(dataWithoutHash); }); it('should add a hash to incoming password', async () => { const req: any = { body: { password: 'pass' } }; await new PasswordToHashInterceptor().hashPasswordInRequest(req); expect(req.body.passwordHash).toBeDefined(); }); it('should let other requests through', async () => { const req: any = { body: { key: 'value' } }; await new PasswordToHashInterceptor().hashPasswordInRequest(req); expect(req.body.passwordHash).not.toBeDefined(); }); });