Files
baserow/web-frontend/test/unit/core/plugins/userSourceClientHandler.spec.js
Peter Evans 864c6d6f51 feat: let visitors report abuse on published applications (#6715)
* feat: let visitors report abuse on published applications

* fix: let logged-in app users report published applications
2026-11-18 09:00:31 +00:00

42 lines
1.5 KiB
JavaScript

import { prepareUserSourceRequestHeaders } from '@baserow/modules/core/plugins/userSourceClientHandler'
function createStore({ baserowUserAuthenticated = false } = {}) {
const application = { id: 1 }
return {
getters: {
'userSourceUser/getCurrentApplication': application,
'userSourceUser/isAuthenticated': () => true,
'userSourceUser/isRefreshing': () => false,
'userSourceUser/accessToken': () => 'app-user-token',
'auth/isAuthenticated': baserowUserAuthenticated,
},
}
}
describe('prepareUserSourceRequestHeaders', () => {
test('sends the user source token of a logged in visitor', () => {
const config = prepareUserSourceRequestHeaders(createStore())({})
expect(config.headers.Authorization).toBe('JWT app-user-token')
expect(config.usesUserSourceAuthorization).toBe(true)
})
test('sends no user source token when the request opts out', () => {
const config = prepareUserSourceRequestHeaders(createStore())({
skipUserSourceAuthorization: true,
})
expect(config.headers?.Authorization).toBeUndefined()
expect(config.headers?.UserSourceAuthorization).toBeUndefined()
expect(config.usesUserSourceAuthorization).toBeUndefined()
})
test('sends no user source header next to a Baserow user when opting out', () => {
const config = prepareUserSourceRequestHeaders(
createStore({ baserowUserAuthenticated: true })
)({ skipUserSourceAuthorization: true })
expect(config.headers?.UserSourceAuthorization).toBeUndefined()
})
})