docs: add section on testing providers (#9453)

This commit is contained in:
Shahed Nasser
2024-10-04 10:29:45 +03:00
committed by GitHub
parent aec99b49cc
commit bc8de8e5b1
16 changed files with 597 additions and 391 deletions
@@ -76,6 +76,25 @@ module.exports = defineConfig({
})
\`\`\`
`,
`## 5. Test it Out
To test out your authentication provider, use any of the [Authentication Routes](https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route), using your provider's ID as a path parameter.
For example, to get a registration token for an admin user, send a \`POST\` request to \`/auth/user/my-auth/register\` replacing \`my-auth\` with your authentication provider's ID:
\`\`\`bash
curl -X POST http://localhost:9000/auth/user/my-auth/register
-H 'Content-Type: application/json' \
--data-raw '{
"email": "Whitney_Schultz@gmail.com",
"password": "supersecret"
}'
\`\`\`
Change the request body to pass the data required for your authentication provider to register the user.
If registration is successful, the response will have a \`token\` property.
`,
],
},
}
@@ -81,6 +81,10 @@ module.exports = defineConfig({
}
})
\`\`\`
`,
`## 5. Test it Out
To test out your file provider, use the Medusa Admin or the [Upload API route](https://docs.medusajs.com/v2/api/admin#uploads_postuploads) to upload a file.
`,
],
},
@@ -75,6 +75,15 @@ module.exports = defineConfig({
}
})
\`\`\`
`,
`## 5. Test it Out
Before you use your fulfillment provider, in the Medusa Admin:
1. Add the fulfillment provider to a location.
2. Add in the location a delivery shipping option that uses the provider.
Then, place an order, choosing the shipping option you created during checkout, and create a fulfillment in the Medusa Admin. The fulfillment is created using your provider.
`,
],
},
@@ -86,6 +86,61 @@ module.exports = defineConfig({
}
})
\`\`\`
Make sure to specify the correct channels for your provider in the \`channels\` option.`,
`## 5. Test it Out
### Create Subscriber
To test out the provider, create a subscriber at \`src/subscribers/user-created.ts\` with the following content:
\`\`\`ts title="src/subscribers/user-created.ts"
import { Modules } from "@medusajs/framework/utils"
import {
SubscriberArgs,
type SubscriberConfig,
} from "@medusajs/medusa"
export default async function userCreatedHandler({
event: { data },
container,
}: SubscriberArgs<{ id: string }>) {
const notificationModuleService = container.resolve(
Modules.NOTIFICATION
)
const userModule = container.resolve(
Modules.USER
)
const user = await userModule.retrieveUser(data.id)
await notificationModuleService.createNotifications({
to: user.email,
channel: "email",
template: "new-user"
})
}
export const config: SubscriberConfig = {
event: "user.created",
}
\`\`\`
In the subscriber, you resolve the Notification and User modules. Then, you use the User Module's main service to retrieve the user's details.
Finally, you use the Notification Module's main service to send a notification to the user's email through the \`email\` channel (assuming that's your provider's channel).
Make sure to replace the value of \`template\` to the ID of the template in your provider.
### Create User
Use the following command to create a user:
\`\`\`bash
npx medusa user -e admin@test.com -p supersecret
\`\`\`
After the user is created, the subscriber is executed, sending the notification using your provider.
`,
],
},
@@ -85,6 +85,16 @@ module.exports = defineConfig({
}
})
\`\`\`
`,
`## 5. Test it Out
Before you use your payment provider, enable it in a region using the Medusa Admin.
Then, go through checkout to place an order. Your payment provider is used to authorize the payment.
`,
`## Useful Guides
- [Storefront Guide: how to implement UI for your payment provider during checkout](https://docs.medusajs.com/v2/resources/storefront-development/checkout/payment)
`,
],
},