Skip to content

Commit

Permalink
Update create-initial-data.seed.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
w3bdesign committed Nov 22, 2024
1 parent 2bc8806 commit c17e985
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions backend/src/database/seeds/create-initial-data.seed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,38 @@ describe('createInitialData', () => {
// Verify error was logged
expect(console.error).toHaveBeenCalledWith('Error creating initial data:', hashError);
});

it('should use default phone number when EMPLOYEE_PHONE is not set', async () => {
// Remove EMPLOYEE_PHONE from environment
delete process.env.EMPLOYEE_PHONE;

// Mock that employee doesn't exist
(mockUserRepository.findOne as jest.Mock).mockResolvedValue(null);

// Mock created services
const mockServices = [{ id: '1', name: 'Standard Klipp' }];
(mockServiceRepository.save as jest.Mock).mockResolvedValue(mockServices);

// Mock created employee user
const mockEmployeeUser = {
id: 'user-1',
email: '[email protected]',
role: UserRole.EMPLOYEE,
};
(mockUserRepository.save as jest.Mock).mockResolvedValue(mockEmployeeUser);

// Mock created employee
const mockEmployee = {
id: 'employee-1',
user: mockEmployeeUser,
};
(mockEmployeeRepository.save as jest.Mock).mockResolvedValue(mockEmployee);

await createInitialData(mockDataSource as DataSource);

// Verify employee user was created with default phone number
expect(mockUserRepository.save).toHaveBeenCalledWith(expect.objectContaining({
phoneNumber: '+1234567890', // This is the default value
}));
});
});

0 comments on commit c17e985

Please sign in to comment.