main

mattermost/focalboard

Last updated at: 29/12/2023 09:46

webhook_test.go

TLDR

This file contains a test function that tests the NotifyUpdate method of the NewClient class in the webhook package. It creates a test server, sets up a configuration, logger, and client, and then calls the NotifyUpdate method. It asserts that the test server has been notified.

Methods

TestClientUpdateNotify

This method is a test function that tests the NotifyUpdate method of the NewClient class in the webhook package. It creates a test server, sets up a configuration, logger, and client, and then calls the NotifyUpdate method. It asserts that the test server has been notified.

Classes

Client

This class is responsible for sending update notifications via webhooks. It has a NotifyUpdate method that sends an update notification using the configured webhooks.

Configuration

This class represents the configuration settings for the webhook service. It has a property WebhookUpdate which is a list of webhook URLs to notify on updates.

Logger

This class is responsible for logging messages. It has a method Shutdown to shutdown the logger.

Model

This class represents the data model for the webhook functionality. It has a Block structure that contains information about the webhook update.

TestRequest

This class is used for testing purposes. It represents an HTTP request.

TestResponseWriter

This class is used for testing purposes. It represents an HTTP response writer.

TestServer

This class is used for testing purposes. It represents an HTTP test server.

TestSuite

This class is used for testing purposes. It represents a test suite.

package webhook

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/mattermost/focalboard/server/model"
	"github.com/mattermost/focalboard/server/services/config"
	"github.com/stretchr/testify/assert"

	"github.com/mattermost/mattermost-server/v6/shared/mlog"
)

func TestClientUpdateNotify(t *testing.T) {
	var isNotified bool
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		isNotified = true
	}))
	defer ts.Close()

	cfg := &config.Configuration{
		WebhookUpdate: []string{ts.URL},
	}

	logger := mlog.CreateConsoleTestLogger(false, mlog.LvlDebug)
	defer func() {
		err := logger.Shutdown()
		assert.NoError(t, err)
	}()

	client := NewClient(cfg, logger)

	client.NotifyUpdate(&model.Block{})

	if !isNotified {
		t.Error("webhook url not be notified")
	}
}