Merge pull request 'Adding user to list now only works online, and it never queued' (#4) from dev into main
This commit was merged in pull request #4.
This commit is contained in:
@@ -14,7 +14,6 @@ export type SyncOperationType =
|
|||||||
| 'createListItem'
|
| 'createListItem'
|
||||||
| 'updateListItem'
|
| 'updateListItem'
|
||||||
| 'setListItemCompleted'
|
| 'setListItemCompleted'
|
||||||
| 'addUserToList'
|
|
||||||
| 'removeUserFromList'
|
| 'removeUserFromList'
|
||||||
| 'deleteList'
|
| 'deleteList'
|
||||||
| 'deleteListItem'
|
| 'deleteListItem'
|
||||||
|
|||||||
@@ -319,4 +319,40 @@ describe('useListsStore', () => {
|
|||||||
expect(listsApiMocks.deleteListItemApi).toHaveBeenCalledWith('item-to-delete')
|
expect(listsApiMocks.deleteListItemApi).toHaveBeenCalledWith('item-to-delete')
|
||||||
expect(store.pendingCount).toBe(0)
|
expect(store.pendingCount).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('shares list with server when online without adding to sync queue', async () => {
|
||||||
|
listsApiMocks.addUserToListApi.mockResolvedValueOnce(undefined)
|
||||||
|
|
||||||
|
const store = useListsStore()
|
||||||
|
await store.addUserToList('list-1', 'friend@example.com')
|
||||||
|
|
||||||
|
expect(listsApiMocks.addUserToListApi).toHaveBeenCalledWith({
|
||||||
|
list_id: 'list-1',
|
||||||
|
email: 'friend@example.com',
|
||||||
|
})
|
||||||
|
expect(store.pendingCount).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('throws error when sharing list while offline without calling API or adding to sync queue', async () => {
|
||||||
|
Object.defineProperty(navigator, 'onLine', { value: false, configurable: true })
|
||||||
|
|
||||||
|
const store = useListsStore()
|
||||||
|
await expect(store.addUserToList('list-1', 'friend@example.com')).rejects.toThrow(
|
||||||
|
'Cannot share list while offline',
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(listsApiMocks.addUserToListApi).not.toHaveBeenCalled()
|
||||||
|
expect(store.pendingCount).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('propagates error when sharing list fails on server without adding to sync queue', async () => {
|
||||||
|
listsApiMocks.addUserToListApi.mockRejectedValueOnce(new Error('User not found'))
|
||||||
|
|
||||||
|
const store = useListsStore()
|
||||||
|
await expect(store.addUserToList('list-1', 'unknown@example.com')).rejects.toThrow(
|
||||||
|
'User not found',
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(store.pendingCount).toBe(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
+4
-11
@@ -145,13 +145,10 @@ export const useListsStore = defineStore('lists', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addUserToList(listId: string, email: string) {
|
async function addUserToList(listId: string, email: string) {
|
||||||
await enqueue({
|
if (typeof navigator !== 'undefined' && !navigator.onLine) {
|
||||||
type: 'addUserToList',
|
throw new Error('Cannot share list while offline')
|
||||||
payload: { list_id: listId, email },
|
}
|
||||||
localListId: listId,
|
await addUserToListApi({ list_id: listId, email })
|
||||||
})
|
|
||||||
await refresh()
|
|
||||||
void sync()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeUserFromList(listId: string, email: string) {
|
async function removeUserFromList(listId: string, email: string) {
|
||||||
@@ -290,10 +287,6 @@ export const useListsStore = defineStore('lists', () => {
|
|||||||
await db.listItems.update(entry.localListItemId, { pendingSync: false })
|
await db.listItems.update(entry.localListItemId, { pendingSync: false })
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'addUserToList': {
|
|
||||||
await addUserToListApi(entry.payload as { list_id: string; email: string })
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'removeUserFromList': {
|
case 'removeUserFromList': {
|
||||||
await removeUserFromListApi(entry.payload as { list_id: string; email: string })
|
await removeUserFromListApi(entry.payload as { list_id: string; email: string })
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user