fix: List item UI improvements
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
||||
createListApi,
|
||||
getListItemsApi,
|
||||
createListItemApi,
|
||||
updateListItemApi,
|
||||
updateListItemTitleApi,
|
||||
setListItemCompletedApi,
|
||||
addUserToListApi,
|
||||
removeUserFromListApi,
|
||||
@@ -77,7 +77,7 @@ describe('lists API', () => {
|
||||
expect(result).toEqual(mockItems)
|
||||
})
|
||||
|
||||
it('setListItemCompletedApi sends POST to /lists/items/{id}', async () => {
|
||||
it('setListItemCompletedApi sends POST to /lists/items/{id}/complete', async () => {
|
||||
const fetchMock = vi.fn<typeof fetch>().mockResolvedValueOnce({
|
||||
ok: true,
|
||||
status: 204,
|
||||
@@ -87,7 +87,7 @@ describe('lists API', () => {
|
||||
await setListItemCompletedApi('item-1', { is_completed: true })
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
`${API_BASE_URL}/lists/items/item-1`,
|
||||
`${API_BASE_URL}/lists/items/item-1/complete`,
|
||||
expect.objectContaining({ method: 'POST' }),
|
||||
)
|
||||
})
|
||||
@@ -137,18 +137,18 @@ describe('lists API', () => {
|
||||
expect(result).toEqual(mockItem)
|
||||
})
|
||||
|
||||
it('updateListItemApi sends PUT to /lists/items', async () => {
|
||||
it('updateListItemTitleApi sends POST to /lists/items/{id}/title', async () => {
|
||||
const fetchMock = vi.fn<typeof fetch>().mockResolvedValueOnce({
|
||||
ok: true,
|
||||
status: 204,
|
||||
} as unknown as Response)
|
||||
global.fetch = fetchMock
|
||||
|
||||
await updateListItemApi({ list_item_id: 'item-1', is_completed: true })
|
||||
await updateListItemTitleApi('item-1', { title: 'Free-range eggs' })
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
`${API_BASE_URL}/lists/items`,
|
||||
expect.objectContaining({ method: 'PUT' }),
|
||||
`${API_BASE_URL}/lists/items/item-1/title`,
|
||||
expect.objectContaining({ method: 'POST' }),
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
+12
-9
@@ -5,8 +5,8 @@ import type {
|
||||
ListItem,
|
||||
CreateListPayload,
|
||||
CreateListItemPayload,
|
||||
UpdateListItemPayload,
|
||||
SetListItemCompletedPayload,
|
||||
SetListItemTitlePayload,
|
||||
AddUserToListPayload,
|
||||
RemoveUserFromListPayload,
|
||||
} from '@/types/list'
|
||||
@@ -43,23 +43,26 @@ export async function createListItemApi(payload: CreateListItemPayload): Promise
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function updateListItemApi(payload: UpdateListItemPayload): Promise<void> {
|
||||
const response = await apiClient.put('/lists/items', payload)
|
||||
if (!response.ok) {
|
||||
throw new Error(await extractErrorMessage(response, 'Failed to update list item'))
|
||||
}
|
||||
}
|
||||
|
||||
export async function setListItemCompletedApi(
|
||||
itemId: string,
|
||||
payload: SetListItemCompletedPayload,
|
||||
): Promise<void> {
|
||||
const response = await apiClient.post(`/lists/items/${itemId}`, payload)
|
||||
const response = await apiClient.post(`/lists/items/${itemId}/complete`, payload)
|
||||
if (!response.ok) {
|
||||
throw new Error(await extractErrorMessage(response, 'Failed to update list item status'))
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateListItemTitleApi(
|
||||
itemId: string,
|
||||
payload: SetListItemTitlePayload,
|
||||
): Promise<void> {
|
||||
const response = await apiClient.post(`/lists/items/${itemId}/title`, payload)
|
||||
if (!response.ok) {
|
||||
throw new Error(await extractErrorMessage(response, 'Failed to update list item title'))
|
||||
}
|
||||
}
|
||||
|
||||
export async function addUserToListApi(payload: AddUserToListPayload): Promise<void> {
|
||||
const response = await apiClient.post('/lists/user', payload)
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user