Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui/profile: always use Dest API #3875

Merged
merged 13 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions graphql2/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions graphql2/graphqlapp/contactmethod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

"github.com/target/goalert/config"
"github.com/target/goalert/expflag"
"github.com/target/goalert/graphql2"
"github.com/target/goalert/notification"
"github.com/target/goalert/notification/webhook"
Expand Down Expand Up @@ -191,7 +190,6 @@ func (m *Mutation) CreateUserContactMethod(ctx context.Context, input graphql2.C
input.NewUserNotificationRule.ContactMethodID = &cm.ID

_, err = m.CreateUserNotificationRule(ctx, *input.NewUserNotificationRule)

if err != nil {
return validation.AddPrefix("newUserNotificationRule.", err)
}
Expand All @@ -216,7 +214,7 @@ func (m *Mutation) UpdateUserContactMethod(ctx context.Context, input graphql2.U
}
if input.Name != nil {
err := validate.IDName("input.name", *input.Name)
if err != nil && expflag.ContextHas(ctx, expflag.DestTypes) {
if err != nil {
addInputError(ctx, err)
return errAlreadySet
}
Expand Down
10 changes: 6 additions & 4 deletions graphql2/graphqlapp/destinationvalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ var errAlreadySet = errors.New("error already set")
// and are only used for signaling to other parts of the system.
type errSkipHandler struct{}

var _ graphql.ResponseInterceptor = errSkipHandler{}
var _ graphql.HandlerExtension = errSkipHandler{}
var (
_ graphql.ResponseInterceptor = errSkipHandler{}
_ graphql.HandlerExtension = errSkipHandler{}
)

func (errSkipHandler) ExtensionName() string { return "ErrorSkipHandler" }

Expand Down Expand Up @@ -164,13 +166,13 @@ func (a *App) ValidateDestination(ctx context.Context, fieldName string, dest *g
case destSlackUG:
ugID := dest.FieldValue(fieldSlackUGID)
userErr := a.SlackStore.ValidateUserGroup(ctx, ugID)
if err != nil {
if userErr != nil {
return addDestFieldError(ctx, fieldName, fieldSlackUGID, userErr)
}

chanID := dest.FieldValue(fieldSlackChanID)
chanErr := a.SlackStore.ValidateChannel(ctx, chanID)
if err != nil {
if chanErr != nil {
return addDestFieldError(ctx, fieldName, fieldSlackChanID, chanErr)
}

Expand Down
2 changes: 1 addition & 1 deletion graphql2/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ input CreateUserContactMethodInput {

type: ContactMethodType

dest: DestinationInput @experimental(flagName: "dest-types")
dest: DestinationInput

name: String!

Expand Down
14 changes: 12 additions & 2 deletions test/integration/email-cm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ test('EMAIL contact method', async ({ page, browser }) => {
await pageAction(page, 'Create Contact Method', 'Create Method')

await page.fill('input[name=name]', name)
await page.fill('input[name=type]', 'EMAIL')
await page.fill('input[name=value]', email)

// ensure disclaimer is shown for voice call
await dropdownSelect(page, 'Destination Type', 'Voice Call')

await expect(
page.locator('span', { hasText: 'test-disclaimer-text' }),
).toBeVisible()

await dropdownSelect(page, 'Destination Type', 'Email')
await page.fill('input[name=email-address]', email)
await page.click('[role=dialog] button[type=submit]')

const mail = await browser.newPage({
Expand Down Expand Up @@ -119,6 +127,8 @@ test('EMAIL contact method', async ({ page, browser }) => {
.click()
await page.getByRole('menuitem', { name: 'Delete' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()

await expect(page.locator('[role=dialog]')).not.toBeVisible()
await page
.locator('.MuiCard-root', {
has: page.locator('div > div > h2', { hasText: 'Contact Methods' }),
Expand Down
46 changes: 46 additions & 0 deletions test/integration/first-login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { test, expect } from '@playwright/test'
import { dropdownSelect, userSessionFile } from './lib'
import Chance from 'chance'
const c = new Chance()

test.describe.configure({ mode: 'serial' })
test.use({ storageState: userSessionFile })

// test create, edit, verify, and delete of an EMAIL contact method
test('first time setup', async ({ page }) => {
await page.goto('.?isFirstLogin=1')
// ensure dialog is shown
await expect(
page.locator('[role=dialog]', { hasText: 'Welcome to GoAlert' }),
).toBeVisible()

const name = 'first-setup-email ' + c.name()
const email = 'first-setup-email-' + c.email()
await page.fill('input[name=name]', name)
await dropdownSelect(page, 'Destination Type', 'Email')
await page.fill('input[name=email-address]', email)
await page.click('[role=dialog] button[type=submit]')
await expect(
page.locator('[role=dialog]', { hasText: 'Verify Contact Method' }),
).toBeVisible()

// cancel out
await page.locator('[role=dialog] button', { hasText: 'Cancel' }).click()

// ensure dialog is not shown
await expect(page.locator('[role=dialog]')).toHaveCount(0)

await page.goto('./profile')
await page
.locator('.MuiCard-root', {
has: page.locator('div > div > h2', { hasText: 'Contact Methods' }),
})
.locator('li', { hasText: email })
.locator('[aria-label="Other Actions"]')
.click()
await page.getByRole('menuitem', { name: 'Delete' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()

await expect(page.locator('[role=dialog]')).not.toBeVisible()
Forfold marked this conversation as resolved.
Show resolved Hide resolved
await expect(page.locator('li', { hasText: email })).not.toBeVisible()
})
6 changes: 6 additions & 0 deletions test/integration/setup/goalert-config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"General": {
"NotificationDisclaimer": "test-disclaimer-text"
},
"Twilio": {
"Enable": true
},
"SMTP": {
"Enable": true,
"From": "goalert@localhost",
Expand Down
4 changes: 2 additions & 2 deletions web/src/app/main/components/NewUserSetup.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState } from 'react'
import UserContactMethodCreateDialog from '../../users/UserContactMethodCreateDialog'
import UserContactMethodVerificationDialog from '../../users/UserContactMethodVerificationDialog'
import { useSessionInfo } from '../../util/RequireConfig'
import { useResetURLParams, useURLParam } from '../../actions'
import UserContactMethodCreateDialogDest from '../../users/UserContactMethodCreateDialogDest'

export default function NewUserSetup(): JSX.Element {
const [isFirstLogin] = useURLParam('isFirstLogin', '')
Expand All @@ -23,7 +23,7 @@ export default function NewUserSetup(): JSX.Element {
}

return (
<UserContactMethodCreateDialog
<UserContactMethodCreateDialogDest
title='Welcome to GoAlert!'
subtitle='To get started, please enter a contact method.'
userID={userID}
Expand Down
174 changes: 0 additions & 174 deletions web/src/app/users/UserContactMethodCreateDialog.tsx

This file was deleted.

Loading
Loading