Skip to content

Commit

Permalink
Merge branch 'stage' into CP-2074
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarski committed Sep 27, 2023
2 parents 36dab17 + 7c1656c commit 725aabc
Show file tree
Hide file tree
Showing 25 changed files with 214 additions and 248 deletions.
2 changes: 1 addition & 1 deletion packages/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mudita/mudita-center-app",
"version": "2.0.2",
"version": "2.2.1",
"description": "Mudita Center",
"main": "./dist/main.js",
"productName": "Mudita Center",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,6 @@
"module.templates.emptyTemplate": "Empty template",
"module.templates.modalTitle": "Use Template",
"module.templates.newButton": "New template",
"module.templates.newLine": "The template contains new line character",
"module.templates.newTemplate": "new",
"module.templates.newTitle": "New template",
"module.templates.orderError": "Reordering was not successful",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export interface Thread {
threadID: number
}

export interface Template {
export interface PureTemplate {
templateID: number
lastUsedAt: number
templateBody: string
Expand Down Expand Up @@ -380,7 +380,7 @@ export interface GetTemplatesRequestConfig
}

export interface GetTemplatesResponseBody {
entries: Template[]
entries: PureTemplate[]
totalCount: number
nextPage?: PaginationBody
}
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/feature-flags/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import { EnvironmentConfig } from "App/feature-flags/types"
import { Feature, Environment } from "App/feature-flags/constants"

const muditaCenterPrereleaseEnabled = process.env.MUDITA_CENTER_PRERELEASE_ENABLED === "1"
const muditaCenterPrereleaseEnabled =
process.env.MUDITA_CENTER_PRERELEASE_ENABLED === "1"
const loggerEnabled = process.env.DEV_DEVICE_LOGGER_ENABLED !== "0"

export const features: EnvironmentConfig = {
Expand Down Expand Up @@ -127,7 +128,7 @@ export const features: EnvironmentConfig = {
},
[Feature.OrderTemplate]: {
[Environment.Development]: true,
[Environment.Production]: false,
[Environment.Production]: true,
[Environment.AlphaProduction]: true,
},
[Feature.AlphaRelaseWarning]: {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/files-manager/actions/get-files.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createAsyncThunk } from "@reduxjs/toolkit"
import {
FilesManagerEvent,
DeviceDirectory,
EligibleFormat,
eligibleFormat,
} from "App/files-manager/constants"
import { getFilesRequest } from "App/files-manager/requests/get-files.request"
import { File } from "App/files-manager/dto"
Expand All @@ -17,7 +17,7 @@ export const getFiles = createAsyncThunk<File[], DeviceDirectory>(
async (payload, { rejectWithValue }) => {
const result = await getFilesRequest({
directory: payload,
filter: { extensions: Object.values(EligibleFormat) },
filter: { extensions: eligibleFormat },
})

if (!result.ok || !result.data) {
Expand Down
146 changes: 43 additions & 103 deletions packages/app/src/files-manager/actions/upload-file.action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import { Result, SuccessResult } from "App/core/builder"
import { AppError } from "App/core/errors"
import { pendingAction } from "App/__deprecated__/renderer/store/helpers"
import { testError } from "App/__deprecated__/renderer/store/constants"
import { getPathsRequest } from "App/file-system/requests"
import { uploadFilesRequest } from "App/files-manager/requests"
import { EligibleFormat } from "App/files-manager/constants/eligible-format.constant"
import { DeviceDirectory } from "App/files-manager/constants/device-directory.constant"
import { GetPathsInput } from "App/file-system/dto"
import { uploadFile } from "App/files-manager/actions/upload-file.action"
import {
setUploadBlocked,
Expand Down Expand Up @@ -44,8 +41,6 @@ jest.mock("App/device/actions/load-storage-info.action", () => ({

const pathsMock = ["/path/file-1.mp3", "/path/file-2.wav"]
const errorMock = new AppError("SOME_ERROR_TYPE", "Luke, I'm your error")
const successGetPathResponse = new SuccessResult<string[]>(pathsMock)
const failedGetPathResponse = Result.failed(errorMock)
const successUploadResponse = new SuccessResult<string[]>(pathsMock)
const failedUploadResponse = Result.failed(errorMock)
const initialStore = {
Expand All @@ -57,98 +52,73 @@ const initialStore = {
},
}

const getFilesPathsResponseMock: GetPathsInput = {
filters: [
{
name: "Audio",
extensions: Object.values(EligibleFormat),
},
],
properties: ["openFile", "multiSelections"],
}

describe("when `getPathRequest` request return Result.success with files list", () => {
describe("when `uploadFileRequest` request return Result.success with uploaded files list", () => {
beforeAll(() => {
;(getPathsRequest as jest.Mock).mockResolvedValue(successGetPathResponse)
;(uploadFilesRequest as jest.Mock).mockReturnValue(successUploadResponse)
;(getFiles as unknown as jest.Mock).mockReturnValue(GET_FILES_MOCK_RESULT)
})

afterEach(() => {
jest.resetAllMocks()
})
describe("when `uploadFileRequest` request return Result.success with uploaded files list", () => {
beforeAll(() => {
;(uploadFilesRequest as jest.Mock).mockReturnValue(successUploadResponse)
;(getFiles as unknown as jest.Mock).mockReturnValue(GET_FILES_MOCK_RESULT)
})

test("dispatch `setUploadingState` with `State.Loaded` and `getFiles` with provided directory", async () => {
const mockStore = createMockStore([thunk])(initialStore)
afterEach(() => {
jest.resetAllMocks()
})

const {
meta: { requestId },
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/await-thenable
} = await mockStore.dispatch(uploadFile() as unknown as AnyAction)
test("dispatch `setUploadingState` with `State.Loaded` and `getFiles` with provided directory", async () => {
const mockStore = createMockStore([thunk])(initialStore)

expect(mockStore.getActions()).toEqual([
uploadFile.pending(requestId),
setUploadBlocked(true),
setUploadingFileCount(2),
setUploadingState(State.Loading),
setUploadBlocked(false),
GET_FILES_MOCK_RESULT,
{
type: pendingAction("DEVICE_LOAD_STORAGE_INFO"),
payload: undefined,
},
const {
meta: { requestId },
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/await-thenable
} = await mockStore.dispatch(uploadFile(pathsMock) as unknown as AnyAction)

setUploadingState(State.Loaded),
uploadFile.fulfilled(undefined, requestId),
])
expect(mockStore.getActions()).toEqual([
uploadFile.pending(requestId, pathsMock),
setUploadBlocked(true),
setUploadingFileCount(2),
setUploadingState(State.Loading),
GET_FILES_MOCK_RESULT,
{
type: pendingAction("DEVICE_LOAD_STORAGE_INFO"),
payload: undefined,
},
setUploadingState(State.Loaded),
setUploadBlocked(false),
uploadFile.fulfilled(undefined, requestId, pathsMock),
])

expect(getPathsRequest).toHaveBeenLastCalledWith(
getFilesPathsResponseMock
)
expect(uploadFilesRequest).toHaveBeenLastCalledWith({
directory: DeviceDirectory.Music,
filePaths: pathsMock,
})
expect(uploadFilesRequest).toHaveBeenLastCalledWith({
directory: DeviceDirectory.Music,
filePaths: pathsMock,
})
})

describe("when `uploadFileRequest` request return Result.success with empty files list", () => {
beforeAll(() => {
;(getPathsRequest as jest.Mock).mockResolvedValue(Result.success([]))
})

afterEach(() => {
jest.resetAllMocks()
})

test("any action is dispatch", async () => {
test("Action is dispatched with empty array as a argument", async () => {
const mockStore = createMockStore([thunk])(initialStore)

const {
meta: { requestId },
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/await-thenable
} = await mockStore.dispatch(uploadFile() as unknown as AnyAction)
} = await mockStore.dispatch(uploadFile([]) as unknown as AnyAction)

expect(mockStore.getActions()).toEqual([
uploadFile.pending(requestId),
uploadFile.pending(requestId, []),
setUploadBlocked(true),
setUploadBlocked(false),
uploadFile.fulfilled(undefined, requestId),
uploadFile.rejected(null, requestId, [], "no files to upload"),
])

expect(getPathsRequest).toHaveBeenLastCalledWith(
getFilesPathsResponseMock
)
expect(uploadFilesRequest).not.toHaveBeenCalled()
})
})

describe("when `uploadFileRequest` request return Result.failed", () => {
beforeAll(() => {
;(getPathsRequest as jest.Mock).mockResolvedValue(successGetPathResponse)
beforeEach(() => {
;(uploadFilesRequest as jest.Mock).mockReturnValue(failedUploadResponse)
;(getFiles as unknown as jest.Mock).mockReturnValue(GET_FILES_MOCK_RESULT)
})
Expand All @@ -164,54 +134,24 @@ describe("when `getPathRequest` request return Result.success with files list",
meta: { requestId },
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/await-thenable
} = await mockStore.dispatch(uploadFile() as unknown as AnyAction)
} = await mockStore.dispatch(
uploadFile(pathsMock) as unknown as AnyAction
)

expect(mockStore.getActions()).toEqual([
uploadFile.pending(requestId),
uploadFile.pending(requestId, pathsMock),
setUploadBlocked(true),
setUploadingFileCount(2),
setUploadingState(State.Loading),
setUploadBlocked(false),
GET_FILES_MOCK_RESULT,
uploadFile.rejected(testError, requestId, undefined, { ...errorMock }),

uploadFile.rejected(testError, requestId, pathsMock, { ...errorMock }),
])

expect(getPathsRequest).toHaveBeenLastCalledWith(
getFilesPathsResponseMock
)
expect(uploadFilesRequest).toHaveBeenLastCalledWith({
directory: DeviceDirectory.Music,
filePaths: pathsMock,
})
})
})
})

describe("when `getPathRequest` request return Result.failed", () => {
beforeAll(() => {
;(getPathsRequest as jest.Mock).mockResolvedValue(failedGetPathResponse)
})

afterEach(() => {
jest.resetAllMocks()
})

test("failed with receive from `uploadFileRequest` error", async () => {
const mockStore = createMockStore([thunk])(initialStore)

const {
meta: { requestId },
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/await-thenable
} = await mockStore.dispatch(uploadFile() as unknown as AnyAction)

expect(mockStore.getActions()).toEqual([
uploadFile.pending(requestId),
setUploadBlocked(true),
uploadFile.rejected(testError, requestId, undefined, { ...errorMock }),
])

expect(getPathsRequest).toHaveBeenLastCalledWith(getFilesPathsResponseMock)
expect(uploadFilesRequest).not.toHaveBeenCalled()
})
})
27 changes: 5 additions & 22 deletions packages/app/src/files-manager/actions/upload-file.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import { State } from "App/core/constants/state.constant"
import { ReduxRootState } from "App/__deprecated__/renderer/store"
import {
FilesManagerEvent,
EligibleFormat,
DeviceDirectory,
FilesManagerError,
} from "App/files-manager/constants"
import { getPathsRequest } from "App/file-system/requests"
import { uploadFilesRequest } from "App/files-manager/requests"
import { getFiles } from "App/files-manager/actions/get-files.action"
import {
Expand All @@ -32,21 +30,12 @@ import { checkFilesExtensions } from "../helpers/check-files-extensions.helper"

export const uploadFile = createAsyncThunk<
void,
void,
string[],
{ state: ReduxRootState }
>(
FilesManagerEvent.UploadFiles,
async (_, { getState, dispatch, rejectWithValue }) => {
async (filePaths, { getState, dispatch, rejectWithValue }) => {
dispatch(setUploadBlocked(true))
const filesToUpload = await getPathsRequest({
filters: [
{
name: "Audio",
extensions: Object.values(EligibleFormat),
},
],
properties: ["openFile", "multiSelections"],
})

const state = getState()

Expand All @@ -58,15 +47,9 @@ export const uploadFile = createAsyncThunk<
return rejectWithValue("files are not yet loaded")
}

if (!filesToUpload.ok || !filesToUpload.data) {
return rejectWithValue(filesToUpload.error)
}

const filePaths = filesToUpload.data ?? []

if (filePaths.length === 0) {
if (!filePaths || !filePaths.length) {
dispatch(setUploadBlocked(false))
return
return rejectWithValue("no files to upload")
}

const allFilesSupported = checkFilesExtensions(filePaths)
Expand Down Expand Up @@ -125,7 +108,6 @@ export const uploadFile = createAsyncThunk<

dispatch(setUploadingFileCount(filePaths.length))
dispatch(setUploadingState(State.Loading))
dispatch(setUploadBlocked(false))

const directory =
state.device.deviceType === DeviceType.MuditaHarmony
Expand All @@ -145,6 +127,7 @@ export const uploadFile = createAsyncThunk<

void dispatch(loadStorageInfoAction())
dispatch(setUploadingState(State.Loaded))
dispatch(setUploadBlocked(false))

return
}
Expand Down
Loading

0 comments on commit 725aabc

Please sign in to comment.