* Create a non-admin user whose policy grants the given directus_files * permissions, returning a static token to authenticate as them. Only the * fields that matter per test need to be passed; the rest are defaulted.
(permissions: Partial<Permission>[])
| 54 | * fields that matter per test need to be passed; the rest are defaulted. |
| 55 | */ |
| 56 | async function createFilesUser(permissions: Partial<Permission>[]) { |
| 57 | const token = randomUUID(); |
| 58 | |
| 59 | const user = await api.request<{ id: string }>( |
| 60 | createUser({ first_name: 'Test', last_name: 'Files', email: `${token}@files.com`, password: 'password', token }), |
| 61 | ); |
| 62 | |
| 63 | const policy = await api.request<{ id: string }>( |
| 64 | createPolicy({ |
| 65 | name: `files-${randomUUID()}`, |
| 66 | admin_access: false, |
| 67 | app_access: false, |
| 68 | users: [{ user: user.id }], |
| 69 | permissions: [], |
| 70 | }), |
| 71 | ); |
| 72 | |
| 73 | await api.request( |
| 74 | updatePolicy(policy.id, { |
| 75 | permissions: permissions.map((perm) => ({ collection: 'directus_files', fields: ['*'], ...perm })) as any, |
| 76 | }), |
| 77 | ); |
| 78 | |
| 79 | return token; |
| 80 | } |
| 81 | |
| 82 | async function findFileByDownloadName(filenameDownload: string) { |
| 83 | const [file] = await api.request<{ id: string }[]>( |
no test coverage detected