|
1 | 1 | import pick from 'lodash/pick'; |
2 | 2 | import channel from '../index'; |
3 | 3 | import { |
| 4 | + Bookmark, |
4 | 5 | Channel, |
5 | 6 | Invitation, |
6 | 7 | ChannelUser, |
@@ -55,7 +56,7 @@ describe('channel actions', () => { |
55 | 56 | .spyOn(Channel, 'where') |
56 | 57 | .mockImplementation(() => Promise.resolve([channelDatum])); |
57 | 58 | return store.dispatch('channel/loadChannelList').then(() => { |
58 | | - expect(store.getters['channel/channels']).toEqual([channelDatum]); |
| 59 | + expect(store.getters['channel/channels']).toEqual([{ ...channelDatum, bookmark: false }]); |
59 | 60 | whereSpy.mockRestore(); |
60 | 61 | }); |
61 | 62 | }); |
@@ -85,7 +86,7 @@ describe('channel actions', () => { |
85 | 86 | .spyOn(Channel, 'get') |
86 | 87 | .mockImplementation(() => Promise.resolve(channelDatum)); |
87 | 88 | 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 }]); |
89 | 90 | getSpy.mockRestore(); |
90 | 91 | }); |
91 | 92 | }); |
@@ -177,22 +178,30 @@ describe('channel actions', () => { |
177 | 178 | }); |
178 | 179 | }); |
179 | 180 | 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'); |
182 | 183 | store.commit('channel/ADD_CHANNEL', { |
183 | 184 | id, |
184 | 185 | name: 'test', |
185 | | - bookmark: false, |
186 | 186 | }); |
187 | 187 | 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); |
189 | 199 | }); |
190 | 200 | }); |
191 | 201 | it('should set the channel as bookmarked in vuex state', () => { |
192 | 202 | store.commit('channel/ADD_CHANNEL', { |
193 | 203 | id, |
194 | 204 | name: 'test', |
195 | | - bookmark: false, |
196 | 205 | }); |
197 | 206 | return store.dispatch('channel/bookmarkChannel', { id, bookmark: true }).then(() => { |
198 | 207 | expect(store.getters['channel/getChannel'](id).bookmark).toBe(true); |
|
0 commit comments