mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-13 05:38:47 +01:00
Previously, three layers enforced that non-admin users must have at least one library: the backend service validation, the frontend data provider (which silently skipped the API call for empty lists), and the frontend form validation. This prevented both creating users without libraries and removing all libraries from existing users. Removed the "at least one library" constraint across all layers so that library assignment is fully optional for non-admin users.
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { validateUserForm } from './userValidation'
|
|
|
|
describe('User Validation Utilities', () => {
|
|
const mockTranslate = vi.fn((key) => key)
|
|
|
|
describe('validateUserForm', () => {
|
|
it('should not return errors for admin users', () => {
|
|
const values = {
|
|
isAdmin: true,
|
|
libraryIds: [],
|
|
}
|
|
const errors = validateUserForm(values, mockTranslate)
|
|
expect(errors).toEqual({})
|
|
})
|
|
|
|
it('should not return errors for non-admin users with libraries', () => {
|
|
const values = {
|
|
isAdmin: false,
|
|
libraryIds: [1, 2, 3],
|
|
}
|
|
const errors = validateUserForm(values, mockTranslate)
|
|
expect(errors).toEqual({})
|
|
})
|
|
|
|
it('should not return errors for non-admin users without libraries', () => {
|
|
const values = {
|
|
isAdmin: false,
|
|
libraryIds: [],
|
|
}
|
|
const errors = validateUserForm(values, mockTranslate)
|
|
expect(errors).toEqual({})
|
|
})
|
|
|
|
it('should not return errors for non-admin users with undefined libraryIds', () => {
|
|
const values = {
|
|
isAdmin: false,
|
|
}
|
|
const errors = validateUserForm(values, mockTranslate)
|
|
expect(errors).toEqual({})
|
|
})
|
|
})
|
|
})
|