Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Duplicate Applet] Enhance Duplication (M2-7729) #1942

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ const renderReportServerHook = (message: string) => {
(verifyReportServer as jest.Mock).mockResolvedValue({
json: async () => ({ message }),
});
(useParams as jest.Mock).mockReturnValue({ appletId: 'testAppletId', ownerId: 'testOwnerId' });

return renderHook(() => useCheckReportServer({ url: mockUrl, publicKey: mockPublicKey }));
return renderHook(() =>
useCheckReportServer({
url: mockUrl,
publicKey: mockPublicKey,
appletId: 'testAppletId',
ownerId: 'testOwnerId',
}),
);
};

const renderDefaultValuesHook = (appletData = {}, params) => {
Expand Down Expand Up @@ -104,10 +110,14 @@ describe('useCheckReportServer', () => {
(setPasswordReportServer as jest.Mock).mockResolvedValue({
json: async () => ({ message: SUCCESS_MESSAGE }),
});
(useParams as jest.Mock).mockReturnValue({ appletId: 'testAppletId', ownerId: 'testOwnerId' });

const { result } = renderHook(() =>
useCheckReportServer({ url: mockUrl, publicKey: 'mockPublicKey' }),
useCheckReportServer({
url: mockUrl,
publicKey: 'mockPublicKey',
appletId: 'testAppletId',
ownerId: 'testOwnerId',
}),
);

let setPasswordResult;
Expand All @@ -131,10 +141,14 @@ describe('useCheckReportServer', () => {
(setPasswordReportServer as jest.Mock).mockResolvedValue({
json: async () => ({ message: 'OTHER_MESSAGE' }),
});
(useParams as jest.Mock).mockReturnValue({ appletId: 'testAppletId', ownerId: 'testOwnerId' });

const { result } = renderHook(() =>
useCheckReportServer({ url: mockUrl, publicKey: 'mockPublicKey' }),
useCheckReportServer({
url: mockUrl,
publicKey: 'mockPublicKey',
appletId: 'testAppletId',
ownerId: 'testOwnerId',
}),
);

let setPasswordResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import {
defaultValues as initialValues,
} from './ReportConfigSetting.const';

export const useCheckReportServer = ({ url, publicKey }: UseCheckReportServer) => {
const { appletId = '', ownerId = '' } = useParams();

export const useCheckReportServer = ({
url,
publicKey,
appletId,
ownerId,
}: UseCheckReportServer) => {
const onVerify = async () => {
const token = authStorage.getAccessToken();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useForm, useFormContext } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import { Box } from '@mui/material';
import { ObjectSchema } from 'yup';
import { useParams } from 'react-router-dom';

import {
postReportConfigApi,
Expand Down Expand Up @@ -180,9 +181,13 @@ export const ReportConfigSetting = ({ 'data-testid': dataTestid }: ReportConfigS
)
: null;

const { appletId = '', ownerId = '' } = useParams();

const { onVerify, onSetPassword } = useCheckReportServer({
url: reportServerUrl,
publicKey: reportPublicKey,
appletId,
ownerId,
});

const handleAddEmail = async (value: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export type VerifyReportServer = {
export type UseCheckReportServer = {
url: string;
publicKey: string;
appletId: string;
ownerId: string;
};

export type SetPasswordReportServer = {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Dashboard/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export const postSubjectInvitationApi = (
);

export const duplicateAppletApi = ({ appletId, options }: DuplicateApplet, signal?: AbortSignal) =>
authApiClient.post(
authApiClient.post<ResponseWithObject<Applet>>(
`/applets/${appletId}/duplicate`,
{ ...options },
{
Expand Down
1 change: 1 addition & 0 deletions src/modules/Dashboard/api/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export type DuplicateApplet = AppletId & {
options: {
encryption: Encryption;
displayName: string;
includeReportServer?: boolean;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import mockAxios from 'jest-mock-axios';

import { expectBanner } from 'shared/utils';
import { renderWithProviders } from 'shared/utils/renderWithProviders';
import { mockedApplet, mockedAppletData, mockedPassword } from 'shared/mock';
import { mockedApplet, mockedAppletData, mockedAppletId, mockedPassword } from 'shared/mock';
import * as encryptionFunctions from 'shared/utils/encryption';
import { mockGetRequestResponses } from 'shared/utils/axios-mocks';

import { DuplicatePopups } from './DuplicatePopups';

Expand Down Expand Up @@ -37,6 +38,7 @@ describe('DuplicatePopups', () => {
});

test('should show an error if the name already exists in database', async () => {
mockAxios.post.mockResolvedValueOnce({ data: { result: mockedAppletData } });
mockAxios.post.mockResolvedValueOnce({ data: { result: { name: 'name' } } });
mockAxios.post.mockResolvedValueOnce({ data: { result: { name: 'name (1)' } } });

Expand All @@ -53,6 +55,10 @@ describe('DuplicatePopups', () => {
});

test('should duplicate and open success modal', async () => {
mockGetRequestResponses({
[`/applets/${mockedAppletId}`]: { data: { result: mockedAppletData } },
});

mockAxios.post.mockResolvedValueOnce({ data: { result: { name: 'name' } } });
mockAxios.post.mockResolvedValueOnce({ data: { result: { name: 'name' } } });
mockAxios.post.mockResolvedValueOnce({ data: { result: mockedAppletData } });
Expand Down Expand Up @@ -102,6 +108,8 @@ describe('DuplicatePopups', () => {
});
});

// TODO Add test(s) for duplicating with report server configuration - https://mindlogger.atlassian.net/browse/M2-8037

// TODO uncomment after useasync changes
// test('should open error modal', async () => {
// mockAxios.post.mockRejectedValue(new Error('error'));
Expand Down
Loading
Loading