notification_test.go

 1package notification
 2
 3import (
 4	"context"
 5	"testing"
 6
 7	"github.com/stretchr/testify/require"
 8)
 9
10func TestNew(t *testing.T) {
11	t.Parallel()
12
13	t.Run("creates notifier with notifications enabled", func(t *testing.T) {
14		t.Parallel()
15		n := New(true)
16		require.NotNil(t, n)
17		require.True(t, n.enabled)
18	})
19
20	t.Run("creates notifier with notifications disabled", func(t *testing.T) {
21		t.Parallel()
22		n := New(false)
23		require.NotNil(t, n)
24		require.False(t, n.enabled)
25	})
26}
27
28func TestNotifyTaskComplete(t *testing.T) {
29	t.Parallel()
30
31	t.Run("does not panic when notifications enabled", func(t *testing.T) {
32		t.Parallel()
33		ctx := context.Background()
34		n := New(true)
35		require.NotPanics(t, func() {
36			cancel := n.NotifyTaskComplete(ctx, "Test Title", "Test Message", 0)
37			defer cancel()
38		})
39	})
40
41	t.Run("does not panic when notifications disabled", func(t *testing.T) {
42		t.Parallel()
43		ctx := context.Background()
44		n := New(false)
45		require.NotPanics(t, func() {
46			cancel := n.NotifyTaskComplete(ctx, "Test Title", "Test Message", 0)
47			defer cancel()
48		})
49	})
50}
51
52func TestNotifyPermissionRequest(t *testing.T) {
53	t.Parallel()
54
55	t.Run("does not panic when notifications enabled", func(t *testing.T) {
56		t.Parallel()
57		ctx := context.Background()
58		n := New(true)
59		require.NotPanics(t, func() {
60			cancel := n.NotifyPermissionRequest(ctx, "Test Title", "Test Message", 0)
61			defer cancel()
62		})
63	})
64
65	t.Run("does not panic when notifications disabled", func(t *testing.T) {
66		t.Parallel()
67		ctx := context.Background()
68		n := New(false)
69		require.NotPanics(t, func() {
70			cancel := n.NotifyPermissionRequest(ctx, "Test Title", "Test Message", 0)
71			defer cancel()
72		})
73	})
74}