Skip to content

Commit

Permalink
Add support for /group-order URLs (#20)
Browse files Browse the repository at this point in the history
* Add support for /group-order URLs

* Add /group-order/ URL test
  • Loading branch information
ramikg authored Jun 4, 2024
1 parent ef13884 commit 7985aae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion service/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/oriser/regroup"
)

var groupLinkRe = regroup.MustCompile(`\/group\/(?P<id>[A-Z0-9]+?)($|\/$)`)
var groupLinkRe = regroup.MustCompile(`\/group(-order)?\/(?P<id>[A-Z0-9]+?)((\/join)?\/?$)`)

var errWontJoin = errors.New("wont join because the channel is not accessible")
var errNotInTime = errors.New("order not in tracking time")
Expand Down
27 changes: 24 additions & 3 deletions testing/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ var timezones = []string{
"Pacific/Pago_Pago", // -11
}

type WoltLinkType int

const (
WoltGroupLink WoltLinkType = iota
WoltGroupOrderJoinLink
)

type testData struct {
woltServer *woltserver.WoltServer
slackServer *slacktest.Server
Expand Down Expand Up @@ -238,7 +245,7 @@ func buildSlackReactionEvent(t *testing.T, itemUser, timestamp, reaction string,
return buildGenericSlackEvent(t, &rawEvent)
}

func buildSlackLinkEvent(t *testing.T, messageTimestamp, groupShortID string) []byte {
func buildSlackLinkEvent(t *testing.T, messageTimestamp, groupShortID string, linkType WoltLinkType) []byte {
t.Helper()

linkEvent := &slackevents.LinkSharedEvent{
Expand All @@ -249,10 +256,19 @@ func buildSlackLinkEvent(t *testing.T, messageTimestamp, groupShortID string) []
MessageTimeStamp: messageTimestamp,
ThreadTimeStamp: "ignored",
}

var linkFormatString string
switch linkType {
case WoltGroupLink:
linkFormatString = "https://wolt.com/group/%s"
case WoltGroupOrderJoinLink:
linkFormatString = "https://wolt.com/en/group-order/%s/join"
}

setLinksToEvent(t, []sharedLinks{
{
Domain: "wolt.com",
URL: fmt.Sprintf("https://wolt.com/group/%s", groupShortID),
URL: fmt.Sprintf(linkFormatString, groupShortID),
},
}, linkEvent)

Expand Down Expand Up @@ -476,6 +492,7 @@ func TestSlackPurchaseGroup(t *testing.T) {
slashCommandSender string
addHostToSlack bool
cancelDebts bool
woltLinkType WoltLinkType
}{
{
name: "Simple no participants",
Expand Down Expand Up @@ -621,6 +638,10 @@ func TestSlackPurchaseGroup(t *testing.T) {
addHostToSlack: true,
host: "Ori",
},
{
name: "Join /group-order/ link type",
woltLinkType: WoltGroupOrderJoinLink,
},
}
for _, tc := range tests {
tc := tc
Expand Down Expand Up @@ -659,7 +680,7 @@ func TestSlackPurchaseGroup(t *testing.T) {

// Sending link event (equal to sending wolt link in a channel)
timestamp := utils.GenerateRandomString(utils.NumberLetters, 8)
evt := buildSlackLinkEvent(t, timestamp, orderShortID)
evt := buildSlackLinkEvent(t, timestamp, orderShortID, tc.woltLinkType)
resp, err := http.Post("http://"+tdata.boltAddr+"/events-endpoint", "application/json", bytes.NewReader(evt))
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
Expand Down

0 comments on commit 7985aae

Please sign in to comment.