1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-23 22:36:32 +02:00
Files
joplin/packages/lib/file-api.test.ts

98 lines
1.7 KiB
TypeScript

import { PaginatedList, RemoteItem, getSupportsDeltaWithItems, isLocalServer } from './file-api';
const defaultPaginatedList = (): PaginatedList => {
return {
items: [],
hasMore: false,
context: null,
};
};
const defaultItem = (): RemoteItem => {
return {
id: '',
};
};
describe('file-api', () => {
test.each([
[
{
...defaultPaginatedList(),
items: [],
},
false,
],
[
{
...defaultPaginatedList(),
items: [
{
...defaultItem(),
path: 'test',
},
],
},
false,
],
[
{
...defaultPaginatedList(),
items: [
{
...defaultItem(),
path: 'test',
jopItem: null,
},
],
},
true,
],
[
{
...defaultPaginatedList(),
items: [
{
...defaultItem(),
path: 'test',
jopItem: { something: 'abcd' },
},
],
},
true,
],
])('should tell if the sync target supports delta with items', async (deltaResponse: PaginatedList, expected: boolean) => {
const actual = getSupportsDeltaWithItems(deltaResponse);
expect(actual).toBe(expected);
});
it.each([
'http://localhost',
'http://localhost/',
'https://localhost:8080',
'http://127.0.0.1',
'https://127.100.50.25:3000/test',
'http://[::1]',
'http://localhost/api/v1',
])('should detect a local server url', (url: string) => {
const result = isLocalServer(url);
expect(result).toBe(true);
});
it.each([
'http://localhostXYZ',
'http://127.0.0.1foobar',
'http://192.168.1.1',
'http://example.com',
'https://my-localhost.com',
])('should detect a non local server url', (url: string) => {
const result = isLocalServer(url);
expect(result).toBe(false);
});
});