Skip to content

Commit 0593068

Browse files
committed
Fix JS tests.
1 parent a393a04 commit 0593068

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

contentcuration/contentcuration/frontend/shared/vuex/channel/__tests__/module.spec.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pick from 'lodash/pick';
22
import channel from '../index';
33
import {
4+
Bookmark,
45
Channel,
56
Invitation,
67
ChannelUser,
@@ -55,7 +56,7 @@ describe('channel actions', () => {
5556
.spyOn(Channel, 'where')
5657
.mockImplementation(() => Promise.resolve([channelDatum]));
5758
return store.dispatch('channel/loadChannelList').then(() => {
58-
expect(store.getters['channel/channels']).toEqual([channelDatum]);
59+
expect(store.getters['channel/channels']).toEqual([{ ...channelDatum, bookmark: false }]);
5960
whereSpy.mockRestore();
6061
});
6162
});
@@ -85,7 +86,7 @@ describe('channel actions', () => {
8586
.spyOn(Channel, 'get')
8687
.mockImplementation(() => Promise.resolve(channelDatum));
8788
return store.dispatch('channel/loadChannel', id).then(() => {
88-
expect(store.getters['channel/channels']).toEqual([channelDatum]);
89+
expect(store.getters['channel/channels']).toEqual([{ ...channelDatum, bookmark: false }]);
8990
getSpy.mockRestore();
9091
});
9192
});
@@ -177,22 +178,30 @@ describe('channel actions', () => {
177178
});
178179
});
179180
describe('bookmarkChannel action', () => {
180-
it('should call Channel.update', () => {
181-
const updateSpy = jest.spyOn(Channel, 'update');
181+
it('should call Bookmark.put when creating a bookmark', () => {
182+
const putSpy = jest.spyOn(Bookmark, 'put');
182183
store.commit('channel/ADD_CHANNEL', {
183184
id,
184185
name: 'test',
185-
bookmark: false,
186186
});
187187
return store.dispatch('channel/bookmarkChannel', { id, bookmark: true }).then(() => {
188-
expect(updateSpy).toHaveBeenCalledWith(id, { bookmark: true });
188+
expect(putSpy).toHaveBeenCalledWith({ channel: id });
189+
});
190+
});
191+
it('should call Bookmark.delete when removing a bookmark', () => {
192+
const deleteSpy = jest.spyOn(Bookmark, 'delete');
193+
store.commit('channel/ADD_CHANNEL', {
194+
id,
195+
name: 'test',
196+
});
197+
return store.dispatch('channel/bookmarkChannel', { id, bookmark: false }).then(() => {
198+
expect(deleteSpy).toHaveBeenCalledWith(id);
189199
});
190200
});
191201
it('should set the channel as bookmarked in vuex state', () => {
192202
store.commit('channel/ADD_CHANNEL', {
193203
id,
194204
name: 'test',
195-
bookmark: false,
196205
});
197206
return store.dispatch('channel/bookmarkChannel', { id, bookmark: true }).then(() => {
198207
expect(store.getters['channel/getChannel'](id).bookmark).toBe(true);

contentcuration/contentcuration/frontend/shared/vuex/channel/getters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { SharingPermissions } from 'shared/constants';
22

33
function mapChannel(state, channel) {
4-
return {
4+
return channel ? {
55
...channel,
66
bookmark: Boolean(state.bookmarksMap[channel.id]),
7-
};
7+
} : channel;
88
}
99

1010
export function channels(state) {

0 commit comments

Comments
 (0)