package main

import (
	"testing"

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

func TestSendingNotifications(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)

	notifier := NewNotifier[string](3)

	err := notifier.SendAndCreate("1", "a")
	require.NoError(err)

	err = notifier.SendAndCreate("1", "b")
	require.NoError(err)

	err = notifier.SendAndCreate("1", "c")
	require.NoError(err)

	ch := notifier.Listeners["1"]

	a := <-ch
	b := <-ch
	c := <-ch

	assert.Equal(a, "a")
	assert.Equal(b, "b")
	assert.Equal(c, "c")
}

func TestFullBuffer(t *testing.T) {
	assert := assert.New(t)
	require := require.New(t)

	notifier := NewNotifier[string](1)

	err := notifier.SendAndCreate("1", "a")
	require.NoError(err)

	err = notifier.SendAndCreate("1", "b")

	assert.Error(err)
}
