Skip to content

Commit

Permalink
Merge pull request #671 from Permify/next
Browse files Browse the repository at this point in the history
test: EntityAndCallOrAttributeToString
  • Loading branch information
tolgaOzen authored Sep 16, 2023
2 parents c36d708 + 80493d8 commit ac3e236
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 43 deletions.
64 changes: 64 additions & 0 deletions pkg/attribute/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,69 @@ var _ = Describe("attribute", func() {
Expect(Attribute(tt.target)).Should(Equal(tt.attribute))
}
})

It("EntityAndCallOrAttributeToString", func() {
tests := []struct {
entity *base.Entity
attributeOrCall string
arguments []*base.Argument
result string
}{
{
entity: &base.Entity{
Type: "organization",
Id: "1",
},
attributeOrCall: "check_credit",
arguments: []*base.Argument{
{
Type: &base.Argument_ComputedAttribute{
ComputedAttribute: &base.ComputedAttribute{
Name: "credit",
},
},
},
},
result: "organization:1$check_credit(credit)",
},
{
entity: &base.Entity{
Type: "organization",
Id: "1",
},
attributeOrCall: "is_public",
arguments: nil,
result: "organization:1$is_public",
},
{
entity: &base.Entity{
Type: "organization",
Id: "877",
},
attributeOrCall: "check_balance",
arguments: []*base.Argument{
{
Type: &base.Argument_ContextAttribute{
ContextAttribute: &base.ContextAttribute{
Name: "amount",
},
},
},
{
Type: &base.Argument_ComputedAttribute{
ComputedAttribute: &base.ComputedAttribute{
Name: "balance",
},
},
},
},
result: "organization:877$check_balance(request.amount,balance)",
},
}

for _, tt := range tests {
Expect(EntityAndCallOrAttributeToString(tt.entity, tt.attributeOrCall, tt.arguments...)).Should(Equal(tt.result))
}
})
})
})
48 changes: 5 additions & 43 deletions pkg/tuple/tuple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,65 +20,27 @@ var _ = Describe("tuple", func() {
Context("TupleToString", func() {
It("EntityAndRelationToString", func() {
tests := []struct {
target *base.EntityAndRelation
arguments []*base.Argument
expected string
target *base.EntityAndRelation
expected string
}{
{&base.EntityAndRelation{
Entity: &base.Entity{
Type: "repository",
Id: "1",
},
Relation: "admin",
}, nil, "repository:1#admin"},
}, "repository:1#admin"},
{&base.EntityAndRelation{
Entity: &base.Entity{
Type: "doc",
Id: "1",
},
Relation: "viewer",
}, nil, "doc:1#viewer"},
{&base.EntityAndRelation{
Entity: &base.Entity{
Type: "doc",
Id: "1",
},
Relation: "check_balance",
}, []*base.Argument{
{
Type: &base.Argument_ComputedAttribute{
ComputedAttribute: &base.ComputedAttribute{
Name: "balance",
},
},
},
}, "doc:1#check_balance(balance)"},
{&base.EntityAndRelation{
Entity: &base.Entity{
Type: "doc",
Id: "1",
},
Relation: "check_balance",
}, []*base.Argument{
{
Type: &base.Argument_ContextAttribute{
ContextAttribute: &base.ContextAttribute{
Name: "amount",
},
},
},
{
Type: &base.Argument_ComputedAttribute{
ComputedAttribute: &base.ComputedAttribute{
Name: "balance",
},
},
},
}, "doc:1#check_balance(request.amount,balance)"},
}, "doc:1#viewer"},
}

for _, tt := range tests {
Expect(EntityAndRelationToString(tt.target, tt.arguments...)).Should(Equal(tt.expected))
Expect(EntityAndRelationToString(tt.target.GetEntity(), tt.target.GetRelation())).Should(Equal(tt.expected))
}
})
})
Expand Down

0 comments on commit ac3e236

Please sign in to comment.