tanszek:oktatas:tdd_es_bdd
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tanszek:oktatas:tdd_es_bdd [2024/10/12 12:29] – [8. Tesztek újrafuttatása] knehez | tanszek:oktatas:tdd_es_bdd [2025/03/03 09:55] (current) – [9. BDD stílusú tesztek] knehez | ||
---|---|---|---|
Line 101: | Line 101: | ||
<sxh json> | <sxh json> | ||
+ | " | ||
" | " | ||
" | " | ||
Line 111: | Line 112: | ||
<sxh javascript> | <sxh javascript> | ||
- | const assert | + | import |
- | const UserRepository | + | import |
describe(' | describe(' | ||
Line 191: | Line 192: | ||
} | } | ||
- | module.exports = UserRepository; | + | export default |
</ | </ | ||
Line 208: | Line 209: | ||
==== 9. BDD stílusú tesztek ==== | ==== 9. BDD stílusú tesztek ==== | ||
+ | |||
+ | Hozzuk létre a '' | ||
<sxh javascript> | <sxh javascript> | ||
Line 272: | Line 275: | ||
}); | }); | ||
}); | }); | ||
+ | </ | ||
+ | |||
+ | A teszt futtatás természetesen hibát ad. | ||
+ | |||
+ | Hozzuk létre az '' | ||
+ | |||
+ | <sxh javascript> | ||
+ | import bcrypt from ' | ||
+ | |||
+ | class UserService { | ||
+ | constructor(userRepository) { | ||
+ | this.userRepository = userRepository; | ||
+ | } | ||
+ | |||
+ | async registerUser(email, | ||
+ | const existingUser = await this.userRepository.findUserByEmail(email); | ||
+ | if (existingUser) { | ||
+ | return { success: false, message: 'Email already in use' }; | ||
+ | } | ||
+ | |||
+ | const hashedPassword = await bcrypt.hash(password, | ||
+ | const newUser = { email, password: hashedPassword }; | ||
+ | await this.userRepository.saveUser(newUser); | ||
+ | |||
+ | return { success: true, message: 'User registered successfully' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | export default UserService; | ||
</ | </ |
tanszek/oktatas/tdd_es_bdd.1728736172.txt.gz · Last modified: 2024/10/12 12:29 by knehez