mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
import { describe, expect, test, vi } from 'vitest'
|
|
|
|
import DataSourceService from '@baserow/modules/builder/services/dataSource'
|
|
|
|
describe('data source service', () => {
|
|
test('uses the preview-scoped endpoint when resolving preview record names', async () => {
|
|
const client = {
|
|
get: vi.fn().mockResolvedValue({ data: { 42: 'Ada' } }),
|
|
}
|
|
|
|
const recordNames = await DataSourceService(client).getRecordNames(
|
|
5,
|
|
[42],
|
|
'preview',
|
|
3
|
|
)
|
|
|
|
expect(client.get).toHaveBeenCalledWith(
|
|
'builder/preview/3/data-sources/5/record-names/',
|
|
{ params: { record_ids: '42' } }
|
|
)
|
|
expect(recordNames).toStrictEqual({ 42: 'Ada' })
|
|
})
|
|
|
|
test('uses the published endpoint when resolving public record names', async () => {
|
|
const client = {
|
|
get: vi.fn().mockResolvedValue({ data: { 42: 'Ada' } }),
|
|
}
|
|
|
|
const recordNames = await DataSourceService(client).getRecordNames(
|
|
5,
|
|
[42],
|
|
'public',
|
|
3
|
|
)
|
|
|
|
expect(client.get).toHaveBeenCalledWith(
|
|
'builder/domains/published/data-source/5/record-names/',
|
|
{ params: { record_ids: '42' } }
|
|
)
|
|
expect(recordNames).toStrictEqual({ 42: 'Ada' })
|
|
})
|
|
|
|
test('uses the generic endpoint while editing', async () => {
|
|
const client = {
|
|
get: vi.fn().mockResolvedValue({ data: { 42: 'Ada' } }),
|
|
}
|
|
|
|
const recordNames = await DataSourceService(client).getRecordNames(
|
|
5,
|
|
[42],
|
|
'editing',
|
|
3
|
|
)
|
|
|
|
expect(client.get).toHaveBeenCalledWith(
|
|
'builder/data-source/5/record-names/',
|
|
{ params: { record_ids: '42' } }
|
|
)
|
|
expect(recordNames).toStrictEqual({ 42: 'Ada' })
|
|
})
|
|
})
|