Skip to content

Commit

Permalink
update FE unsubscribe flag shape to match BE
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Mar 11, 2024
1 parent a1ad5d7 commit d97e9b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/src/redux/shell/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface NotifyRefetchData {
statusCode: never
}

interface NotifyUnsubscribeData extends NotifyRefetchData {
interface NotifyUnsubscribeData {
unsubscribe: boolean
}

Expand Down
17 changes: 17 additions & 0 deletions app/src/resources/__tests__/useNotifyService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,21 @@ describe('useNotifyService', () => {
rerender()
expect(mockHTTPRefetch).toHaveBeenCalledWith('once')
})

it('should trigger a single HTTP refetch if the unsubscribe flag was returned', () => {
vi.mocked(appShellListener).mockImplementation(
(_: any, __: any, mockCb: any) => {
mockCb({ unsubscribe: true })
}
)
const { rerender } = renderHook(() =>
useNotifyService({
topic: MOCK_TOPIC,
setRefetchUsingHTTP: mockHTTPRefetch,
options: MOCK_OPTIONS,
} as any)
)
rerender()
expect(mockHTTPRefetch).toHaveBeenCalledWith('once')
})
})
2 changes: 1 addition & 1 deletion app/src/resources/useNotifyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function useNotifyService<TData, TError = Error>({
properties: {},
})
}
} else if ('refetchUsingHTTP' in data) {
} else if ('refetchUsingHTTP' in data || 'unsubscribe' in data) {
setRefetchUsingHTTP('once')
}
}
Expand Down

0 comments on commit d97e9b7

Please sign in to comment.