eletrotupi / tcc/ api/tests/mocks/avatar.ts96b6b65fa3a441d97c317cf1c2ee53661ad5b664
584 B | 27 lines Raw
1
import { vi } from 'vitest'
2

3
// multer-s3 (and the S3 client) is replaced by this middleware in tests, so
4
// the avatar specs can stage the file the controller will read off req.file
5
let uploadedFile: unknown = null
6

7
export function setUploadedFile(file: unknown) {
8
  uploadedFile = file
9
}
10

11
export function resetAvatarMock() {
12
  uploadedFile = null
13

14
  avatarMulterMock.single.mockClear()
15
}
16

17
export const avatarMulterMock = {
18
  single: vi.fn(
19
    () => (req: any, _res: any, next: any) => {
20
      if (uploadedFile) {
21
        req.file = uploadedFile
22
      }
23

24
      next()
25
    },
26
  ),
27
}