Skip to content

Commit

Permalink
Add tests for subscription updater
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuixz committed Aug 19, 2024
1 parent e6880af commit 1d08956
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkg/slack/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slack

import (
"context"
"fmt"
"testing"

"github.com/oursky/github-actions-manager/pkg/kv"
Expand Down Expand Up @@ -157,4 +158,44 @@ func TestSpec(t *testing.T) {
Convey("has no tests at the moment", func() {
})
})
Convey("When reading the previous (deprecated) format, the bot", t, func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

testStore := kv.NewInMemoryStore()
nsSlackSubscriptions := "slack-subscriptions"
testApp := &App{
logger: zap.NewNop(),
store: testStore,
commandName: testCommand,
commands: GetCommands(),
}

Convey("correctly converts from filterless", func() {
testStore.Set(ctx, kv.Namespace(nsSlackSubscriptions), "owner/repo", channelID1)

response := testApp.Handle(ctx, commandFromChannel1("list owner/repo"))
So(response["response_type"], ShouldEqual, "in_channel")
So(response["text"], ShouldContainSubstring, channelID1)
})
Convey("correctly converts from filtered", func() {
testStore.Set(ctx, kv.Namespace(nsSlackSubscriptions), "owner/repo", fmt.Sprintf("%s:success,failure", channelID1))

response := testApp.Handle(ctx, commandFromChannel1("list owner/repo"))
So(response["response_type"], ShouldEqual, "in_channel")
So(response["text"], ShouldContainSubstring, "success")
So(response["text"], ShouldContainSubstring, "failure")
So(response["text"], ShouldContainSubstring, channelID1)
})
Convey("correctly converts from fusion", func() {
testStore.Set(ctx, kv.Namespace(nsSlackSubscriptions), "owner/repo", fmt.Sprintf("%s;%s:success,failure", channelID1, channelID2))

response := testApp.Handle(ctx, commandFromChannel1("list owner/repo"))
So(response["response_type"], ShouldEqual, "in_channel")
So(response["text"], ShouldContainSubstring, "success")
So(response["text"], ShouldContainSubstring, "failure")
So(response["text"], ShouldContainSubstring, channelID1)
So(response["text"], ShouldContainSubstring, channelID2)
})
})
}

0 comments on commit 1d08956

Please sign in to comment.