Criar somente a automação backend em Node.js para integrar Hotmart → Webhook → Banco → Fluxos de e-mail e status, para uso dentro da minha plataforma já existente Zeyra (não criar frontend, sistema, telas nem painel).
848f927 verified Download tests/webhook.test.js from fernandosliborioo/hotmartflow-integrator: direct link, hf CLI and curl.
- Browser
- Download file 2.81 kB
-
https://huggingface.co/spaces/fernandosliborioo/hotmartflow-integrator/resolve/main/tests/webhook.test.js
- Command line
-
hf download hf://spaces/fernandosliborioo/hotmartflow-integrator/tests/webhook.test.js
-
curl -L -o webhook.test.js https://huggingface.co/spaces/fernandosliborioo/hotmartflow-integrator/resolve/main/tests/webhook.test.js
2.81 kB
| const request = require('supertest'); | |
| const { PrismaClient } = require('@prisma/client'); | |
| const app = require('../src/server'); | |
| const prisma = new PrismaClient(); | |
| describe('Hotmart Webhook Integration', () => { | |
| beforeEach(async () => { | |
| // Clean up database before each test | |
| await prisma.webhookLog.deleteMany(); | |
| await prisma.user.deleteMany(); | |
| }); | |
| afterAll(async () => { | |
| await prisma.$disconnect(); | |
| }); | |
| describe('POST /api/webhook/hotmart', () => { | |
| it('should reject request with invalid token', async () => { | |
| const response = await request(app) | |
| .post('/api/webhook/hotmart') | |
| .set('x-hotmart-hottok', 'invalid-token') | |
| .send({ | |
| event: 'approved', | |
| data: { | |
| buyer: { email: 'test@example.com', name: 'Test User' }, | |
| product: { name: 'Premium Plan' }, | |
| purchase: { transaction: '12345', approved_date: new Date().toISOString() } | |
| } | |
| }); | |
| expect(response.status).toBe(403); | |
| }); | |
| it('should process approved event and create user', async () => { | |
| const mockPayload = { | |
| event: 'approved', | |
| data: { | |
| buyer: { email: 'newuser@example.com', name: 'New User' }, | |
| product: { name: 'Premium Plan' }, | |
| purchase: { transaction: 'TRANS123', approved_date: new Date().toISOString() } | |
| } | |
| }; | |
| const response = await request(app) | |
| .post('/api/webhook/hotmart') | |
| .set('x-hotmart-hottok', process.env.HOTMART_WEBHOOK_TOKEN) | |
| .send(mockPayload); | |
| expect(response.status).toBe(200); | |
| // Check if user was created | |
| const user = await prisma.user.findUnique({ | |
| where: { email: 'newuser@example.com' } | |
| }); | |
| expect(user).toBeTruthy(); | |
| expect(user.status).toBe('active'); | |
| expect(user.plan).toBe('Premium Plan'); | |
| }); | |
| it('should process canceled event and block user', async () => { | |
| // First create a user | |
| await prisma.user.create({ | |
| data: { | |
| email: 'existing@example.com', | |
| name: 'Existing User', | |
| password: 'hashedpassword', | |
| status: 'active' | |
| } | |
| }); | |
| const mockPayload = { | |
| event: 'canceled', | |
| data: { | |
| buyer: { email: 'existing@example.com' }, | |
| purchase: { transaction: 'TRANS123' } | |
| } | |
| }; | |
| const response = await request(app) | |
| .post('/api/webhook/hotmart') | |
| .set('x-hotmart-hottok', process.env.HOTMART_WEBHOOK_TOKEN) | |
| .send(mockPayload); | |
| expect(response.status).toBe(200); | |
| // Check if user was blocked | |
| const user = await prisma.user.findUnique({ | |
| where: { email: 'existing@example.com' } | |
| }); | |
| expect(user.status).toBe('blocked'); | |
| }); | |
| }); | |
| }); |