Skip to content

Commit

Permalink
added UT
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivek Yadav committed Dec 23, 2024
1 parent 1994899 commit 206a211
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 18 additions & 0 deletions webv2/api/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit 206a211

Please sign in to comment.