2
0

ci: Fix e2e tests

This commit is contained in:
Baptiste Arnaud
2022-05-13 06:47:39 -07:00
parent 7507a1ab1e
commit e268638786
7 changed files with 65 additions and 18 deletions

View File

@@ -26,7 +26,7 @@ export const Edges = ({
left="0" left="0"
top="0" top="0"
pointerEvents="none" pointerEvents="none"
shape-rendering="geometricPrecision" shapeRendering="geometricPrecision"
> >
<DrawingEdge /> <DrawingEdge />
{edges.map((edge) => ( {edges.map((edge) => (

View File

@@ -162,7 +162,7 @@ export const TypebotContext = ({
useEffect(() => { useEffect(() => {
if (!typebot || !currentTypebotRef.current) return if (!typebot || !currentTypebotRef.current) return
if (typebotId !== currentTypebotRef.current.id) { if (typebotId !== currentTypebotRef.current.id) {
setLocalTypebot({ ...typebot }) setLocalTypebot({ ...typebot }, { updateDate: false })
flush() flush()
} else if ( } else if (
new Date(typebot.updatedAt) > new Date(typebot.updatedAt) >

View File

@@ -84,7 +84,7 @@ test.describe.parallel('Image bubble step', () => {
force: true, force: true,
position: { x: 0, y: 0 }, position: { x: 0, y: 0 },
}) })
await expect(page.locator('img[alt="Step image"]')).toHaveAttribute( await expect(page.locator('img[alt="Block image"]')).toHaveAttribute(
'src', 'src',
new RegExp('giphy.com/media', 'gm') new RegExp('giphy.com/media', 'gm')
) )

View File

@@ -12,7 +12,10 @@ enum ActionType {
} }
export interface Actions<T> { export interface Actions<T> {
set: (newPresent: T | ((current: T) => T)) => void set: (
newPresent: T | ((current: T) => T),
options?: { updateDate: boolean }
) => void
undo: () => void undo: () => void
redo: () => void redo: () => void
flush: () => void flush: () => void
@@ -24,6 +27,7 @@ export interface Actions<T> {
interface Action<T> { interface Action<T> {
type: ActionType type: ActionType
newPresent?: T newPresent?: T
updateDate?: boolean
} }
export interface State<T> { export interface State<T> {
@@ -72,7 +76,7 @@ const reducer = <T>(state: State<T>, action: Action<T>) => {
} }
case ActionType.Set: { case ActionType.Set: {
const { newPresent } = action const { newPresent, updateDate } = action
if ( if (
isNotDefined(newPresent) || isNotDefined(newPresent) ||
(present && (present &&
@@ -92,7 +96,12 @@ const reducer = <T>(state: State<T>, action: Action<T>) => {
// ) // )
return { return {
past: [...past, present].filter(isDefined), past: [...past, present].filter(isDefined),
present: { ...newPresent, updatedAt: new Date() }, present: {
...newPresent,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
updatedAt: updateDate ? new Date() : newPresent.updatedAt,
},
future: [], future: [],
} }
} }
@@ -124,14 +133,21 @@ const useUndo = <T>(initialPresent: T): [State<T>, Actions<T>] => {
} }
}, [canRedo]) }, [canRedo])
const set = useCallback((newPresent: T | ((current: T) => T)) => { const set = useCallback(
const updatedTypebot = (newPresent: T | ((current: T) => T), options = { updateDate: true }) => {
'id' in newPresent const updatedTypebot =
? newPresent 'id' in newPresent
: (newPresent as (current: T) => T)(presentRef.current) ? newPresent
presentRef.current = updatedTypebot : (newPresent as (current: T) => T)(presentRef.current)
dispatch({ type: ActionType.Set, newPresent: updatedTypebot }) presentRef.current = updatedTypebot
}, []) dispatch({
type: ActionType.Set,
newPresent: updatedTypebot,
updateDate: options.updateDate,
})
},
[]
)
const flush = useCallback(() => { const flush = useCallback(() => {
dispatch({ type: ActionType.Flush }) dispatch({ type: ActionType.Flush })

View File

@@ -0,0 +1,15 @@
import { withSentry } from '@sentry/nextjs'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed } from 'utils'
const handler = (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
return res.status(500).json({
statusCode: 500,
statusMessage: 'Fail',
})
}
methodNotAllowed(res)
}
export default withSentry(handler)

View File

@@ -0,0 +1,15 @@
import { withSentry } from '@sentry/nextjs'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed } from 'utils'
const handler = (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
return res.status(200).json({
statusCode: 200,
statusMessage: 'OK',
})
}
methodNotAllowed(res)
}
export default withSentry(handler)

View File

@@ -13,21 +13,22 @@ test('should execute webhooks properly', async ({ page }) => {
) )
await createWebhook(typebotId, { await createWebhook(typebotId, {
id: 'success-webhook', id: 'success-webhook',
url: 'https://webhook.site/912bafb0-b92f-4be8-ae6a-186b5879a17a', url: 'http://localhost:3001/api/mock/success',
method: HttpMethod.POST, method: HttpMethod.POST,
}) })
await createWebhook(typebotId, { await createWebhook(typebotId, {
id: 'failed-webhook', id: 'failed-webhook',
url: 'https://webhook.site/8be94c01-141e-4792-b3c6-cf45137481d6', url: 'http://localhost:3001/api/mock/fail',
method: HttpMethod.POST, method: HttpMethod.POST,
}) })
await page.goto(`/${typebotId}-public`) await page.goto(`/${typebotId}-public`)
await typebotViewer(page).locator('text=Send success webhook').click() await typebotViewer(page).locator('text=Send success webhook').click()
await page.waitForResponse( await page.waitForResponse(
(resp) => async (resp) =>
resp.request().url().includes(`/api/typebots/${typebotId}/blocks`) && resp.request().url().includes(`/api/typebots/${typebotId}/blocks`) &&
resp.status() === 200 resp.status() === 200 &&
(await resp.json()).statusCode === 200
) )
await typebotViewer(page).locator('text=Send failed webhook').click() await typebotViewer(page).locator('text=Send failed webhook').click()
await page.waitForResponse( await page.waitForResponse(