|
| 1 | +import FormData from 'form-data'; |
1 | 2 | import type { FastifyInstance } from 'fastify'; |
2 | 3 | import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'; |
3 | 4 | import { prisma } from '../src/db.js'; |
@@ -289,6 +290,45 @@ runIf('API integration', () => { |
289 | 290 | }); |
290 | 291 | expect(bad.statusCode).toBe(400); |
291 | 292 | }); |
| 293 | + |
| 294 | + it('drops code uploads with no explicit target into the owner Fast-Upload folder', async () => { |
| 295 | + const admin = await createUser({ email: 'fu@test.local', password: 'correct-horse-battery', role: 'ADMIN' }); |
| 296 | + const auth = await login(app, 'fu@test.local', 'correct-horse-battery'); |
| 297 | + |
| 298 | + // A code with no targetFolderId. |
| 299 | + const created = await app.inject({ |
| 300 | + method: 'POST', |
| 301 | + url: '/admin/quick-codes', |
| 302 | + headers: authHeaders(auth), |
| 303 | + payload: {}, |
| 304 | + }); |
| 305 | + expect(created.statusCode).toBe(201); |
| 306 | + const code = created.json().code.code as string; |
| 307 | + |
| 308 | + // Guest upload (no auth / no CSRF on the public quick route). |
| 309 | + const form = new FormData(); |
| 310 | + form.append('file', Buffer.from('dropped by code'), { filename: 'drop.txt', contentType: 'text/plain' }); |
| 311 | + const up = await app.inject({ |
| 312 | + method: 'POST', |
| 313 | + url: `/quick/${code}`, |
| 314 | + payload: form.getBuffer(), |
| 315 | + headers: form.getHeaders(), |
| 316 | + }); |
| 317 | + expect(up.statusCode).toBe(201); |
| 318 | + |
| 319 | + // The file landed in the owner's Fast-Upload folder. |
| 320 | + const fastFolder = await prisma.folder.findFirst({ |
| 321 | + where: { ownerId: admin.id, parentId: null, name: 'Fast-Upload' }, |
| 322 | + }); |
| 323 | + expect(fastFolder).not.toBeNull(); |
| 324 | + const listed = await app.inject({ |
| 325 | + method: 'GET', |
| 326 | + url: `/files?folderId=${fastFolder!.id}`, |
| 327 | + headers: authHeaders(auth), |
| 328 | + }); |
| 329 | + expect(listed.statusCode).toBe(200); |
| 330 | + expect(listed.json().files.map((f: { name: string }) => f.name)).toContain('drop.txt'); |
| 331 | + }); |
292 | 332 | }); |
293 | 333 |
|
294 | 334 | describe('share links', () => { |
|
0 commit comments