Commit 9efaef6

mo khan <mo@mokhan.ca>
2022-05-16 03:03:49
test: start to add tests for inserting a new client
1 parent 6e926d6
Changed files (2)
pkg/tasks/create_client_test.go
@@ -0,0 +1,23 @@
+package tasks
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"mokhan.ca/xlgmokha/idp/pkg/dto"
+)
+
+func TestCreateClient(t *testing.T) {
+	t.Run("with valid parameters", func(t *testing.T) {
+		request := dto.ClientRegistrationRequest{
+			ClientMetadata: dto.ClientMetadata{
+				ClientName:   "jive",
+				RedirectUris: []string{"https://example.com/callback"},
+			},
+		}
+		response, err := CreateClient(request)
+
+		assert.Nil(t, err)
+		assert.NotNil(t, response)
+	})
+}
pkg/x/must_test.go
@@ -0,0 +1,24 @@
+package x
+
+import (
+	"errors"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestMust(t *testing.T) {
+	t.Run("without error", func(t *testing.T) {
+		item := 1
+		result := Must(item, nil)
+		assert.Equal(t, item, result)
+	})
+
+	t.Run("with error", func(t *testing.T) {
+		assert.Panics(t, func() {
+			item := 1
+			result := Must(item, errors.New("darn"))
+			assert.Equal(t, item, result)
+		})
+	})
+}