From 8f4a1db1f0a00bec990fecd7fdea0b390074dbd9 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Fri, 22 Apr 2022 14:51:44 -0400 Subject: [PATCH] Changelog, add tests --- docs/releases.md | 12 +++++++++- server/server_test.go | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/docs/releases.md b/docs/releases.md index 5d2a126b..b53a9570 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -8,7 +8,10 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release **Features:** -* Support for ntfy:// deep links ([#20](https://github.com/binwiederhier/ntfy/issues/20), thanks to [@Copephobia](https://github.com/Copephobia) for reporting) +* Custom notification [action buttons](https://ntfy.sh/docs/publish/#action-buttons) ([#134](https://github.com/binwiederhier/ntfy/issues/134), + thanks to [@mrherman](https://github.com/mrherman) for reporting) +* Support for [ntfy:// deep links](https://ntfy.sh/docs/subscribe/phone/#ntfy-links) ([#20](https://github.com/binwiederhier/ntfy/issues/20), thanks + to [@Copephobia](https://github.com/Copephobia) for reporting) * [Fastlane metadata](https://hosted.weblate.org/projects/ntfy/android-fastlane/) can now be translated too ([#198](https://github.com/binwiederhier/ntfy/issues/198), thanks to [@StoyanDimitrov](https://github.com/StoyanDimitrov) for reporting) * Channel settings option to configure DND override, sounds, etc. ([#91](https://github.com/binwiederhier/ntfy/issues/91)) @@ -26,10 +29,17 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release * Japanese (thanks to [@shak](https://hosted.weblate.org/user/shak/)) * Russian (thanks to [@flamey](https://hosted.weblate.org/user/flamey/) and [@ilya.mikheev.coder](https://hosted.weblate.org/user/ilya.mikheev.coder/)) +**Thanks for testing:** + +Thanks to [@RasHas](https://github.com/RasHas) (aka @Shard), [@Fallenbagel](https://github.com/Fallenbagel), [@cmeis](https://github.com/cmeis), +@poblabs, and everyone I forgot for testing. + ## ntfy server v1.21.0 (UNRELEASED) **Features:** +* Custom notification [action buttons](https://ntfy.sh/docs/publish/#action-buttons) ([#134](https://github.com/binwiederhier/ntfy/issues/134), + thanks to [@mrherman](https://github.com/mrherman) for reporting) * Added ARMv6 build ([#200](https://github.com/binwiederhier/ntfy/issues/200), thanks to [@jcrubioa](https://github.com/jcrubioa) for reporting) * Web app internationalization support ([#189](https://github.com/binwiederhier/ntfy/issues/189)) diff --git a/server/server_test.go b/server/server_test.go index c0b41c03..0f84b90a 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -876,6 +876,26 @@ func TestServer_PublishUnifiedPushText(t *testing.T) { require.Equal(t, "this is a unifiedpush text message", m.Message) } +func TestServer_PublishActions_AndPoll(t *testing.T) { + s := newTestServer(t, newTestConfig(t)) + response := request(t, s, "PUT", "/mytopic", "my message", map[string]string{ + "Actions": "view, Open portal, https://home.nest.com/; http, Turn down, https://api.nest.com/device/XZ1D2, body=target_temp_f=65", + }) + require.Equal(t, 200, response.Code) + + response = request(t, s, "GET", "/mytopic/json?poll=1", "", nil) + require.Equal(t, 200, response.Code) + m := toMessage(t, response.Body.String()) + require.Equal(t, 2, len(m.Actions)) + require.Equal(t, "view", m.Actions[0].Action) + require.Equal(t, "Open portal", m.Actions[0].Label) + require.Equal(t, "https://home.nest.com/", m.Actions[0].URL) + require.Equal(t, "http", m.Actions[1].Action) + require.Equal(t, "Turn down", m.Actions[1].Label) + require.Equal(t, "https://api.nest.com/device/XZ1D2", m.Actions[1].URL) + require.Equal(t, "target_temp_f=65", m.Actions[1].Body) +} + func TestServer_PublishAsJSON(t *testing.T) { s := newTestServer(t, newTestConfig(t)) body := `{"topic":"mytopic","message":"A message","title":"a title\nwith lines","tags":["tag1","tag 2"],` + @@ -911,6 +931,41 @@ func TestServer_PublishAsJSON_WithEmail(t *testing.T) { require.Equal(t, 1, mailer.Count()) } +func TestServer_PublishAsJSON_WithActions(t *testing.T) { + s := newTestServer(t, newTestConfig(t)) + body := `{ + "topic":"mytopic", + "message":"A message", + "actions": [ + { + "action": "view", + "label": "Open portal", + "url": "https://home.nest.com/" + }, + { + "action": "http", + "label": "Turn down", + "url": "https://api.nest.com/device/XZ1D2", + "body": "target_temp_f=65" + } + ] + }` + response := request(t, s, "POST", "/", body, nil) + require.Equal(t, 200, response.Code) + + m := toMessage(t, response.Body.String()) + require.Equal(t, "mytopic", m.Topic) + require.Equal(t, "A message", m.Message) + require.Equal(t, 2, len(m.Actions)) + require.Equal(t, "view", m.Actions[0].Action) + require.Equal(t, "Open portal", m.Actions[0].Label) + require.Equal(t, "https://home.nest.com/", m.Actions[0].URL) + require.Equal(t, "http", m.Actions[1].Action) + require.Equal(t, "Turn down", m.Actions[1].Label) + require.Equal(t, "https://api.nest.com/device/XZ1D2", m.Actions[1].URL) + require.Equal(t, "target_temp_f=65", m.Actions[1].Body) +} + func TestServer_PublishAsJSON_Invalid(t *testing.T) { s := newTestServer(t, newTestConfig(t)) body := `{"topic":"mytopic",INVALID`