@@ -1952,6 +1952,83 @@ func TestNotificationTargetMatrix(t *testing.T) {
19521952}
19531953}
19541954
1955+ func TestNotificationOneTimePasswordDeliveryTargets (t * testing.T ) {
1956+ t .Parallel ()
1957+
1958+ t .Run ("Inbox" ,func (t * testing.T ) {
1959+ t .Parallel ()
1960+
1961+ // nolint:gocritic // Unit test.
1962+ ctx := dbauthz .AsNotifier (testutil .Context (t ,testutil .WaitSuperLong ))
1963+ store ,_ := dbtestutil .NewDB (t )
1964+ logger := testutil .Logger (t )
1965+
1966+ // Given: Coder Inbox is enabled and SMTP/Webhook are disabled.
1967+ cfg := defaultNotificationsConfig (database .NotificationMethodSmtp )
1968+ cfg .Inbox .Enabled = true
1969+ cfg .SMTP = codersdk.NotificationsEmailConfig {}
1970+ cfg .Webhook = codersdk.NotificationsWebhookConfig {}
1971+
1972+ enq ,err := notifications .NewStoreEnqueuer (cfg ,store ,defaultHelpers (),logger .Named ("enqueuer" ),quartz .NewMock (t ))
1973+ require .NoError (t ,err )
1974+ user := createSampleUser (t ,store )
1975+
1976+ // When: A one-time-passcode notification is sent, it does not enqueue a notification.
1977+ enqueued ,err := enq .Enqueue (ctx ,user .ID ,notifications .TemplateUserRequestedOneTimePasscode ,
1978+ map [string ]string {"one_time_passcode" :"1234" },"test" ,user .ID )
1979+ require .NoError (t ,err )
1980+ require .Len (t ,enqueued ,0 )
1981+ })
1982+
1983+ t .Run ("SMTP" ,func (t * testing.T ) {
1984+ t .Parallel ()
1985+
1986+ // nolint:gocritic // Unit test.
1987+ ctx := dbauthz .AsNotifier (testutil .Context (t ,testutil .WaitSuperLong ))
1988+ store ,_ := dbtestutil .NewDB (t )
1989+ logger := testutil .Logger (t )
1990+
1991+ // Given: Coder Inbox/Webhook are disabled and SMTP is enabled.
1992+ cfg := defaultNotificationsConfig (database .NotificationMethodSmtp )
1993+ cfg .Inbox .Enabled = false
1994+ cfg .Webhook = codersdk.NotificationsWebhookConfig {}
1995+
1996+ enq ,err := notifications .NewStoreEnqueuer (cfg ,store ,defaultHelpers (),logger .Named ("enqueuer" ),quartz .NewMock (t ))
1997+ require .NoError (t ,err )
1998+ user := createSampleUser (t ,store )
1999+
2000+ // When: A one-time-passcode notification is sent, it does enqueue a notification.
2001+ enqueued ,err := enq .Enqueue (ctx ,user .ID ,notifications .TemplateUserRequestedOneTimePasscode ,
2002+ map [string ]string {"one_time_passcode" :"1234" },"test" ,user .ID )
2003+ require .NoError (t ,err )
2004+ require .Len (t ,enqueued ,1 )
2005+ })
2006+
2007+ t .Run ("Webhook" ,func (t * testing.T ) {
2008+ t .Parallel ()
2009+
2010+ // nolint:gocritic // Unit test.
2011+ ctx := dbauthz .AsNotifier (testutil .Context (t ,testutil .WaitSuperLong ))
2012+ store ,_ := dbtestutil .NewDB (t )
2013+ logger := testutil .Logger (t )
2014+
2015+ // Given: Coder Inbox/SMTP are disabled and Webhook is enabled.
2016+ cfg := defaultNotificationsConfig (database .NotificationMethodWebhook )
2017+ cfg .Inbox .Enabled = false
2018+ cfg .SMTP = codersdk.NotificationsEmailConfig {}
2019+
2020+ enq ,err := notifications .NewStoreEnqueuer (cfg ,store ,defaultHelpers (),logger .Named ("enqueuer" ),quartz .NewMock (t ))
2021+ require .NoError (t ,err )
2022+ user := createSampleUser (t ,store )
2023+
2024+ // When: A one-time-passcode notification is sent, it does enqueue a notification.
2025+ enqueued ,err := enq .Enqueue (ctx ,user .ID ,notifications .TemplateUserRequestedOneTimePasscode ,
2026+ map [string ]string {"one_time_passcode" :"1234" },"test" ,user .ID )
2027+ require .NoError (t ,err )
2028+ require .Len (t ,enqueued ,1 )
2029+ })
2030+ }
2031+
19552032type fakeHandler struct {
19562033mu sync.RWMutex
19572034succeeded ,failed []string