summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDevlin Junker <devlin.junker@gmail.com>2023-08-31 18:36:20 -0700
committerBenjamin Brahmer <info@b-brahmer.de>2023-09-03 12:05:24 +0200
commite2e8ae517afcb57bd2e0d5e6d4aacbb96603bd96 (patch)
tree51baf1eb5cf06ab0f5dd809cfd064f97db5f60eb /tests
parent6111aca4af59ec167811ec594bf777d094c8fe2a (diff)
move backend call details to services
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/javascript/unit/components/routes/Feed.spec.ts2
-rw-r--r--tests/javascript/unit/components/routes/Starred.spec.ts2
-rw-r--r--tests/javascript/unit/components/routes/Unread.spec.ts2
-rw-r--r--tests/javascript/unit/services/feed.service.spec.ts34
-rw-r--r--tests/javascript/unit/services/folder.service.spec.ts45
-rw-r--r--tests/javascript/unit/store/feed.spec.ts25
-rw-r--r--tests/javascript/unit/store/folder.spec.ts26
-rw-r--r--tests/javascript/unit/store/item.spec.ts8
8 files changed, 112 insertions, 32 deletions
diff --git a/tests/javascript/unit/components/routes/Feed.spec.ts b/tests/javascript/unit/components/routes/Feed.spec.ts
index 4e0e69f2b..dca9a02e2 100644
--- a/tests/javascript/unit/components/routes/Feed.spec.ts
+++ b/tests/javascript/unit/components/routes/Feed.spec.ts
@@ -2,7 +2,7 @@ import Vuex, { Store } from 'vuex'
import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'
import Feed from '../../../../../src/components/routes/Feed.vue'
-import FeedItemDisplayList from '../../../../../src/components/FeedItemDisplayList.vue'
+import FeedItemDisplayList from '../../../../../src/components/feed-display/FeedItemDisplayList.vue'
jest.mock('@nextcloud/axios')
diff --git a/tests/javascript/unit/components/routes/Starred.spec.ts b/tests/javascript/unit/components/routes/Starred.spec.ts
index 44c9acd75..cf77cbef2 100644
--- a/tests/javascript/unit/components/routes/Starred.spec.ts
+++ b/tests/javascript/unit/components/routes/Starred.spec.ts
@@ -2,7 +2,7 @@ import Vuex, { Store } from 'vuex'
import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'
import Starred from '../../../../../src/components/routes/Starred.vue'
-import FeedItemDisplayList from '../../../../../src/components/FeedItemDisplayList.vue'
+import FeedItemDisplayList from '../../../../../src/components/feed-display/FeedItemDisplayList.vue'
jest.mock('@nextcloud/axios')
diff --git a/tests/javascript/unit/components/routes/Unread.spec.ts b/tests/javascript/unit/components/routes/Unread.spec.ts
index 149fc015f..78f741199 100644
--- a/tests/javascript/unit/components/routes/Unread.spec.ts
+++ b/tests/javascript/unit/components/routes/Unread.spec.ts
@@ -2,7 +2,7 @@ import Vuex, { Store } from 'vuex'
import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'
import Unread from '../../../../../src/components/routes/Unread.vue'
-import FeedItemDisplayList from '../../../../../src/components/FeedItemDisplayList.vue'
+import FeedItemDisplayList from '../../../../../src/components/feed-display/FeedItemDisplayList.vue'
jest.mock('@nextcloud/axios')
diff --git a/tests/javascript/unit/services/feed.service.spec.ts b/tests/javascript/unit/services/feed.service.spec.ts
new file mode 100644
index 000000000..5f0c058cd
--- /dev/null
+++ b/tests/javascript/unit/services/feed.service.spec.ts
@@ -0,0 +1,34 @@
+import { FeedService } from './../../../../src/dataservices/feed.service'
+import axios from '@nextcloud/axios'
+
+jest.mock('@nextcloud/axios')
+
+describe('feed.service.ts', () => {
+ 'use strict'
+
+ beforeEach(() => {
+ (axios.get as any).mockReset();
+ (axios.post as any).mockReset()
+ })
+
+ describe('fetchAllFeeds', () => {
+ it('should call GET to retrieve all feeds', async () => {
+ (axios as any).get.mockResolvedValue({ data: { feeds: [] } })
+
+ await FeedService.fetchAllFeeds()
+
+ expect(axios.get).toBeCalled()
+ })
+ })
+
+ describe('addFeed', () => {
+ it('should call POST with item id in URL and read param', async () => {
+ await FeedService.addFeed({ url: 'http://example.com', folderId: 0 })
+
+ expect(axios.post).toBeCalled()
+ const args = (axios.post as any).mock.calls[0]
+
+ expect(args[1].url).toEqual('http://example.com')
+ })
+ })
+})
diff --git a/tests/javascript/unit/services/folder.service.spec.ts b/tests/javascript/unit/services/folder.service.spec.ts
new file mode 100644
index 000000000..6577df2c8
--- /dev/null
+++ b/tests/javascript/unit/services/folder.service.spec.ts
@@ -0,0 +1,45 @@
+import { FolderService } from './../../../../src/dataservices/folder.service'
+import axios from '@nextcloud/axios'
+
+jest.mock('@nextcloud/axios')
+
+describe('folder.service.ts', () => {
+ 'use strict'
+
+ beforeEach(() => {
+ (axios.get as any).mockReset();
+ (axios.post as any).mockReset()
+ })
+
+ describe('fetchAllFolders', () => {
+ it('should call GET to retrieve all folders', async () => {
+ (axios as any).get.mockResolvedValue({ data: { feeds: [] } })
+
+ await FolderService.fetchAllFolders()
+
+ expect(axios.get).toBeCalled()
+ })
+ })
+
+ describe('createFolder', () => {
+ it('should call POST with item id in URL and read param', async () => {
+ await FolderService.createFolder({ name: 'abc' })
+
+ expect(axios.post).toBeCalled()
+ const args = (axios.post as any).mock.calls[0]
+
+ expect(args[1].folderName).toEqual('abc')
+ })
+ })
+
+ describe('deleteFolder', () => {
+ it('should call POST with item id in URL and read param', async () => {
+ await FolderService.deleteFolder({ id: 123 })
+
+ expect(axios.delete).toBeCalled()
+ const args = (axios.delete as any).mock.calls[0]
+
+ expect(args[0]).toContain('123')
+ })
+ })
+})
diff --git a/tests/javascript/unit/store/feed.spec.ts b/tests/javascript/unit/store/feed.spec.ts
index 3a7521f89..451d04d7a 100644
--- a/tests/javascript/unit/store/feed.spec.ts
+++ b/tests/javascript/unit/store/feed.spec.ts
@@ -1,41 +1,42 @@
-import axios from '@nextcloud/axios'
import { Feed } from '../../../../src/types/Feed'
import { AppState } from '../../../../src/store'
import { FEED_ACTION_TYPES, mutations, actions } from '../../../../src/store/feed'
+import { FeedService } from '../../../../src/dataservices/feed.service'
import { FEED_ITEM_MUTATION_TYPES, FEED_MUTATION_TYPES } from '../../../../src/types/MutationTypes'
-jest.mock('@nextcloud/axios')
-
describe('feed.ts', () => {
'use strict'
describe('actions', () => {
describe('FETCH_FEEDS', () => {
- it('should call GET and commit returned feeds to state', async () => {
- (axios as any).get.mockResolvedValue({ data: { feeds: [] } })
+ it('should call FeedService.fetchAllFeeds and commit returned feeds to state', async () => {
+ FeedService.fetchAllFeeds = jest.fn();
+ (FeedService.fetchAllFeeds as any).mockResolvedValue({ data: { feeds: [] } })
const commit = jest.fn()
await (actions[FEED_ACTION_TYPES.FETCH_FEEDS] as any)({ commit })
- expect(axios.get).toBeCalled()
+ expect(FeedService.fetchAllFeeds).toBeCalled()
expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.SET_FEEDS, [])
expect(commit).toBeCalledWith(FEED_ITEM_MUTATION_TYPES.SET_UNREAD_COUNT, 0)
})
})
describe('ADD_FEED', () => {
- it('should call POST and commit feed to state', async () => {
- (axios as any).post.mockResolvedValue({ data: { feeds: [] } })
+ it('should call FeedService.addF and commit feed to state', async () => {
+ FeedService.addFeed = jest.fn();
+ (FeedService.addFeed as any).mockResolvedValue({ data: { feeds: [] } })
const commit = jest.fn()
await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } })
- expect(axios.post).toBeCalled()
+ expect(FeedService.addFeed).toBeCalled()
expect(commit).toBeCalled()
})
- it('should call POST and not call commit if error', async () => {
- (axios as any).post.mockRejectedValue()
+ it('should call FeedService.addF and not call commit if error', async () => {
+ FeedService.addFeed = jest.fn();
+ (FeedService.addFeed as any).mockRejectedValue()
const commit = jest.fn()
await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } })
- expect(axios.post).toBeCalled()
+ expect(FeedService.addFeed).toBeCalled()
expect(commit).not.toBeCalled()
})
diff --git a/tests/javascript/unit/store/folder.spec.ts b/tests/javascript/unit/store/folder.spec.ts
index eacfd18cb..8fd2ad34f 100644
--- a/tests/javascript/unit/store/folder.spec.ts
+++ b/tests/javascript/unit/store/folder.spec.ts
@@ -1,47 +1,47 @@
-import axios from '@nextcloud/axios'
-import { generateUrl } from '@nextcloud/router'
import { Folder } from '../../../../src/types/Folder'
import { AppState } from '../../../../src/store'
import { FOLDER_ACTION_TYPES, mutations, actions } from '../../../../src/store/folder'
import { FOLDER_MUTATION_TYPES } from '../../../../src/types/MutationTypes'
+import { FolderService } from '../../../../src/dataservices/folder.service'
-jest.mock('@nextcloud/axios')
jest.mock('@nextcloud/router')
describe('folder.ts', () => {
'use strict'
describe('actions', () => {
- it('FETCH_FOLDERS should send GET and then commit folders returned to state', async () => {
- (generateUrl as any).mockReturnValue('');
- (axios.get as any).mockResolvedValue({ data: { folders: [] } })
+ it('FETCH_FOLDERS should call FolderService.fetchAllFolders and then commit folders returned to state', async () => {
+ FolderService.fetchAllFolders = jest.fn();
+ (FolderService.fetchAllFolders as any).mockResolvedValue({ data: { folders: [] } })
const commit = jest.fn()
await (actions[FOLDER_ACTION_TYPES.FETCH_FOLDERS] as any)({ commit })
- expect(axios.get).toBeCalled()
+ expect(FolderService.fetchAllFolders).toBeCalled()
expect(commit).toBeCalled()
})
- it('ADD_FOLDERS should send POST and then commit the folders returned to state', async () => {
- (axios.post as any).mockResolvedValue({ data: { folders: [] } })
+ it('ADD_FOLDERS should call FolderService.createFolder and then commit the folders returned to state', async () => {
+ FolderService.createFolder = jest.fn();
+ (FolderService.createFolder as any).mockResolvedValue({ data: { folders: [] } })
const folder = {} as Folder
const commit = jest.fn()
await actions[FOLDER_ACTION_TYPES.ADD_FOLDERS]({ commit }, { folder })
- expect(axios.post).toBeCalled()
+ expect(FolderService.createFolder).toBeCalled()
expect(commit).toBeCalled()
})
- it('DELETE_FOLDER should send DELETE and then commit deleted folder to state', async () => {
- (axios.delete as any).mockResolvedValue()
+ it('DELETE_FOLDER should call FolderService.deleteFolder and then commit deleted folder to state', async () => {
+ FolderService.deleteFolder = jest.fn();
+ (FolderService.deleteFolder as any).mockResolvedValue()
const folder = {} as Folder
const commit = jest.fn()
await actions[FOLDER_ACTION_TYPES.DELETE_FOLDER]({ commit }, { folder })
- expect(axios.delete).toBeCalled()
+ expect(FolderService.deleteFolder).toBeCalled()
expect(commit).toBeCalled()
})
})
diff --git a/tests/javascript/unit/store/item.spec.ts b/tests/javascript/unit/store/item.spec.ts
index 84869c4d8..7866cff5b 100644
--- a/tests/javascript/unit/store/item.spec.ts
+++ b/tests/javascript/unit/store/item.spec.ts
@@ -11,28 +11,28 @@ describe('item.ts', () => {
describe('FETCH_UNREAD', () => {
it('should call ItemService and commit items to state', async () => {
const fetchMock = jest.fn()
- fetchMock.mockResolvedValue({ data: { items: [] } })
+ fetchMock.mockResolvedValue({ data: { items: [{ id: 123 }] } })
ItemService.debounceFetchUnread = fetchMock as any
const commit = jest.fn()
await (actions[FEED_ITEM_ACTION_TYPES.FETCH_UNREAD] as any)({ commit })
expect(fetchMock).toBeCalled()
- expect(commit).toBeCalledWith(FEED_ITEM_MUTATION_TYPES.SET_ITEMS, [])
+ expect(commit).toBeCalledWith(FEED_ITEM_MUTATION_TYPES.SET_ITEMS, [{ id: 123 }])
})
})
describe('FETCH_STARRED', () => {
it('should call ItemService and commit items and starred count to state', async () => {
const fetchMock = jest.fn()
- fetchMock.mockResolvedValue({ data: { items: [], starred: 3 } })
+ fetchMock.mockResolvedValue({ data: { items: [{ id: 123 }], starred: 3 } })
ItemService.debounceFetchStarred = fetchMock as any
const commit = jest.fn()
await (actions[FEED_ITEM_ACTION_TYPES.FETCH_STARRED] as any)({ commit })
expect(fetchMock).toBeCalled()
- expect(commit).toBeCalledWith(FEED_ITEM_MUTATION_TYPES.SET_ITEMS, [])
+ expect(commit).toBeCalledWith(FEED_ITEM_MUTATION_TYPES.SET_ITEMS, [{ id: 123 }])
expect(commit).toBeCalledWith(FEED_ITEM_MUTATION_TYPES.SET_STARRED_COUNT, 3)
})
})