🤡(app-impress) remove mock pad endpoints

The backend was updated to include the
pad endpoints.
The mock pad endpoints were removed
in favor of the real ones.
We adapted the types as well to match
the real ones.
This commit is contained in:
Anthony LC
2024-04-16 09:15:10 +02:00
committed by Anthony LC
parent 3e0739cd0a
commit db9c9ecfe3
11 changed files with 73 additions and 237 deletions

View File

@@ -2,55 +2,14 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query';
import { APIError, errorCauses, fetchAPI } from '@/api';
import { Pad, Role } from '../types';
import { Pad } from '../types';
export type PadParams = {
id: string;
};
export const getPad = async ({ id }: PadParams): Promise<Pad> => {
/**
* TODO: Remove this block when the API endpoint is ready
*/
return await new Promise((resolve) => {
const pad: Pad = {
id: '1',
name: 'My mocked pad',
created_at: '2021-10-01T00:00:00Z',
updated_at: '2021-10-01T00:00:00Z',
accesses: [
{
id: '1',
role: Role.MEMBER,
user: {
id: '1',
name: 'user1',
email: 'john@doe.com',
},
abilities: {
delete: true,
get: true,
patch: true,
put: true,
set_role_to: [Role.MEMBER, Role.ADMIN],
},
},
],
abilities: {
delete: true,
get: true,
manage_accesses: true,
patch: true,
put: true,
},
};
setTimeout(() => {
resolve(pad);
}, 500);
});
const response = await fetchAPI(`pads/${id}`);
const response = await fetchAPI(`documents/${id}`);
if (!response.ok) {
throw new APIError('Failed to get the pad', await errorCauses(response));

View File

@@ -17,7 +17,7 @@ export const PadEditor = ({ pad }: PadEditorProps) => {
<PadToolBox pad={pad} />
<Card className="m-b p-b" $css="margin-top:0;flex:1;" $overflow="auto">
<Text as="h2" $align="center">
{pad.name}
{pad.title}
</Text>
<BlockNoteEditor pad={pad} />
</Card>

View File

@@ -1,15 +1,13 @@
import { User } from '@/core/auth';
export interface Access {
id: string;
role: Role;
user: User;
team: string;
user: string;
abilities: {
delete: boolean;
get: boolean;
patch: boolean;
put: boolean;
destroy: boolean;
retrieve: boolean;
set_role_to: Role[];
update: boolean;
};
}
@@ -21,15 +19,14 @@ export enum Role {
export interface Pad {
id: string;
name: string;
title: string;
accesses: Access[];
created_at: string;
updated_at: string;
abilities: {
delete: boolean;
get: boolean;
destroy: boolean;
retrieve: boolean;
manage_accesses: boolean;
patch: boolean;
put: boolean;
update: boolean;
};
}

View File

@@ -5,14 +5,14 @@ import { KEY_LIST_PAD } from '@/features/pads';
type CreatePadResponse = {
id: string;
name: string;
title: string;
};
export const createPad = async (name: string): Promise<CreatePadResponse> => {
const response = await fetchAPI(`pads/`, {
export const createPad = async (title: string): Promise<CreatePadResponse> => {
const response = await fetchAPI(`documents/`, {
method: 'POST',
body: JSON.stringify({
name,
title,
}),
});

View File

@@ -22,11 +22,8 @@ describe('PanelPads', () => {
fetchMock.restore();
});
/**
* TODO: When the backend endpoint `pads` is ready, unskip this test
*/
it.skip('renders with no pad to display', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
it('renders with no pad to display', async () => {
fetchMock.mock(`/api/documents/?page=1&ordering=-created_at`, {
count: 0,
results: [],
});
@@ -42,11 +39,8 @@ describe('PanelPads', () => {
).toBeInTheDocument();
});
/**
* TODO: When the backend endpoint `pads` is ready, unskip this test
*/
it.skip('renders an empty pad', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
it('renders an empty pad', async () => {
fetchMock.mock(`/api/documents/?page=1&ordering=-created_at`, {
count: 1,
results: [
{
@@ -64,11 +58,8 @@ describe('PanelPads', () => {
expect(await screen.findByLabelText('Empty pads icon')).toBeInTheDocument();
});
/**
* TODO: When the backend endpoint `pads` is ready, unskip this test
*/
it.skip('renders a pad with only 1 member', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
it('renders a pad with only 1 member', async () => {
fetchMock.mock(`/api/documents/?page=1&ordering=-created_at`, {
count: 1,
results: [
{
@@ -91,11 +82,8 @@ describe('PanelPads', () => {
expect(await screen.findByLabelText('Empty pads icon')).toBeInTheDocument();
});
/**
* TODO: When the backend endpoint `pads` is ready, unskip this test
*/
it.skip('renders a non-empty pad', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
it('renders a non-empty pad', async () => {
fetchMock.mock(`/api/documents/?page=1&ordering=-created_at`, {
count: 1,
results: [
{
@@ -122,11 +110,8 @@ describe('PanelPads', () => {
expect(await screen.findByLabelText('Pads icon')).toBeInTheDocument();
});
/**
* TODO: When the backend endpoint `pads` is ready, unskip this test
*/
it.skip('renders the error', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
it('renders the error', async () => {
fetchMock.mock(`/api/documents/?page=1&ordering=-created_at`, {
status: 500,
});
@@ -142,7 +127,7 @@ describe('PanelPads', () => {
});
it('renders with pad panel open', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
fetchMock.mock(`/api/documents/?page=1&ordering=-created_at`, {
count: 1,
results: [],
});
@@ -157,7 +142,7 @@ describe('PanelPads', () => {
});
it('closes and opens the pad panel', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
fetchMock.mock(`/api/documents/?page=1&ordering=-created_at`, {
count: 1,
results: [],
});

View File

@@ -6,7 +6,7 @@ import {
} from '@tanstack/react-query';
import { APIError, APIList, errorCauses, fetchAPI } from '@/api';
import { Pad, Role } from '@/features/pads/pad';
import { Pad } from '@/features/pads/pad';
export enum PadsOrdering {
BY_CREATED_ON = 'created_at',
@@ -26,90 +26,11 @@ export const getPads = async ({
ordering,
page,
}: PadsAPIParams): Promise<PadsResponse> => {
/**
* TODO: Remove this block when the API endpoint is ready
*/
return await new Promise((resolve) => {
const pads: PadsResponse = {
count: 1,
next: null,
previous: null,
results: [
{
id: '1',
name: 'My mocked pad',
created_at: '2021-10-01T00:00:00Z',
updated_at: '2021-10-01T00:00:00Z',
accesses: [
{
id: '1',
role: Role.MEMBER,
user: {
id: '1',
name: 'user1',
email: 'john@doe.com',
},
abilities: {
delete: true,
get: true,
patch: true,
put: true,
set_role_to: [Role.MEMBER, Role.ADMIN],
},
},
],
abilities: {
delete: true,
get: true,
manage_accesses: true,
patch: true,
put: true,
},
},
{
id: '2',
name: 'My mocked pad number 2',
created_at: '2021-10-01T00:00:00Z',
updated_at: '2021-10-01T00:00:00Z',
accesses: [
{
id: '1',
role: Role.MEMBER,
user: {
id: '1',
name: 'user1',
email: 'john@doe.com',
},
abilities: {
delete: true,
get: true,
patch: true,
put: true,
set_role_to: [Role.MEMBER, Role.ADMIN],
},
},
],
abilities: {
delete: true,
get: true,
manage_accesses: true,
patch: true,
put: true,
},
},
],
};
setTimeout(() => {
resolve(pads);
}, 500);
});
const orderingQuery = ordering ? `&ordering=${ordering}` : '';
const response = await fetchAPI(`pads/?page=${page}${orderingQuery}`);
const response = await fetchAPI(`documents/?page=${page}${orderingQuery}`);
if (!response.ok) {
throw new APIError('Failed to get the teams', await errorCauses(response));
throw new APIError('Failed to get the pads', await errorCauses(response));
}
return response.json() as Promise<PadsResponse>;

View File

@@ -93,7 +93,7 @@ export const PadItem = ({ pad }: PadItemProps) => {
min-width: 14rem;
`}
>
{pad.name}
{pad.title}
</Text>
</Box>
</StyledLink>