Skip to content

Commit

Permalink
review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarMichalkiewicz committed Sep 22, 2023
1 parent f0eedf9 commit 3e69085
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const uploadFile = createAsyncThunk<
return rejectWithValue("no files to upload")
}

const [validFiles, invalidFiles] = checkFilesExtensions(filePaths)
const { validFiles, invalidFiles } = checkFilesExtensions(filePaths)

if (!validFiles.length && invalidFiles.length) {
dispatch(setUploadBlocked(false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ const supportedFiles = eligibleFormat.map((extension) => `file.${extension}`)

describe("`checkFilesExtensions` helper", () => {
test("all correct extensions", () => {
expect(checkFilesExtensions(supportedFiles)).toBeTruthy()
expect(checkFilesExtensions(supportedFiles)).toEqual({
validFiles: supportedFiles,
invalidFiles: [],
})
})

test("empty files array", () => {
expect(checkFilesExtensions([])).toBeTruthy()
expect(checkFilesExtensions([])).toEqual({
validFiles: [],
invalidFiles: [],
})
})

test("at least one unsupported extension", () => {
const unsupportedFiles = ["file.unsupported"]
const allFiles = [...supportedFiles, ...unsupportedFiles]
expect(checkFilesExtensions(allFiles)).toEqual([
supportedFiles,
unsupportedFiles,
])
expect(checkFilesExtensions(allFiles)).toEqual({
validFiles: supportedFiles,
invalidFiles: unsupportedFiles,
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@

import { eligibleFormat } from "App/files-manager/constants/eligible-format.constant"

export const checkFilesExtensions = (
filesPaths: string[]
): [string[], string[]] => {
const validFiles = filesPaths.filter((filePath) => {
return eligibleFormat.includes(
(filePath.split(".").pop() ?? "").toLocaleLowerCase()
)
})
const invalidFiles = filesPaths.filter((filePath) => {
return !eligibleFormat.includes(
(filePath.split(".").pop() ?? "").toLocaleLowerCase()
)
})
export const checkFilesExtensions = (filesPaths: string[]) => {
const isPathEligible = (path: string) =>
eligibleFormat.includes((path.split(".").pop() ?? "").toLocaleLowerCase())
const validFiles = filesPaths.filter((filePath) => isPathEligible(filePath))
const invalidFiles = filesPaths.filter(
(filePath) => !isPathEligible(filePath)
)

return [validFiles, invalidFiles]
return { validFiles, invalidFiles }
}

0 comments on commit 3e69085

Please sign in to comment.