mirror of
https://github.com/langgenius/dify.git
synced 2026-03-30 18:40:17 +08:00
- Moved test files for completion parameters, clipboard, app redirection, and emoji utilities to the appropriate directory structure. - Added comprehensive tests for clipboard functionality, including modern and legacy methods. - Implemented tests for app redirection logic based on user permissions and app modes. - Enhanced tests for completion parameters validation and error handling. - Introduced tests for emoji search functionality with various scenarios. - Updated icon utility tests to cover edge cases and security concerns. - Improved formatting tests for numbers, file sizes, and time representation.
96 lines
3.3 KiB
TypeScript
96 lines
3.3 KiB
TypeScript
import { DatasetPermission } from '@/models/datasets'
|
|
/**
|
|
* Test suite for permission utility functions
|
|
* Tests dataset edit permission logic based on user roles and dataset settings
|
|
*/
|
|
import { hasEditPermissionForDataset } from '../permission'
|
|
|
|
describe('permission', () => {
|
|
/**
|
|
* Tests hasEditPermissionForDataset which checks if a user can edit a dataset
|
|
* Based on three permission levels:
|
|
* - onlyMe: Only the creator can edit
|
|
* - allTeamMembers: All team members can edit
|
|
* - partialMembers: Only specified members can edit
|
|
*/
|
|
describe('hasEditPermissionForDataset', () => {
|
|
const userId = 'user-123'
|
|
const creatorId = 'creator-456'
|
|
const otherUserId = 'user-789'
|
|
|
|
it('returns true when permission is onlyMe and user is creator', () => {
|
|
const config = {
|
|
createdBy: userId,
|
|
partialMemberList: [],
|
|
permission: DatasetPermission.onlyMe,
|
|
}
|
|
expect(hasEditPermissionForDataset(userId, config)).toBe(true)
|
|
})
|
|
|
|
it('returns false when permission is onlyMe and user is not creator', () => {
|
|
const config = {
|
|
createdBy: creatorId,
|
|
partialMemberList: [],
|
|
permission: DatasetPermission.onlyMe,
|
|
}
|
|
expect(hasEditPermissionForDataset(userId, config)).toBe(false)
|
|
})
|
|
|
|
it('returns true when permission is allTeamMembers for any user', () => {
|
|
const config = {
|
|
createdBy: creatorId,
|
|
partialMemberList: [],
|
|
permission: DatasetPermission.allTeamMembers,
|
|
}
|
|
expect(hasEditPermissionForDataset(userId, config)).toBe(true)
|
|
expect(hasEditPermissionForDataset(otherUserId, config)).toBe(true)
|
|
expect(hasEditPermissionForDataset(creatorId, config)).toBe(true)
|
|
})
|
|
|
|
it('returns true when permission is partialMembers and user is in list', () => {
|
|
const config = {
|
|
createdBy: creatorId,
|
|
partialMemberList: [userId, otherUserId],
|
|
permission: DatasetPermission.partialMembers,
|
|
}
|
|
expect(hasEditPermissionForDataset(userId, config)).toBe(true)
|
|
})
|
|
|
|
it('returns false when permission is partialMembers and user is not in list', () => {
|
|
const config = {
|
|
createdBy: creatorId,
|
|
partialMemberList: [otherUserId],
|
|
permission: DatasetPermission.partialMembers,
|
|
}
|
|
expect(hasEditPermissionForDataset(userId, config)).toBe(false)
|
|
})
|
|
|
|
it('returns false when permission is partialMembers with empty list', () => {
|
|
const config = {
|
|
createdBy: creatorId,
|
|
partialMemberList: [],
|
|
permission: DatasetPermission.partialMembers,
|
|
}
|
|
expect(hasEditPermissionForDataset(userId, config)).toBe(false)
|
|
})
|
|
|
|
it('creator is not automatically granted access with partialMembers permission', () => {
|
|
const config = {
|
|
createdBy: creatorId,
|
|
partialMemberList: [userId],
|
|
permission: DatasetPermission.partialMembers,
|
|
}
|
|
expect(hasEditPermissionForDataset(creatorId, config)).toBe(false)
|
|
})
|
|
|
|
it('creator has access when included in partialMemberList', () => {
|
|
const config = {
|
|
createdBy: creatorId,
|
|
partialMemberList: [creatorId, userId],
|
|
permission: DatasetPermission.partialMembers,
|
|
}
|
|
expect(hasEditPermissionForDataset(creatorId, config)).toBe(true)
|
|
})
|
|
})
|
|
})
|