fix: use new list item routes
This commit is contained in:
@@ -119,7 +119,7 @@ describe('lists API', () => {
|
|||||||
await expect(createListApi({ name: 'x' })).rejects.toThrow('Failed')
|
await expect(createListApi({ name: 'x' })).rejects.toThrow('Failed')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('createListItemApi sends POST to /lists/item and returns the created item with its server id', async () => {
|
it('createListItemApi sends POST to /lists/items and returns the created item with its server id', async () => {
|
||||||
const mockItem = { id: 'item-1', list_id: '', title: 'Milk', is_completed: false }
|
const mockItem = { id: 'item-1', list_id: '', title: 'Milk', is_completed: false }
|
||||||
const fetchMock = vi.fn<typeof fetch>().mockResolvedValueOnce({
|
const fetchMock = vi.fn<typeof fetch>().mockResolvedValueOnce({
|
||||||
ok: true,
|
ok: true,
|
||||||
@@ -131,13 +131,13 @@ describe('lists API', () => {
|
|||||||
const result = await createListItemApi({ list_id: 'list-1', title: 'Milk' })
|
const result = await createListItemApi({ list_id: 'list-1', title: 'Milk' })
|
||||||
|
|
||||||
expect(fetchMock).toHaveBeenCalledWith(
|
expect(fetchMock).toHaveBeenCalledWith(
|
||||||
`${API_BASE_URL}/lists/item`,
|
`${API_BASE_URL}/lists/items`,
|
||||||
expect.objectContaining({ method: 'POST' }),
|
expect.objectContaining({ method: 'POST' }),
|
||||||
)
|
)
|
||||||
expect(result).toEqual(mockItem)
|
expect(result).toEqual(mockItem)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updateListItemApi sends PUT to /lists/item', async () => {
|
it('updateListItemApi sends PUT to /lists/items', async () => {
|
||||||
const fetchMock = vi.fn<typeof fetch>().mockResolvedValueOnce({
|
const fetchMock = vi.fn<typeof fetch>().mockResolvedValueOnce({
|
||||||
ok: true,
|
ok: true,
|
||||||
status: 204,
|
status: 204,
|
||||||
@@ -147,7 +147,7 @@ describe('lists API', () => {
|
|||||||
await updateListItemApi({ list_item_id: 'item-1', is_completed: true })
|
await updateListItemApi({ list_item_id: 'item-1', is_completed: true })
|
||||||
|
|
||||||
expect(fetchMock).toHaveBeenCalledWith(
|
expect(fetchMock).toHaveBeenCalledWith(
|
||||||
`${API_BASE_URL}/lists/item`,
|
`${API_BASE_URL}/lists/items`,
|
||||||
expect.objectContaining({ method: 'PUT' }),
|
expect.objectContaining({ method: 'PUT' }),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -206,7 +206,7 @@ describe('lists API', () => {
|
|||||||
await expect(deleteListApi('list-1')).rejects.toThrow('List not found')
|
await expect(deleteListApi('list-1')).rejects.toThrow('List not found')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('deleteListItemApi sends DELETE to /lists/item/{id}', async () => {
|
it('deleteListItemApi sends DELETE to /lists/items/{id}', async () => {
|
||||||
const fetchMock = vi.fn<typeof fetch>().mockResolvedValueOnce({
|
const fetchMock = vi.fn<typeof fetch>().mockResolvedValueOnce({
|
||||||
ok: true,
|
ok: true,
|
||||||
status: 204,
|
status: 204,
|
||||||
@@ -216,7 +216,7 @@ describe('lists API', () => {
|
|||||||
await deleteListItemApi('item-1')
|
await deleteListItemApi('item-1')
|
||||||
|
|
||||||
expect(fetchMock).toHaveBeenCalledWith(
|
expect(fetchMock).toHaveBeenCalledWith(
|
||||||
`${API_BASE_URL}/lists/item/item-1`,
|
`${API_BASE_URL}/lists/items/item-1`,
|
||||||
expect.objectContaining({ method: 'DELETE' }),
|
expect.objectContaining({ method: 'DELETE' }),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
+3
-3
@@ -36,7 +36,7 @@ export async function getListItemsApi(listId: string): Promise<ListItem[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createListItemApi(payload: CreateListItemPayload): Promise<ListItem> {
|
export async function createListItemApi(payload: CreateListItemPayload): Promise<ListItem> {
|
||||||
const response = await apiClient.post('/lists/item', payload)
|
const response = await apiClient.post('/lists/items', payload)
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(await extractErrorMessage(response, 'Failed to create list item'))
|
throw new Error(await extractErrorMessage(response, 'Failed to create list item'))
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ export async function createListItemApi(payload: CreateListItemPayload): Promise
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function updateListItemApi(payload: UpdateListItemPayload): Promise<void> {
|
export async function updateListItemApi(payload: UpdateListItemPayload): Promise<void> {
|
||||||
const response = await apiClient.put('/lists/item', payload)
|
const response = await apiClient.put('/lists/items', payload)
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(await extractErrorMessage(response, 'Failed to update list item'))
|
throw new Error(await extractErrorMessage(response, 'Failed to update list item'))
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ export async function deleteListApi(listId: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteListItemApi(itemId: string): Promise<void> {
|
export async function deleteListItemApi(itemId: string): Promise<void> {
|
||||||
const response = await apiClient.delete(`/lists/item/${itemId}`)
|
const response = await apiClient.delete(`/lists/items/${itemId}`)
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(await extractErrorMessage(response, 'Failed to delete list item'))
|
throw new Error(await extractErrorMessage(response, 'Failed to delete list item'))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user