mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Add tests for invite and revoke in same batch
This commit is contained in:
parent
985a1d7184
commit
2f661565dc
2 changed files with 16 additions and 1 deletions
|
@ -67,6 +67,7 @@ var (
|
||||||
func (a *AclTestExecutor) buildBatchRequest(args []string, acl AclList, getPerm func(perm string) AclPermissions, addRec func(rec *consensusproto.RawRecordWithId) error) (afterAll []func(), err error) {
|
func (a *AclTestExecutor) buildBatchRequest(args []string, acl AclList, getPerm func(perm string) AclPermissions, addRec func(rec *consensusproto.RawRecordWithId) error) (afterAll []func(), err error) {
|
||||||
// remove:a,b,c;add:d,rw,m1|e,r,m2;changes:f,rw|g,r;revoke:inv1id;decline:g,h;
|
// remove:a,b,c;add:d,rw,m1|e,r,m2;changes:f,rw|g,r;revoke:inv1id;decline:g,h;
|
||||||
batchPayload := BatchRequestPayload{}
|
batchPayload := BatchRequestPayload{}
|
||||||
|
var inviteIds []string
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
parts := strings.Split(arg, ":")
|
parts := strings.Split(arg, ":")
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
|
@ -182,6 +183,16 @@ func (a *AclTestExecutor) buildBatchRequest(args []string, acl AclList, getPerm
|
||||||
afterAll = append(afterAll, func() {
|
afterAll = append(afterAll, func() {
|
||||||
a.expectedAccounts[id].status = StatusDeclined
|
a.expectedAccounts[id].status = StatusDeclined
|
||||||
})
|
})
|
||||||
|
case "invite":
|
||||||
|
inviteParts := strings.Split(commandArgs[0], ",")
|
||||||
|
id := inviteParts[0]
|
||||||
|
inviteIds = append(inviteIds, id)
|
||||||
|
batchPayload.NewInvites = append(batchPayload.NewInvites, AclPermissionsNone)
|
||||||
|
case "invite_anyone":
|
||||||
|
inviteParts := strings.Split(commandArgs[0], ",")
|
||||||
|
id := inviteParts[0]
|
||||||
|
inviteIds = append(inviteIds, id)
|
||||||
|
batchPayload.NewInvites = append(batchPayload.NewInvites, AclPermissionsReader)
|
||||||
case "approve":
|
case "approve":
|
||||||
recs, err := acl.AclState().JoinRecords(false)
|
recs, err := acl.AclState().JoinRecords(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -212,11 +223,13 @@ func (a *AclTestExecutor) buildBatchRequest(args []string, acl AclList, getPerm
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := acl.RecordBuilder().BuildBatchRequest(batchPayload)
|
res, err := acl.RecordBuilder().BuildBatchRequest(batchPayload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
for i, id := range inviteIds {
|
||||||
|
a.invites[id] = res.Invites[i]
|
||||||
|
}
|
||||||
return afterAll, addRec(WrapAclRecord(res.Rec))
|
return afterAll, addRec(WrapAclRecord(res.Rec))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,8 @@ func TestAclExecutor(t *testing.T) {
|
||||||
{"a.invite_change::oldInvId,a", nil},
|
{"a.invite_change::oldInvId,a", nil},
|
||||||
{"new2.invite_join::oldInvId", nil},
|
{"new2.invite_join::oldInvId", nil},
|
||||||
{"new2.add::new3,r,new3m", nil},
|
{"new2.add::new3,r,new3m", nil},
|
||||||
|
{"a.batch::revoke:oldInvId;invite_anyone:someId", nil},
|
||||||
|
{"new4.invite_join::someId", nil},
|
||||||
}
|
}
|
||||||
for _, cmd := range cmds {
|
for _, cmd := range cmds {
|
||||||
err := a.Execute(cmd.cmd)
|
err := a.Execute(cmd.cmd)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue