Skip to content

Commit c5b4f14

Browse files
committed
cleanup
1 parent 1ec4e54 commit c5b4f14

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

packages/compass-data-modeling/src/utils/schema-traversal.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ const getMutatedSchema = ({
194194
case 'renameField': {
195195
if (!schema.properties || !schema.properties[fieldName])
196196
throw new Error('Field to rename does not exist');
197+
if (!newFieldName)
198+
throw new Error('New field name is required for the rename operation');
197199
return {
198200
...schema,
199201
properties: Object.fromEntries(

packages/compass-data-modeling/src/utils/utils.spec.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
isRelationshipOfAField,
55
isSameFieldOrAncestor,
66
} from './utils';
7+
import type { Relationship } from '../services/data-model-storage';
78

89
describe('isSameFieldOrAncestor', function () {
910
it('should return true for the same field', function () {
@@ -24,9 +25,9 @@ describe('isSameFieldOrAncestor', function () {
2425
});
2526

2627
describe('isRelationshipOfAField', function () {
27-
const relationship = [
28-
{ ns: 'db.coll1', fields: ['a', 'b'] },
29-
{ ns: 'db.coll2', fields: ['c', 'd'] },
28+
const relationship: Relationship['relationship'] = [
29+
{ ns: 'db.coll1', fields: ['a', 'b'], cardinality: 1 },
30+
{ ns: 'db.coll2', fields: ['c', 'd'], cardinality: 1 },
3031
];
3132

3233
it('should return true for exact match', function () {
@@ -44,11 +45,15 @@ describe('isRelationshipOfAField', function () {
4445

4546
it('should handle incomplete relationships', function () {
4647
expect(
47-
isRelationshipOfAField([{}, relationship[1]], 'db.coll2', ['c', 'd'])
48+
isRelationshipOfAField(
49+
[{ ns: null, fields: null, cardinality: 1 }, relationship[1]],
50+
'db.coll2',
51+
['c', 'd']
52+
)
4853
).to.be.true;
4954
expect(
5055
isRelationshipOfAField(
51-
[{ ns: 'db.coll2', fields: null }, relationship[1]],
56+
[{ ns: 'db.coll2', fields: null, cardinality: 1 }, relationship[1]],
5257
'db.coll2',
5358
['c', 'd']
5459
)
@@ -57,9 +62,9 @@ describe('isRelationshipOfAField', function () {
5762
});
5863

5964
describe('isRelationshipInvolvingAField', function () {
60-
const relationship = [
61-
{ ns: 'db.coll1', fields: ['a', 'b'] },
62-
{ ns: 'db.coll2', fields: ['c', 'd', 'e'] },
65+
const relationship: Relationship['relationship'] = [
66+
{ ns: 'db.coll1', fields: ['a', 'b'], cardinality: 1 },
67+
{ ns: 'db.coll2', fields: ['c', 'd', 'e'], cardinality: 1 },
6368
];
6469

6570
it('should return true for exact match', function () {
@@ -89,14 +94,15 @@ describe('isRelationshipInvolvingAField', function () {
8994

9095
it('should handle incomplete relationships', function () {
9196
expect(
92-
isRelationshipInvolvingField([{}, relationship[1]], 'db.coll2', [
93-
'c',
94-
'd',
95-
])
97+
isRelationshipInvolvingField(
98+
[{ ns: null, fields: null, cardinality: 1 }, relationship[1]],
99+
'db.coll2',
100+
['c', 'd']
101+
)
96102
).to.be.true;
97103
expect(
98104
isRelationshipInvolvingField(
99-
[{ ns: 'db.coll2', fields: null }, relationship[1]],
105+
[{ ns: 'db.coll2', fields: null, cardinality: 1 }, relationship[1]],
100106
'db.coll2',
101107
['c', 'd']
102108
)

packages/compass-data-modeling/src/utils/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ export function isSameFieldOrAncestor(
1616
if (ancestor.length > child.length) return false;
1717
// ignore the last character - closing bracket
1818
const ancestorPath = JSON.stringify(ancestor).slice(0, -1);
19-
const beginningOfchildPath = JSON.stringify(child).slice(
19+
const beginningOfChildPath = JSON.stringify(child).slice(
2020
0,
2121
ancestorPath.length
2222
);
23-
return ancestorPath === beginningOfchildPath;
23+
return ancestorPath === beginningOfChildPath;
2424
}
2525

2626
export function isRelationshipOfAField(

0 commit comments

Comments
 (0)