test: plugin-sentry suite (#4040)
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
MONGODB_URI=mongodb://localhost/plugin-sentry
|
||||
PAYLOAD_SECRET=mwfkfksosksseanllcosjshdncm
|
||||
6
packages/plugin-sentry/dev/.gitignore
vendored
6
packages/plugin-sentry/dev/.gitignore
vendored
@@ -1,6 +0,0 @@
|
||||
node_modules
|
||||
.env
|
||||
dist
|
||||
build
|
||||
.DS_Store
|
||||
package-lock.json
|
||||
@@ -1,7 +0,0 @@
|
||||
# Sentry Plugin Demo
|
||||
|
||||
This project was created using create-payload-app using the blank template.
|
||||
|
||||
## How to Use
|
||||
|
||||
`yarn dev` will start up your application and reload on any changes.
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"exec": "ts-node src/server.ts",
|
||||
"ext": "ts"
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
{
|
||||
"name": "plugin-sentry-demo",
|
||||
"description": "Payload project to demonstrate how to use the sentry plugin",
|
||||
"version": "1.0.0",
|
||||
"main": "dist/server.js",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"dev": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon",
|
||||
"build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
|
||||
"build:server": "tsc",
|
||||
"build": "yarn copyfiles && yarn build:payload && yarn build:server",
|
||||
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
|
||||
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
|
||||
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
|
||||
"generate:graphQLSchema": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sentry/react": "^7.56.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"eslint": "^8.42.0",
|
||||
"express": "^4.17.1",
|
||||
"payload": "^1.9.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.9",
|
||||
"copyfiles": "^2.4.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"nodemon": "^2.0.6",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "^4.8.4"
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/* eslint-disable import/no-relative-packages */
|
||||
import path from 'path'
|
||||
import { buildConfig } from 'payload/config'
|
||||
|
||||
import { sentry } from '../../src/index'
|
||||
import Posts from './collections/Posts'
|
||||
import Users from './collections/Users'
|
||||
import { testErrors } from './test/component'
|
||||
|
||||
export default buildConfig({
|
||||
serverURL: 'http://localhost:3000',
|
||||
admin: {
|
||||
user: Users.slug,
|
||||
components: {
|
||||
beforeDashboard: [testErrors],
|
||||
},
|
||||
},
|
||||
collections: [Posts, Users],
|
||||
typescript: {
|
||||
outputFile: path.resolve(__dirname, 'payload-types.ts'),
|
||||
},
|
||||
graphQL: {
|
||||
schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
|
||||
},
|
||||
plugins: [
|
||||
sentry({
|
||||
dsn: 'https://61edebe5ee6d4d38a9d6459c7323d777@o4505289711681536.ingest.sentry.io/4505357688242176',
|
||||
options: {
|
||||
init: {
|
||||
debug: true,
|
||||
},
|
||||
requestHandler: {
|
||||
serverName: false,
|
||||
},
|
||||
captureErrors: [400, 403, 404],
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
@@ -1,27 +0,0 @@
|
||||
import dotenv from 'dotenv'
|
||||
import express from 'express'
|
||||
import payload from 'payload'
|
||||
|
||||
dotenv.config()
|
||||
const app = express()
|
||||
|
||||
// Redirect root to Admin panel
|
||||
app.get('/', (_, res) => {
|
||||
res.redirect('/admin')
|
||||
})
|
||||
|
||||
// Initialize Payload
|
||||
const start = async (): Promise<void> => {
|
||||
await payload.init({
|
||||
secret: process.env.PAYLOAD_SECRET,
|
||||
mongoURL: process.env.MONGODB_URI,
|
||||
express: app,
|
||||
onInit: () => {
|
||||
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
||||
},
|
||||
})
|
||||
|
||||
app.listen(3000)
|
||||
}
|
||||
|
||||
start()
|
||||
@@ -1,92 +0,0 @@
|
||||
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>
|
||||
)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"strict": false,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "../",
|
||||
"jsx": "react",
|
||||
"sourceMap": true
|
||||
},
|
||||
"ts-node": {
|
||||
"transpileOnly": true
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
"dist"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"payload": "^1.10.1",
|
||||
"payload": "^1.10.1 || ^2.0.0",
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -36,7 +36,7 @@
|
||||
"express": "^4.18.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@payloadcms/eslint-config": "^1.0.0",
|
||||
"@payloadcms/eslint-config": "workspace:*",
|
||||
"@types/express": "^4.17.9",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "18.11.3",
|
||||
@@ -46,7 +46,7 @@
|
||||
"dotenv": "^8.2.0",
|
||||
"jest": "^29.5.0",
|
||||
"nodemon": "^2.0.6",
|
||||
"payload": "^1.10.1",
|
||||
"payload": "workspace:*",
|
||||
"ts-jest": "^29.1.0",
|
||||
"webpack": "^5.78.0"
|
||||
}
|
||||
|
||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -1213,7 +1213,7 @@ importers:
|
||||
version: 18.2.0
|
||||
devDependencies:
|
||||
'@payloadcms/eslint-config':
|
||||
specifier: ^1.0.0
|
||||
specifier: workspace:*
|
||||
version: link:../eslint-config-payload
|
||||
'@types/express':
|
||||
specifier: ^4.17.9
|
||||
@@ -1243,14 +1243,14 @@ importers:
|
||||
specifier: ^2.0.6
|
||||
version: 2.0.22
|
||||
payload:
|
||||
specifier: ^1.10.1
|
||||
version: 1.15.8(@types/react@18.0.21)(typescript@5.2.2)
|
||||
specifier: workspace:*
|
||||
version: link:../payload
|
||||
ts-jest:
|
||||
specifier: ^29.1.0
|
||||
version: 29.1.1(@babel/core@7.22.20)(jest@29.7.0)(typescript@5.2.2)
|
||||
webpack:
|
||||
specifier: ^5.78.0
|
||||
version: 5.88.2(@swc/core@1.3.78)(webpack-cli@4.10.0)
|
||||
version: 5.88.2(@swc/core@1.3.76)(webpack-cli@4.10.0)
|
||||
|
||||
packages/plugin-stripe:
|
||||
dependencies:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { CollectionConfig } from 'payload/types'
|
||||
import type { CollectionConfig } from '../../../packages/payload/src/collections/config/types'
|
||||
|
||||
const Posts: CollectionConfig = {
|
||||
export const Posts: CollectionConfig = {
|
||||
slug: 'posts',
|
||||
access: {
|
||||
create: () => false,
|
||||
@@ -13,5 +13,3 @@ const Posts: CollectionConfig = {
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export default Posts
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { CollectionConfig } from 'payload/types'
|
||||
import type { CollectionConfig } from '../../../packages/payload/src/collections/config/types'
|
||||
|
||||
const Users: CollectionConfig = {
|
||||
export const Users: CollectionConfig = {
|
||||
slug: 'users',
|
||||
auth: true,
|
||||
admin: {
|
||||
@@ -8,12 +8,9 @@ const Users: CollectionConfig = {
|
||||
},
|
||||
access: {
|
||||
read: () => true,
|
||||
delete: () => false,
|
||||
},
|
||||
fields: [
|
||||
// Email added by default
|
||||
// Add more fields as needed
|
||||
],
|
||||
}
|
||||
|
||||
export default Users
|
||||
32
test/plugin-sentry/config.ts
Normal file
32
test/plugin-sentry/config.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { sentry } from '../../packages/plugin-sentry/src'
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||
import { devUser } from '../credentials'
|
||||
import { Posts } from './collections/Posts'
|
||||
import { Users } from './collections/Users'
|
||||
|
||||
export default buildConfigWithDefaults({
|
||||
collections: [Posts, Users],
|
||||
plugins: [
|
||||
sentry({
|
||||
dsn: 'https://61edebe5ee6d4d38a9d6459c7323d777@o4505289711681536.ingest.sentry.io/4505357688242176',
|
||||
options: {
|
||||
init: {
|
||||
debug: true,
|
||||
},
|
||||
requestHandler: {
|
||||
serverName: false,
|
||||
},
|
||||
captureErrors: [400, 403, 404],
|
||||
},
|
||||
}),
|
||||
],
|
||||
onInit: async (payload) => {
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
data: {
|
||||
email: devUser.email,
|
||||
password: devUser.password,
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
11
test/plugin-sentry/int.spec.ts
Normal file
11
test/plugin-sentry/int.spec.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { initPayloadTest } from '../helpers/configHelpers'
|
||||
|
||||
describe('plugin-sentry', () => {
|
||||
beforeAll(async () => {
|
||||
await initPayloadTest({ __dirname, init: { local: true } })
|
||||
})
|
||||
|
||||
describe('tests', () => {
|
||||
it.todo('plugin-sentry tests')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user