From 206a211b9613c58ac9a0b8e91c8f3cc058e4a576 Mon Sep 17 00:00:00 2001 From: Vivek Yadav Date: Mon, 23 Dec 2024 21:11:37 +0530 Subject: [PATCH] added UT --- .../object-detail.component.spec.ts | 47 +++++++++++++++++++ webv2/api/schema_test.go | 18 +++++++ 2 files changed, 65 insertions(+) diff --git a/ui/src/app/components/object-detail/object-detail.component.spec.ts b/ui/src/app/components/object-detail/object-detail.component.spec.ts index 278313fcd..945a1e1aa 100644 --- a/ui/src/app/components/object-detail/object-detail.component.spec.ts +++ b/ui/src/app/components/object-detail/object-detail.component.spec.ts @@ -350,6 +350,53 @@ describe('ObjectDetailComponent', () => { }) + it('should Edit the existing record and updateCheckConstraint and handle success response', () => { + spyOn(component, 'setCCRows').and.callThrough() + component.ccData = [ + { + srcSno: '', + srcConstraintName: '', + srcCondition: '', + spSno: '1', + spConstraintName: 'check_1', + spConstraintCondition: 'age > 18', + spExprId:'expr1', + deleteIndex: 'cc1', + } + ] + component.setCCRows() + component.ccData[0].srcConstraintName = "check_modify" + component.setCCRows() + component.currentObject = { id: 't2' } as FlatNode + + component.saveCc(); + + expect(dataServiceSpy.updateCheckConstraint); + expect(component.isCcEditMode).toBe(false); + + }) + + it('should display the check constraints perfectly', () => { + spyOn(component, 'setCCRows').and.callThrough() + component.ccData = [ + { + srcSno: '', + srcConstraintName: '', + srcCondition: '', + spSno: '1', + spConstraintName: 'check_1', + spConstraintCondition: 'age > 18', + spExprId:'expr1', + deleteIndex: 'cc1', + } + ] + fixture.detectChanges() + component.setCCRows() + expect(component.ccData.length).toBe(1) + expect(component.ccDataSource.length).toBe(1); + + }) + it('should show error dialog if updateCheckConstraint response is an error', () => { spyOn(component, 'setCCRows').and.callThrough() diff --git a/webv2/api/schema_test.go b/webv2/api/schema_test.go index 198cc0210..33013fe9e 100644 --- a/webv2/api/schema_test.go +++ b/webv2/api/schema_test.go @@ -2640,9 +2640,27 @@ func TestVerifyCheckConstraintExpressions(t *testing.T) { name: "AllValidExpressions", expressions: []ddl.CheckConstraint{ {Expr: "(col1 > 0)", ExprId: "expr1", Name: "check1"}, + {Expr: "(((col1 > 0) and (col2 like 'A%') and (col4 between 5 and 100)) or (col5 in ('Alpha', 'Beta', 'Gamma')) )", ExprId: "expr2", Name: "complex_check"}, + {Expr: "(col1 > 10)", ExprId: "expr3", Name: "conflict_check1"}, + {Expr: "(col1 < 40)", ExprId: "expr4", Name: "conflict_check2"}, + {Expr: "(col1 > 0)", ExprId: "expr5", Name: "auto_increment_check"}, + {Expr: "(price >= 0.01 AND price <= 10000.00)", ExprId: "expr6", Name: "numeric_check"}, + {Expr: "username <> 'invalid'", ExprId: "expr7", Name: "character_check"}, + {Expr: "(status IN ('Pending', 'In Progress', 'Completed', 'Cancelled'))", ExprId: "expr8", Name: "enumerate_check"}, + {Expr: "((col2 & 8) = 0)", ExprId: "expr9", Name: "bitwise_check"}, + {Expr: "featureA IN (0, 1)", ExprId: "expr10", Name: "boolean_check"}, }, expectedResults: []internal.ExpressionVerificationOutput{ {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 0)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c1", "checkConstraintName": "check1"}, ExpressionId: "expr1"}}, + {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(((col1 > 0) and (col2 like 'A%') and (col4 between 5 and 100)) or (col5 in ('Alpha', 'Beta', 'Gamma')) )", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c2", "checkConstraintName": "complex_check"}, ExpressionId: "expr2"}}, + {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 10)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c3", "checkConstraintName": "conflict_check1"}, ExpressionId: "expr3"}}, + {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 < 40)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c4", "checkConstraintName": "conflict_check2"}, ExpressionId: "expr4"}}, + {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(col3 > 0)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c5", "checkConstraintName": "auto_increment_check"}, ExpressionId: "expr5"}}, + {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(price >= 0.01 AND price <= 10000.00)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c6", "checkConstraintName": "numeric_check"}, ExpressionId: "expr6"}}, + {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "username <> 'invalid'", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c7", "checkConstraintName": "character_check"}, ExpressionId: "expr7"}}, + {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(status IN ('Pending', 'In Progress', 'Completed', 'Cancelled'))", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c8", "checkConstraintName": "enumerate_check"}, ExpressionId: "expr8"}}, + {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "((col2 & 8) = 0)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c9", "checkConstraintName": "bitwise_check"}, ExpressionId: "expr9"}}, + {Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "featureA IN (0, 1)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c10", "checkConstraintName": "boolean_check"}, ExpressionId: "expr10"}}, }, expectedResponse: false, },