Skip to content

Commit

Permalink
Add TestUpdateMessagesForOrg()
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Mar 9, 2024
1 parent fd553c6 commit c3b846c
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions object/org_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2024 The casbin Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !skipCi
// +build !skipCi

package object

import (
"fmt"
"strings"
"testing"

"github.com/casibase/casibase/util"
)

func TestUpdateMessagesForOrg(t *testing.T) {
InitConfig()

organization := "casbin"

messages, err := GetGlobalMessages()
if err != nil {
panic(err)
}

for i, message := range messages {
if !strings.Contains(message.ReplyTo, "/") && !strings.Contains(message.Author, "/") && message.Organization == organization {
continue
}

message.ReplyTo = strings.TrimPrefix(message.ReplyTo, "admin/")

if strings.Contains(message.Author, "/") {
_, author := util.GetOwnerAndNameFromId(message.Author)
message.Author = author
}

message.Organization = organization

fmt.Printf("[%d/%d] message: %s, organization: %s, user: %s, author: %s\n", i+1, len(messages), message.Name, message.Organization, message.User, message.Author)

_, err = UpdateMessage(message.GetId(), message)
if err != nil {
panic(err)
}
}
}

0 comments on commit c3b846c

Please sign in to comment.