aboutsummaryrefslogtreecommitdiff
path: root/matrix/pushrules/action_test.go
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-04-16 19:27:35 +0300
committerTulir Asokan <tulir@maunium.net>2020-04-19 15:01:16 +0300
commit815190be147e575f12211c468f8121e5c60e6337 (patch)
tree8abd9b3d3952dbf767ca369ddad400db8a6f2d45 /matrix/pushrules/action_test.go
parentff20c2c44f86b40f9214f1dc3d339584e48374f1 (diff)
Update stuff and move pushrules to mautrix-go
Diffstat (limited to 'matrix/pushrules/action_test.go')
-rw-r--r--matrix/pushrules/action_test.go210
1 files changed, 0 insertions, 210 deletions
diff --git a/matrix/pushrules/action_test.go b/matrix/pushrules/action_test.go
deleted file mode 100644
index 79b2fdf..0000000
--- a/matrix/pushrules/action_test.go
+++ /dev/null
@@ -1,210 +0,0 @@
-// gomuks - A terminal Matrix client written in Go.
-// Copyright (C) 2019 Tulir Asokan
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-package pushrules_test
-
-import (
- "testing"
-
- "github.com/stretchr/testify/assert"
- "maunium.net/go/gomuks/matrix/pushrules"
-)
-
-func TestPushActionArray_Should_EmptyArrayReturnsDefaults(t *testing.T) {
- should := pushrules.PushActionArray{}.Should()
- assert.False(t, should.NotifySpecified)
- assert.False(t, should.Notify)
- assert.False(t, should.Highlight)
- assert.False(t, should.PlaySound)
- assert.Empty(t, should.SoundName)
-}
-
-func TestPushActionArray_Should_MixedArrayReturnsExpected1(t *testing.T) {
- should := pushrules.PushActionArray{
- {Action: pushrules.ActionNotify},
- {Action: pushrules.ActionSetTweak, Tweak: pushrules.TweakHighlight},
- {Action: pushrules.ActionSetTweak, Tweak: pushrules.TweakSound, Value: "ping"},
- }.Should()
- assert.True(t, should.NotifySpecified)
- assert.True(t, should.Notify)
- assert.True(t, should.Highlight)
- assert.True(t, should.PlaySound)
- assert.Equal(t, "ping", should.SoundName)
-}
-
-func TestPushActionArray_Should_MixedArrayReturnsExpected2(t *testing.T) {
- should := pushrules.PushActionArray{
- {Action: pushrules.ActionDontNotify},
- {Action: pushrules.ActionSetTweak, Tweak: pushrules.TweakHighlight, Value: false},
- {Action: pushrules.ActionSetTweak, Tweak: pushrules.TweakSound, Value: ""},
- }.Should()
- assert.True(t, should.NotifySpecified)
- assert.False(t, should.Notify)
- assert.False(t, should.Highlight)
- assert.False(t, should.PlaySound)
- assert.Empty(t, should.SoundName)
-}
-
-func TestPushActionArray_Should_NotifySet(t *testing.T) {
- should := pushrules.PushActionArray{
- {Action: pushrules.ActionNotify},
- }.Should()
- assert.True(t, should.NotifySpecified)
- assert.True(t, should.Notify)
- assert.False(t, should.Highlight)
- assert.False(t, should.PlaySound)
- assert.Empty(t, should.SoundName)
-}
-
-func TestPushActionArray_Should_NotifyAndCoalesceDoTheSameThing(t *testing.T) {
- should1 := pushrules.PushActionArray{
- {Action: pushrules.ActionNotify},
- }.Should()
- should2 := pushrules.PushActionArray{
- {Action: pushrules.ActionCoalesce},
- }.Should()
- assert.Equal(t, should1, should2)
-}
-
-func TestPushActionArray_Should_DontNotify(t *testing.T) {
- should := pushrules.PushActionArray{
- {Action: pushrules.ActionDontNotify},
- }.Should()
- assert.True(t, should.NotifySpecified)
- assert.False(t, should.Notify)
- assert.False(t, should.Highlight)
- assert.False(t, should.PlaySound)
- assert.Empty(t, should.SoundName)
-}
-
-func TestPushActionArray_Should_HighlightBlank(t *testing.T) {
- should := pushrules.PushActionArray{
- {Action: pushrules.ActionSetTweak, Tweak: pushrules.TweakHighlight},
- }.Should()
- assert.False(t, should.NotifySpecified)
- assert.False(t, should.Notify)
- assert.True(t, should.Highlight)
- assert.False(t, should.PlaySound)
- assert.Empty(t, should.SoundName)
-}
-
-func TestPushActionArray_Should_HighlightFalse(t *testing.T) {
- should := pushrules.PushActionArray{
- {Action: pushrules.ActionSetTweak, Tweak: pushrules.TweakHighlight, Value: false},
- }.Should()
- assert.False(t, should.NotifySpecified)
- assert.False(t, should.Notify)
- assert.False(t, should.Highlight)
- assert.False(t, should.PlaySound)
- assert.Empty(t, should.SoundName)
-}
-
-func TestPushActionArray_Should_SoundName(t *testing.T) {
- should := pushrules.PushActionArray{
- {Action: pushrules.ActionSetTweak, Tweak: pushrules.TweakSound, Value: "ping"},
- }.Should()
- assert.False(t, should.NotifySpecified)
- assert.False(t, should.Notify)
- assert.False(t, should.Highlight)
- assert.True(t, should.PlaySound)
- assert.Equal(t, "ping", should.SoundName)
-}
-
-func TestPushActionArray_Should_SoundNameEmpty(t *testing.T) {
- should := pushrules.PushActionArray{
- {Action: pushrules.ActionSetTweak, Tweak: pushrules.TweakSound, Value: ""},
- }.Should()
- assert.False(t, should.NotifySpecified)
- assert.False(t, should.Notify)
- assert.False(t, should.Highlight)
- assert.False(t, should.PlaySound)
- assert.Empty(t, should.SoundName)
-}
-
-func TestPushAction_UnmarshalJSON_InvalidJSONFails(t *testing.T) {
- pa := &pushrules.PushAction{}
- err := pa.UnmarshalJSON([]byte("Not JSON"))
- assert.NotNil(t, err)
-}
-
-func TestPushAction_UnmarshalJSON_InvalidTypeDoesNothing(t *testing.T) {
- pa := &pushrules.PushAction{
- Action: pushrules.PushActionType("unchanged"),
- Tweak: pushrules.PushActionTweak("unchanged"),
- Value: "unchanged",
- }
-
- err := pa.UnmarshalJSON([]byte(`{"foo": "bar"}`))
- assert.Nil(t, err)
- err = pa.UnmarshalJSON([]byte(`9001`))
- assert.Nil(t, err)
-
- assert.Equal(t, pushrules.PushActionType("unchanged"), pa.Action)
- assert.Equal(t, pushrules.PushActionTweak("unchanged"), pa.Tweak)
- assert.Equal(t, "unchanged", pa.Value)
-}
-
-func TestPushAction_UnmarshalJSON_StringChangesActionType(t *testing.T) {
- pa := &pushrules.PushAction{
- Action: pushrules.PushActionType("unchanged"),
- Tweak: pushrules.PushActionTweak("unchanged"),
- Value: "unchanged",
- }
-
- err := pa.UnmarshalJSON([]byte(`"foo"`))
- assert.Nil(t, err)
-
- assert.Equal(t, pushrules.PushActionType("foo"), pa.Action)
- assert.Equal(t, pushrules.PushActionTweak("unchanged"), pa.Tweak)
- assert.Equal(t, "unchanged", pa.Value)
-}
-
-func TestPushAction_UnmarshalJSON_SetTweakChangesTweak(t *testing.T) {
- pa := &pushrules.PushAction{
- Action: pushrules.PushActionType("unchanged"),
- Tweak: pushrules.PushActionTweak("unchanged"),
- Value: "unchanged",
- }
-
- err := pa.UnmarshalJSON([]byte(`{"set_tweak": "foo", "value": 123.0}`))
- assert.Nil(t, err)
-
- assert.Equal(t, pushrules.ActionSetTweak, pa.Action)
- assert.Equal(t, pushrules.PushActionTweak("foo"), pa.Tweak)
- assert.Equal(t, 123.0, pa.Value)
-}
-
-func TestPushAction_MarshalJSON_TweakOutputWorks(t *testing.T) {
- pa := &pushrules.PushAction{
- Action: pushrules.ActionSetTweak,
- Tweak: pushrules.PushActionTweak("foo"),
- Value: "bar",
- }
- data, err := pa.MarshalJSON()
- assert.Nil(t, err)
- assert.Equal(t, []byte(`{"set_tweak":"foo","value":"bar"}`), data)
-}
-
-func TestPushAction_MarshalJSON_OtherOutputWorks(t *testing.T) {
- pa := &pushrules.PushAction{
- Action: pushrules.PushActionType("something else"),
- Tweak: pushrules.PushActionTweak("foo"),
- Value: "bar",
- }
- data, err := pa.MarshalJSON()
- assert.Nil(t, err)
- assert.Equal(t, []byte(`"something else"`), data)
-}