mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-31 21:38:19 +03:00
Add test for servers helpers
This commit is contained in:
parent
7a9209af03
commit
645abea72a
1 changed files with 43 additions and 0 deletions
43
test/servers/helpers/index.test.ts
Normal file
43
test/servers/helpers/index.test.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import type { ServersMap } from '../../../src/servers/data';
|
||||
import { ensureUniqueIds } from '../../../src/servers/helpers';
|
||||
|
||||
describe('index', () => {
|
||||
describe('ensureUniqueIds', () => {
|
||||
const servers: ServersMap = {
|
||||
'the-name-example.com': fromPartial({}),
|
||||
'another-name-example.com': fromPartial({}),
|
||||
'short-domain-s.test': fromPartial({}),
|
||||
};
|
||||
|
||||
it('returns expected list of servers when existing IDs conflict', () => {
|
||||
const result = ensureUniqueIds(servers, [
|
||||
fromPartial({ name: 'The name', url: 'https://example.com' }),
|
||||
fromPartial({ name: 'Short domain', url: 'https://s.test' }),
|
||||
fromPartial({ name: 'The name', url: 'https://example.com' }),
|
||||
]);
|
||||
|
||||
expect(result).toEqual([
|
||||
expect.objectContaining({ id: 'the-name-example.com-1' }),
|
||||
expect.objectContaining({ id: 'short-domain-s.test-1' }),
|
||||
expect.objectContaining({ id: 'the-name-example.com-2' }),
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns expected list of servers when IDs conflict in provided list of servers', () => {
|
||||
const result = ensureUniqueIds(servers, [
|
||||
fromPartial({ name: 'Foo', url: 'https://example.com' }),
|
||||
fromPartial({ name: 'Bar', url: 'https://s.test' }),
|
||||
fromPartial({ name: 'Foo', url: 'https://example.com' }),
|
||||
fromPartial({ name: 'Baz', url: 'https://s.test' }),
|
||||
]);
|
||||
|
||||
expect(result).toEqual([
|
||||
expect.objectContaining({ id: 'foo-example.com' }),
|
||||
expect.objectContaining({ id: 'bar-s.test' }),
|
||||
expect.objectContaining({ id: 'foo-example.com-1' }),
|
||||
expect.objectContaining({ id: 'baz-s.test' }),
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue