Fix/alpha/int tests (#5311)

* chore: converts dynamic imports to esm require

* chore: adjusts require and import usage

* chore: reverts bin script change

* chore: adjust dataloaded tests to use slate editor

* fix: converts custom auth strategy

* chore: fixes to form builder int test config

* chore: adjusts plugin-stripe and int tests

---------

Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
This commit is contained in:
Dan Ribbens
2024-03-12 16:27:43 -04:00
committed by GitHub
parent 8436dd5851
commit 04fcf57d0a
18 changed files with 202 additions and 253 deletions

View File

@@ -5,10 +5,9 @@ import { customersSlug } from '../shared.js'
export const Customers: CollectionConfig = {
slug: customersSlug,
timestamps: true,
admin: {
useAsTitle: 'email',
defaultColumns: ['email', 'name'],
useAsTitle: 'email',
},
auth: {
useAPIKey: true,
@@ -16,12 +15,11 @@ export const Customers: CollectionConfig = {
fields: [
{
name: 'name',
label: 'Name',
type: 'text',
label: 'Name',
},
{
name: 'subscriptions',
label: 'Subscriptions',
type: 'array',
admin: {
description:
@@ -30,7 +28,6 @@ export const Customers: CollectionConfig = {
fields: [
{
name: 'link',
label: 'Link',
type: 'ui',
admin: {
components: {
@@ -38,43 +35,44 @@ export const Customers: CollectionConfig = {
LinkToDoc({
...args,
isTestKey: process.env.PAYLOAD_PUBLIC_IS_STRIPE_TEST_KEY === 'true',
stripeResourceType: 'subscriptions',
nameOfIDField: `${args.path}.stripeSubscriptionID`,
stripeResourceType: 'subscriptions',
}),
},
},
label: 'Link',
},
{
name: 'stripeSubscriptionID',
label: 'Stripe ID',
type: 'text',
admin: {
readOnly: true,
},
label: 'Stripe ID',
},
{
name: 'stripeProductID',
label: 'Product ID',
type: 'text',
admin: {
readOnly: true,
},
label: 'Product ID',
},
{
name: 'product',
type: 'relationship',
relationTo: 'products',
admin: {
readOnly: true,
},
relationTo: 'products',
},
{
name: 'status',
label: 'Status',
type: 'select',
admin: {
readOnly: true,
},
label: 'Status',
options: [
{
label: 'Active',
@@ -107,6 +105,8 @@ export const Customers: CollectionConfig = {
],
},
],
label: 'Subscriptions',
},
],
timestamps: true,
}

View File

@@ -4,36 +4,36 @@ import { productsSlug } from '../shared.js'
export const Products: CollectionConfig = {
slug: productsSlug,
timestamps: true,
admin: {
defaultColumns: ['name'],
},
fields: [
{
name: 'name',
label: 'Name',
type: 'text',
label: 'Name',
},
{
name: 'price',
label: 'Price',
type: 'group',
admin: {
readOnly: true,
description: 'All pricing information is managed in Stripe and will be reflected here.',
readOnly: true,
},
fields: [
{
name: 'stripePriceID',
label: 'Stripe Price ID',
type: 'text',
label: 'Stripe Price ID',
},
{
name: 'stripeJSON',
label: 'Stripe JSON',
type: 'textarea',
label: 'Stripe JSON',
},
],
label: 'Price',
},
],
timestamps: true,
}

View File

@@ -2,13 +2,13 @@ import type { CollectionConfig } from '../../../packages/payload/src/collections
export const Users: CollectionConfig = {
slug: 'users',
auth: true,
admin: {
useAsTitle: 'email',
},
access: {
read: () => true,
},
admin: {
useAsTitle: 'email',
},
auth: true,
fields: [
{
name: 'name',

View File

@@ -32,14 +32,14 @@ export default buildConfigWithDefaults({
},
plugins: [
stripePlugin({
stripeSecretKey: process.env.STRIPE_SECRET_KEY,
isTestKey: true,
logs: true,
rest: false,
stripeSecretKey: process.env.STRIPE_SECRET_KEY,
stripeWebhooksEndpointSecret: process.env.STRIPE_WEBHOOKS_ENDPOINT_SECRET,
sync: [
{
collection: 'customers',
stripeResourceType: 'customers',
stripeResourceTypeSingular: 'customer',
fields: [
{
fieldPath: 'name',
@@ -57,11 +57,11 @@ export default buildConfigWithDefaults({
// property: 'plan.name',
// }
],
stripeResourceType: 'customers',
stripeResourceTypeSingular: 'customer',
},
{
collection: 'products',
stripeResourceType: 'products',
stripeResourceTypeSingular: 'product',
fields: [
{
fieldPath: 'name',
@@ -72,17 +72,17 @@ export default buildConfigWithDefaults({
stripeProperty: 'default_price',
},
],
stripeResourceType: 'products',
stripeResourceTypeSingular: 'product',
},
],
rest: false,
webhooks: {
'customer.subscription.created': subscriptionCreatedOrUpdated,
'customer.subscription.updated': subscriptionCreatedOrUpdated,
'customer.subscription.deleted': subscriptionDeleted,
'customer.subscription.updated': subscriptionCreatedOrUpdated,
'product.created': syncPriceJSON,
'product.updated': syncPriceJSON,
},
stripeWebhooksEndpointSecret: process.env.STRIPE_WEBHOOKS_ENDPOINT_SECRET,
}),
],
})

View File

@@ -1,4 +0,0 @@
module.exports = {
raw: () => {},
url: () => {},
}

View File

@@ -1 +0,0 @@
module.exports = {}

View File

@@ -72,28 +72,28 @@ export const subscriptionCreatedOrUpdated = async (args) => {
payload.logger.info(`- Subscription already exists, now updating.`)
// update existing subscription
subscriptions[indexOfSubscription] = {
stripeProductID: plan.product,
product: payloadProductID,
status: subscriptionStatus,
stripeProductID: plan.product,
}
} else {
payload.logger.info(`- This is a new subscription, now adding.`)
// create new subscription
subscriptions.push({
stripeSubscriptionID: eventID,
stripeProductID: plan.product,
product: payloadProductID,
status: subscriptionStatus,
stripeProductID: plan.product,
stripeSubscriptionID: eventID,
})
}
try {
await payload.update({
collection: 'customers',
id: foundCustomer.id,
collection: 'customers',
data: {
subscriptions,
skipSync: true,
subscriptions,
},
})

View File

@@ -49,11 +49,11 @@ export const subscriptionDeleted = async (args) => {
try {
await payload.update({
collection: 'customers',
id: foundCustomer.id,
collection: 'customers',
data: {
subscriptions,
skipSync: true,
subscriptions,
},
})

View File

@@ -41,8 +41,8 @@ export const syncPriceJSON = async (args) => {
const stripePrice = await stripe.prices.retrieve(default_price)
await payload.update({
collection: 'products',
id: payloadProductID,
collection: 'products',
data: {
price: {
stripeJSON: JSON.stringify(stripePrice),