Skip to content

Commit a1e3720

Browse files
committed
fix: code-review
1 parent 72e45eb commit a1e3720

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/containers/Tenant/ObjectSummary/__test__/transformPath.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {transformPath} from '../transformPath';
1+
import {EPathType} from '../../../../types/api/schema';
2+
import {isDomain, transformPath} from '../transformPath';
23

34
describe('transformPath', () => {
45
test.each([
@@ -41,3 +42,32 @@ describe('transformPath', () => {
4142
expect(transformPath('///dev/v1/sth', '/dev')).toBe('v1/sth');
4243
});
4344
});
45+
46+
describe('isDomain', () => {
47+
it('should return true for valid domain paths', () => {
48+
expect(isDomain('/domain', EPathType.EPathTypeDir)).toBe(true);
49+
expect(isDomain('/another-domain', EPathType.EPathTypeDir)).toBe(true);
50+
});
51+
52+
it('should return false for non-directory paths', () => {
53+
expect(isDomain('/domain', EPathType.EPathTypeColumnStore)).toBe(false);
54+
expect(isDomain('/domain', undefined)).toBe(false);
55+
});
56+
57+
it('should return false for paths without slash', () => {
58+
expect(isDomain('domain', EPathType.EPathTypeDir)).toBe(false);
59+
});
60+
61+
it('should return false for paths with multiple slashes', () => {
62+
expect(isDomain('/domain/subdomain', EPathType.EPathTypeDir)).toBe(false);
63+
expect(isDomain('/domain/', EPathType.EPathTypeDir)).toBe(false);
64+
});
65+
66+
it('should return false for empty paths', () => {
67+
expect(isDomain('', EPathType.EPathTypeDir)).toBe(false);
68+
});
69+
70+
it('should return true for root path', () => {
71+
expect(isDomain('/', EPathType.EPathTypeDir)).toBe(true);
72+
});
73+
});

src/containers/Tenant/ObjectSummary/transformPath.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,5 @@ export function isDomain(path: string, type?: EPathType) {
2424
if (type !== EPathType.EPathTypeDir) {
2525
return false;
2626
}
27-
let count = 0;
28-
for (let i = 0; i <= path.length; i++) {
29-
if (path[i] === '/') {
30-
count++;
31-
}
32-
if (count > 1) {
33-
return false;
34-
}
35-
}
36-
return count === 1;
27+
return path.split('/').length === 2 && path.startsWith('/');
3728
}

0 commit comments

Comments
 (0)