Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

1005 B
Raw Blame
package jobs_test

import (
	"context"
	"testing"

	"github.com/getfider/fider/app/jobs"
	"github.com/getfider/fider/app/models/cmd"
	"github.com/getfider/fider/app/models/query"
	. "github.com/getfider/fider/app/pkg/assert"
	"github.com/getfider/fider/app/pkg/bus"
)

func TestEmailSupressionJob_Schedule_IsCorrect(t *testing.T) {
	RegisterT(t)

	job := &jobs.EmailSupressionJobHandler{}
	Expect(job.Schedule()).Equals("0 5 * * * *")
}

func TestEmailSupressionJob_ShouldSupressRecentFailures(t *testing.T) {
	RegisterT(t)

	bus.AddHandler(func(ctx context.Context, q *query.FetchRecentSupressions) error {
		q.EmailAddresses = []string{
			"[email protected]", "[email protected]",
		}
		return nil
	})

	bus.AddHandler(func(ctx context.Context, c *cmd.SupressEmail) error {
		Expect(c.EmailAddresses).Equals([]string{"[email protected]", "[email protected]"})
		return nil
	})

	job := &jobs.EmailSupressionJobHandler{}
	err := job.Run(jobs.Context{
		Context: context.Background(),
	})
	Expect(err).IsNil()
}