Skip to content

Commit

Permalink
Fix unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
lookacat committed Jul 31, 2023
1 parent b078644 commit 4ee4a41
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
40 changes: 22 additions & 18 deletions packages/web-pkg/src/composables/sse/useServerSentEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,29 @@ export const useServerSentEvents = (options: ServerSentEventsOptions) => {
}
const setupSSE = async () => {
retryCounter.value++
await fetchEventSource(new URL(options.url, configurationManager.serverUrl).href, {
signal: ctrl.signal,
headers: {
Authorization: `Bearer ${accessToken.value}`,
'Accept-Language': unref(language).current,
'X-Request-ID': uuidV4()
},
async onopen(response) {
if (response.status === 401) {
ctrl.abort()
return
try {
await fetchEventSource(new URL(options.url, configurationManager.serverUrl).href, {
signal: ctrl.signal,
headers: {
Authorization: `Bearer ${accessToken.value}`,
'Accept-Language': unref(language).current,
'X-Request-ID': uuidV4()
},
async onopen(response) {
if (response.status === 401) {
ctrl.abort()
return
}
retryCounter.value = 0
await options.onOpen?.(response)
},
onmessage(msg) {
options.onMessage?.(msg)
}
retryCounter.value = 0
await options.onOpen?.(response)
},
onmessage(msg) {
options.onMessage?.(msg)
}
})
})
} catch (e) {
console.error(e)
}
}
setupSSE().then(() => {
setupServerSentEvents()
Expand Down
4 changes: 3 additions & 1 deletion packages/web-runtime/src/components/Topbar/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ export default {
}
onMounted(async () => {
await setupServerSentEvents()
if (setupServerSentEvents) {
await setupServerSentEvents()
}
fetchNotificationsTask.perform()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const selectors = {
notificationActions: '.oc-notifications-actions'
}

jest.mock('web-pkg/src/composables/sse/useServerSentEvents')

describe('Notification component', () => {
it('renders the notification bell and no notifications if there are none', () => {
const { wrapper } = getWrapper()
Expand Down Expand Up @@ -55,7 +57,7 @@ describe('Notification component', () => {
await wrapper.vm.fetchNotificationsTask.last
await wrapper.find(selectors.markAll).trigger('click')
expect(wrapper.find(selectors.notificationItem).exists()).toBeFalsy()
expect(mocks.$clientService.owncloudSdk.requests.ocs).toHaveBeenCalledTimes(2)
expect(mocks.$clientService.owncloudSdk.requests.ocs).toHaveBeenCalledTimes(3)
})
describe('avatar', () => {
it('loads based on the username', async () => {
Expand Down

0 comments on commit 4ee4a41

Please sign in to comment.