Skip to content

Commit 3a7b806

Browse files
committed
Add tests
1 parent 8554dc3 commit 3a7b806

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

packages/twenty-server/src/engine/metadata-modules/remote-server/remote-table/distant-table/utils/__tests__/sort-distant-tables.spec.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RemoteTableStatus } from 'src/engine/metadata-modules/remote-server/remote-table/dtos/remote-table.dto';
2-
import { distantTablesSorter } from 'src/engine/metadata-modules/remote-server/remote-table/distant-table/utils/sort-distant-tables.util';
2+
import { sortDistantTables } from 'src/engine/metadata-modules/remote-server/remote-table/distant-table/utils/sort-distant-tables.util';
33

44
const table1 = {
55
status: RemoteTableStatus.SYNCED,
@@ -13,19 +13,19 @@ const table2 = {
1313

1414
describe('sortDistantTables', () => {
1515
it('should return -1 when first param status is SYNCED and second param status is NOT_SYNCED', () => {
16-
const result = distantTablesSorter(table1, table2);
16+
const result = sortDistantTables(table1, table2);
1717

1818
expect(result).toBe(-1);
1919
});
2020

2121
it('should return 1 when first param status is NOT_SYNCED and second param status is SYNCED', () => {
22-
const result = distantTablesSorter(table2, table1);
22+
const result = sortDistantTables(table2, table1);
2323

2424
expect(result).toBe(1);
2525
});
2626

2727
it('should return -1 when same status and first param name is smaller than second param name', () => {
28-
const result = distantTablesSorter(
28+
const result = sortDistantTables(
2929
{ ...table1, status: RemoteTableStatus.NOT_SYNCED },
3030
table2,
3131
);
@@ -34,11 +34,20 @@ describe('sortDistantTables', () => {
3434
});
3535

3636
it('should return 1 when same status and second param name is smaller than first param name', () => {
37-
const result = distantTablesSorter(table2, {
37+
const result = sortDistantTables(table2, {
3838
...table1,
3939
status: RemoteTableStatus.NOT_SYNCED,
4040
});
4141

4242
expect(result).toBe(1);
4343
});
44+
45+
it('should be case insensitive', () => {
46+
const result = sortDistantTables(
47+
{ ...table1, name: 'table1', status: RemoteTableStatus.NOT_SYNCED },
48+
{ ...table2, name: 'Table2' },
49+
);
50+
51+
expect(result).toBe(-1);
52+
});
4453
});

packages/twenty-server/src/engine/metadata-modules/remote-server/remote-table/distant-table/utils/sort-distant-tables.util.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { RemoteTableStatus } from 'src/engine/metadata-modules/remote-server/remote-table/dtos/remote-table.dto';
22

3-
export const sortDistantTables = (table1, table2) => {
3+
export const sortDistantTables = (
4+
table1: {
5+
status: RemoteTableStatus;
6+
name: string;
7+
},
8+
table2: {
9+
status: RemoteTableStatus;
10+
name: string;
11+
},
12+
) => {
413
if (
514
table1.status === RemoteTableStatus.SYNCED &&
615
table2.status === RemoteTableStatus.NOT_SYNCED
@@ -15,5 +24,5 @@ export const sortDistantTables = (table1, table2) => {
1524
return 1;
1625
}
1726

18-
return table1.name > table2.name ? 1 : -1;
27+
return table1.name.toUpperCase() > table2.name.toUpperCase() ? 1 : -1;
1928
};

0 commit comments

Comments
 (0)