test(plugin-sentry): add test components (#4042)

This commit is contained in:
Elliot DeNolf
2023-11-07 16:02:24 -05:00
committed by GitHub
parent acba5e482b
commit 64136a6b17
6 changed files with 206 additions and 1 deletions

View File

@@ -0,0 +1,92 @@
import React from 'react'
import * as Sentry from '@sentry/react'
export const testErrors = () => {
const notFound = async () => {
const req = await fetch('http://localhost:3000/api/users/notFound', {
method: 'GET',
})
}
const cannotCreate = async () => {
const req = await fetch('http://localhost:3000/api/posts', {
method: 'POST',
body: JSON.stringify({
text: 'New post',
}),
})
}
const badLogin = async () => {
const req = await fetch('http://localhost:3000/api/users/login', {
method: 'POST',
body: JSON.stringify({
email: 'sorry@whoareyou.com',
password: '123456',
}),
})
}
const badReq = async () => {
const req = await fetch('http://localhost:3000/api/users/forgot-password', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
})
}
const badReset = async () => {
const req = await fetch('http://localhost:3000/api/users/reset-password', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
token: '7eac3830ffcfc7f9f66c00315dabeb11575dba91',
password: 'newPassword',
}),
})
}
const badVerify = async () => {
const req = await fetch('http://localhost:3000/api/users/unlock', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
}
return (
<Sentry.ErrorBoundary>
<h4>Test Errors</h4>
<div style={{ display: 'flex', gap: '10px' }}>
<button style={{ marginBottom: '20px' }} onClick={() => notFound()} type="button">
Not Found
</button>
<button style={{ marginBottom: '20px' }} onClick={() => cannotCreate()} type="button">
Forbidden
</button>
<button style={{ marginBottom: '20px' }} onClick={() => badLogin()} type="button">
Bad login
</button>
<button style={{ marginBottom: '20px' }} onClick={() => badReq()} type="button">
TypeError
</button>
<button style={{ marginBottom: '20px' }} onClick={() => badReset()} type="button">
Bad Reset
</button>
<button style={{ marginBottom: '20px' }} onClick={() => badVerify()} type="button">
Bad Verify
</button>
</div>
</Sentry.ErrorBoundary>
)
}

View File

@@ -3,9 +3,16 @@ import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
import { devUser } from '../credentials'
import { Posts } from './collections/Posts'
import { Users } from './collections/Users'
import { testErrors } from './components'
export default buildConfigWithDefaults({
collections: [Posts, Users],
admin: {
user: Users.slug,
components: {
beforeDashboard: [testErrors],
},
},
plugins: [
sentry({
dsn: 'https://61edebe5ee6d4d38a9d6459c7323d777@o4505289711681536.ingest.sentry.io/4505357688242176',

View File

@@ -0,0 +1,66 @@
/* tslint:disable */
/* eslint-disable */
/**
* This file was automatically generated by Payload.
* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,
* and re-run `payload generate:types` to regenerate this file.
*/
export interface Config {
collections: {
posts: Post
users: User
'payload-preferences': PayloadPreference
'payload-migrations': PayloadMigration
}
globals: {}
}
export interface Post {
id: string
text?: string | null
updatedAt: string
createdAt: string
}
export interface User {
id: string
updatedAt: string
createdAt: string
email: string
resetPasswordToken?: string | null
resetPasswordExpiration?: string | null
salt?: string | null
hash?: string | null
loginAttempts?: number | null
lockUntil?: string | null
password: string | null
}
export interface PayloadPreference {
id: string
user: {
relationTo: 'users'
value: string | User
}
key?: string | null
value?:
| {
[k: string]: unknown
}
| unknown[]
| string
| number
| boolean
| null
updatedAt: string
createdAt: string
}
export interface PayloadMigration {
id: string
name?: string | null
batch?: number | null
updatedAt: string
createdAt: string
}
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}