summaryrefslogtreecommitdiff
path: root/app/domain/sparkle_test.go
blob: 8d81afd48b9f030d4ca441b16f368a78e795c07a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package domain

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestSparkle(t *testing.T) {
	t.Run("NewSparkle", func(t *testing.T) {
		t.Run("with a valid body", func(t *testing.T) {
			sparkle, err := NewSparkle("@tanuki for helping me with my homework!")

			assert.Nil(t, err)
			if err != nil {
				assert.Equal(t, "@tanuki", sparkle.Sparklee)
				assert.Equal(t, "for helping me with my homework!", sparkle.Reason)
			}
		})

		t.Run("with an empty body", func(t *testing.T) {
			sparkle, err := NewSparkle("")

			assert.Nil(t, sparkle)
			assert.NotNil(t, err)
			if err != nil {
				assert.Equal(t, "Sparkle is empty", err.Error())
			}
		})

		t.Run("without a reason", func(t *testing.T) {
			sparkle, err := NewSparkle("@tanuki")

			assert.Nil(t, sparkle)
			assert.NotNil(t, err)
			if err != nil {
				assert.Equal(t, "Sparkle is invalid", err.Error())
			}
		})

		t.Run("without a username", func(t *testing.T) {
			sparkle, err := NewSparkle("for helping me with my homework")

			assert.Nil(t, sparkle)
			assert.NotNil(t, err)
			if err != nil {
				assert.Equal(t, "Sparkle is invalid", err.Error())
			}
		})
	})
}