diff options
author | Devlin Junker <devlin.junker@gmail.com> | 2023-08-24 14:52:54 -0700 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2023-08-26 07:48:18 +0200 |
commit | 8183510385bad408ea3f0136bd4a5487ba7df526 (patch) | |
tree | f5cb61b97eb62f1cabb5ad506e47e8d982fc3d63 /tests/javascript/unit/services/item.service.spec.ts | |
parent | 3f34e3da33e4e20995f33f69ad8e6fed1a7bad72 (diff) |
More cleanup and started on unit tests
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests/javascript/unit/services/item.service.spec.ts')
-rw-r--r-- | tests/javascript/unit/services/item.service.spec.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/javascript/unit/services/item.service.spec.ts b/tests/javascript/unit/services/item.service.spec.ts new file mode 100644 index 000000000..29de8f1a3 --- /dev/null +++ b/tests/javascript/unit/services/item.service.spec.ts @@ -0,0 +1,66 @@ +import { ITEM_TYPES, ItemService } from '../../../../src/dataservices/item.service' +import axios from '@nextcloud/axios' + +jest.mock('@nextcloud/axios') + +describe('item.service.ts', () => { + 'use strict' + + beforeEach(() => { + (axios.get as any).mockReset(); + (axios.post as any).mockReset() + }) + + describe('fetchStarred', () => { + it('should call GET with offset set to start param', async () => { + (axios as any).get.mockResolvedValue({ data: { feeds: [] } }) + + await ItemService.fetchStarred(0) + + expect(axios.get).toBeCalled() + const queryParams = (axios.get as any).mock.calls[0][1].params + + expect(queryParams.offset).toEqual(0) + expect(queryParams.type).toEqual(ITEM_TYPES.STARRED) + }) + }) + + describe('fetchUnread', () => { + it('should call GET with offset set to start param', async () => { + (axios as any).get.mockResolvedValue({ data: { feeds: [] } }) + + await ItemService.fetchUnread(2) + + expect(axios.get).toBeCalled() + const queryParams = (axios.get as any).mock.calls[0][1].params + + expect(queryParams.offset).toEqual(2) + expect(queryParams.type).toEqual(ITEM_TYPES.UNREAD) + }) + }) + + describe('markRead', () => { + it('should call POST with item id in URL and read param', async () => { + await ItemService.markRead({ id: 123 } as any, true) + + expect(axios.post).toBeCalled() + const args = (axios.post as any).mock.calls[0] + + expect(args[0]).toContain('123') + expect(args[1].isRead).toEqual(true) + }) + }) + + describe('markStarred', () => { + it('should call POST with item feedId and guidHash in URL and read param', async () => { + await ItemService.markStarred({ feedId: 1, guidHash: 'abc' } as any, false) + + expect(axios.post).toBeCalled() + const args = (axios.post as any).mock.calls[0] + + expect(args[0]).toContain('1') + expect(args[0]).toContain('abc') + expect(args[1].isStarred).toEqual(false) + }) + }) +}) |