Files
2026-03-04 20:02:39 +01:00

37 lines
1.7 KiB
JavaScript

const { expect } = require('chai');
const UserService = require('../src/services/UserService');
describe('UserService', () => {
let emailService;
let userService;
beforeEach(() => {
// TODO 1: Hozz létre egy mock EmailService-t (sendWelcomeEmail = async () => {})
// Tipp: emailService = { sendWelcomeEmail: async (email, name) => { /* mock */ } };
// TODO 2: Példányosítsd a UserService-t a mock-kal
// Tipp: userService = new UserService(emailService);
});
it('should create a user and send welcome email', async () => {
// TODO 3: Teszt: createUser létrehoz egy usert és email-t küld
// 1. Hívd meg a createUser-t: const user = await userService.createUser('Test User', 'test@example.com');
// 2. Ellenőrizd az user property-ket: expect(user).to.have.property('id');
// 3. Ellenőrizd a name-et: expect(user.name).to.equal('Test User');
// 4. Ellenőrizd, hogy a user a listában van: const users = userService.getAllUsers();
});
it('should throw error for duplicate email', async () => {
// TODO 4: Teszt: duplikált email hibát dob
// 1. Hozz létre egy usert: await userService.createUser('User 1', 'test@example.com');
// 2. Próbáld létrehozni ugyanazzal az emaillel: expect(...).to.throw() vagy try-catch
// Tipp async esetén: try { await userService.createUser(...); } catch(e) { expect(e.message).to.include('already exists'); }
});
it('should validate required fields', async () => {
// TODO 5: Teszt: hiányzó mezők validációs hibát dobnak
// 1. Próbáld meg név nélkül: expect(() => userService.createUser('', 'test@example.com')).to.throw();
// 2. Próbáld meg email nélkül: expect(() => userService.createUser('Test', '')).to.throw();
});
});