User Tools

Site Tools


tanszek:oktatas:tdd_es_bdd

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tanszek:oktatas:tdd_es_bdd [2024/10/12 12:29] – [5. Tesztek írása (TDD módszerrel)] kneheztanszek:oktatas:tdd_es_bdd [2025/03/03 09:55] (current) – [9. BDD stílusú tesztek] knehez
Line 101: Line 101:
  
 <sxh json> <sxh json>
 +"type": "module",
 "scripts": { "scripts": {
   "test": "mocha"   "test": "mocha"
Line 191: Line 192:
 } }
  
-module.exports = UserRepository;+export default UserRepository;
 </sxh> </sxh>
  
Line 208: Line 209:
  
 ==== 9. BDD stílusú tesztek ==== ==== 9. BDD stílusú tesztek ====
 +
 +Hozzuk létre a ''test/userRepository.test.js''-t az alábbi tartalommal.
  
 <sxh javascript> <sxh javascript>
Line 272: Line 275:
   });   });
 }); });
 +</sxh>
 +
 +A teszt futtatás természetesen hibát ad.
 +
 +Hozzuk létre az ''services/userService.js'' implementációt az alábbiak szerint:
 +
 +<sxh javascript>
 +import bcrypt from 'bcrypt';
 +
 +class UserService {
 +    constructor(userRepository) {
 +        this.userRepository = userRepository;
 +    }
 +
 +    async registerUser(email, password) {
 +        const existingUser = await this.userRepository.findUserByEmail(email);
 +        if (existingUser) {
 +            return { success: false, message: 'Email already in use' };
 +        }
 +
 +        const hashedPassword = await bcrypt.hash(password, 10);
 +        const newUser = { email, password: hashedPassword };
 +        await this.userRepository.saveUser(newUser);
 +
 +        return { success: true, message: 'User registered successfully' };
 +    }
 +}
 +
 +export default UserService;  // CommonJS helyett exportáljuk ESM szintaxissal
 </sxh> </sxh>
tanszek/oktatas/tdd_es_bdd.1728736183.txt.gz · Last modified: 2024/10/12 12:29 by knehez