Skip to content

Commit

Permalink
Merge pull request #30 from signaux-faibles/feat/config
Browse files Browse the repository at this point in the history
feature: work with in-memory config for cached purpose
  • Loading branch information
chrnin authored May 24, 2023
2 parents 2cf7427 + dda77b9 commit 4c28135
Show file tree
Hide file tree
Showing 20 changed files with 864 additions and 175 deletions.
32 changes: 31 additions & 1 deletion boards.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Board struct {
Permission string `bson:"permission"`
Sort float64 `bson:"sort"`
Archived bool `bson:"archived"`
CreatedAt time.Time `bson:"createAt"`
CreatedAt time.Time `bson:"createdAt"`
ModifiedAt time.Time `bson:"modifiedAt"`
Stars int `bson:"stars"`
Labels []BoardLabel `bson:"labels"`
Expand Down Expand Up @@ -412,6 +412,7 @@ func (wekan *Wekan) InsertBoardLabel(ctx context.Context, board Board, boardLabe
return err
}

// SelectBoardsFromMemberID retourne les boards où on trouve le memberID passé en paramètre
func (wekan *Wekan) SelectBoardsFromMemberID(ctx context.Context, memberID UserID) ([]Board, error) {
var boards []Board
query := bson.M{
Expand All @@ -428,6 +429,7 @@ func (wekan *Wekan) SelectBoardsFromMemberID(ctx context.Context, memberID UserI
return boards, nil
}

// SelectDomainBoards retourne les boards correspondant à la slugDomainRegexp
func (wekan *Wekan) SelectDomainBoards(ctx context.Context) ([]Board, error) {
var boards []Board
query := bson.M{
Expand All @@ -443,3 +445,31 @@ func (wekan *Wekan) SelectDomainBoards(ctx context.Context) ([]Board, error) {
}
return boards, nil
}

// HasLabelName est vrai lorsque la board dispose du labelName passé en paramètre
func (board Board) HasLabelName(name BoardLabelName) bool {
for _, label := range board.Labels {
if label.Name == name {
return true
}
}
return false
}

func (board Board) HasAnyLabelNames(names []BoardLabelName) bool {
for _, name := range names {
if board.HasLabelName(name) {
return true
}
}
return false
}

func (board Board) HasAllLabelNames(names []BoardLabelName) bool {
for _, name := range names {
if !board.HasLabelName(name) {
return false
}
}
return true
}
4 changes: 2 additions & 2 deletions boards_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,13 @@ func createTestBoard(t *testing.T, suffix string, swimlanesCount int, listsCount
var swimlanes []Swimlane
var lists []List
for i := 0; i < swimlanesCount; i++ {
swimlane := BuildSwimlane(board.ID, "swimlane", t.Name()+"swimlane", i)
swimlane := BuildSwimlane(board.ID, "swimlane", t.Name()+"swimlane", float64(i))
swimlanes = append(swimlanes, swimlane)
wekan.InsertSwimlane(ctx, swimlane)
}
for i := 0; i < listsCount; i++ {
title := fmt.Sprintf("%sList%d", t.Name(), i)
list := BuildList(board.ID, title, i)
list := BuildList(board.ID, title, float64(i))
lists = append(lists, list)
wekan.InsertList(ctx, list)
}
Expand Down
64 changes: 63 additions & 1 deletion boards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func TestBoards_GetLabelByID_whenBoardLabelDoesntExists(t *testing.T) {
ass.Empty(label)
}

// NewBoardLabel retourne un objet BoardLabel
func Test_BuildBoardLabel(t *testing.T) {
id := t.Name() + "ID"
name := t.Name() + "Name"
Expand All @@ -148,3 +147,66 @@ func Test_BuildBoardLabel(t *testing.T) {
assert.Equal(t, expected.Name, boardLabel.Name)
assert.Equal(t, expected.Color, boardLabel.Color)
}

func TestBoard_HasLabelName_NotExistingLabel(t *testing.T) {
board := BuildBoard(t.Name(), t.Name(), "board")
assert.False(t, board.HasLabelName("notExistingLabel"))
}

func TestBoard_HasLabelName_ExistingLabel(t *testing.T) {
board := BuildBoard(t.Name(), t.Name(), "board")
name := BoardLabelName("testLabel")
boardLabel := NewBoardLabel(string(name), "red")
board.Labels = append(board.Labels, boardLabel)

assert.True(t, board.HasLabelName(name))
}

func TestBoard_HasAllLabelNames_ExistingLabels(t *testing.T) {
board := BuildBoard(t.Name(), t.Name(), "board")

name1 := BoardLabelName("testLabel 1")
name2 := BoardLabelName("testLabel 2")
boardLabel1 := NewBoardLabel(string(name1), "red")
boardLabel2 := NewBoardLabel(string(name2), "red")

board.Labels = append(board.Labels, boardLabel1, boardLabel2)

assert.True(t, board.HasAllLabelNames([]BoardLabelName{name1, name2}))
}

func TestBoard_HasAllLabelNames_MissingLabels(t *testing.T) {
board := BuildBoard(t.Name(), t.Name(), "board")

name1 := BoardLabelName("testLabel 1")
name2 := BoardLabelName("testLabel 2")
boardLabel1 := NewBoardLabel(string(name1), "red")

board.Labels = append(board.Labels, boardLabel1)

assert.False(t, board.HasAllLabelNames([]BoardLabelName{name1, name2}))
}

func TestBoard_HasAnyLabelNames_ExistingLabels(t *testing.T) {
board := BuildBoard(t.Name(), t.Name(), "board")

name1 := BoardLabelName("testLabel 1")
name2 := BoardLabelName("testLabel 2")
boardLabel1 := NewBoardLabel(string(name1), "red")

board.Labels = append(board.Labels, boardLabel1)

assert.True(t, board.HasAnyLabelNames([]BoardLabelName{name1, name2}))
}

func TestBoard_HasAnyLabelNames_MissingLabel(t *testing.T) {
board := BuildBoard(t.Name(), t.Name(), "board")

name1 := BoardLabelName("testLabel 1")
name2 := BoardLabelName("testLabel 2")
boardLabel1 := NewBoardLabel(string(name1), "red")

board.Labels = append(board.Labels, boardLabel1)

assert.False(t, board.HasAnyLabelNames([]BoardLabelName{name2}))
}
Loading

0 comments on commit 4c28135

Please sign in to comment.