chore: fix prettier formatting
This commit is contained in:
@@ -166,9 +166,7 @@ describe('yookassa getPayment', () => {
|
|||||||
describe('yookassa buildReceipt', () => {
|
describe('yookassa buildReceipt', () => {
|
||||||
it('builds receipt with order items', () => {
|
it('builds receipt with order items', () => {
|
||||||
const result = buildReceipt({
|
const result = buildReceipt({
|
||||||
orderItems: [
|
orderItems: [{ titleSnapshot: 'Test Product', qty: 2, priceCentsSnapshot: 100000 }],
|
||||||
{ titleSnapshot: 'Test Product', qty: 2, priceCentsSnapshot: 100000 },
|
|
||||||
],
|
|
||||||
deliveryFeeCents: 0,
|
deliveryFeeCents: 0,
|
||||||
userEmail: 'user@test.ru',
|
userEmail: 'user@test.ru',
|
||||||
})
|
})
|
||||||
@@ -187,9 +185,7 @@ describe('yookassa buildReceipt', () => {
|
|||||||
|
|
||||||
it('adds delivery item when deliveryFeeCents > 0', () => {
|
it('adds delivery item when deliveryFeeCents > 0', () => {
|
||||||
const result = buildReceipt({
|
const result = buildReceipt({
|
||||||
orderItems: [
|
orderItems: [{ titleSnapshot: 'Item A', qty: 1, priceCentsSnapshot: 50000 }],
|
||||||
{ titleSnapshot: 'Item A', qty: 1, priceCentsSnapshot: 50000 },
|
|
||||||
],
|
|
||||||
deliveryFeeCents: 35000,
|
deliveryFeeCents: 35000,
|
||||||
userEmail: 'user@test.ru',
|
userEmail: 'user@test.ru',
|
||||||
})
|
})
|
||||||
@@ -202,9 +198,7 @@ describe('yookassa buildReceipt', () => {
|
|||||||
|
|
||||||
it('passes through taxSystemCode', () => {
|
it('passes through taxSystemCode', () => {
|
||||||
const result = buildReceipt({
|
const result = buildReceipt({
|
||||||
orderItems: [
|
orderItems: [{ titleSnapshot: 'Item', qty: 1, priceCentsSnapshot: 1000 }],
|
||||||
{ titleSnapshot: 'Item', qty: 1, priceCentsSnapshot: 1000 },
|
|
||||||
],
|
|
||||||
deliveryFeeCents: 0,
|
deliveryFeeCents: 0,
|
||||||
userEmail: 'user@test.ru',
|
userEmail: 'user@test.ru',
|
||||||
taxSystemCode: 3,
|
taxSystemCode: 3,
|
||||||
@@ -241,15 +235,11 @@ describe('yookassa validateWebhook', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('throws if missing event', () => {
|
it('throws if missing event', () => {
|
||||||
expect(() => validateWebhook('127.0.0.1', { type: 'notification', object: {} })).toThrow(
|
expect(() => validateWebhook('127.0.0.1', { type: 'notification', object: {} })).toThrow('Missing event or object')
|
||||||
'Missing event or object',
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws if missing object', () => {
|
it('throws if missing object', () => {
|
||||||
expect(() => validateWebhook('127.0.0.1', { type: 'notification', event: 'x' })).toThrow(
|
expect(() => validateWebhook('127.0.0.1', { type: 'notification', event: 'x' })).toThrow('Missing event or object')
|
||||||
'Missing event or object',
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws for invalid body type', () => {
|
it('throws for invalid body type', () => {
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ function isYookassaIp(ip) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isTestMode() {
|
function isTestMode() {
|
||||||
return (process.env.YOOKASSA_SECRET_KEY?.startsWith('test_')) ?? false
|
return process.env.YOOKASSA_SECRET_KEY?.startsWith('test_') ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateWebhook(ip, body) {
|
export function validateWebhook(ip, body) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
||||||
import Fastify from 'fastify'
|
|
||||||
import jwt from '@fastify/jwt'
|
import jwt from '@fastify/jwt'
|
||||||
|
import Fastify from 'fastify'
|
||||||
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import { prisma } from '../../lib/prisma.js'
|
import { prisma } from '../../lib/prisma.js'
|
||||||
import { registerUserPaymentRoutes } from '../user-payments.js'
|
import { registerUserPaymentRoutes } from '../user-payments.js'
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
||||||
import Fastify from 'fastify'
|
import Fastify from 'fastify'
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import { NOTIFICATION_EVENTS } from '../../../../shared/constants/notification-events.js'
|
import { NOTIFICATION_EVENTS } from '../../../../shared/constants/notification-events.js'
|
||||||
|
|
||||||
const { mockPrisma } = vi.hoisted(() => ({
|
const { mockPrisma } = vi.hoisted(() => ({
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ import { prisma } from '../lib/prisma.js'
|
|||||||
import { createPayment, buildReceipt, getPayment } from '../lib/yookassa.js'
|
import { createPayment, buildReceipt, getPayment } from '../lib/yookassa.js'
|
||||||
|
|
||||||
export async function registerUserPaymentRoutes(fastify) {
|
export async function registerUserPaymentRoutes(fastify) {
|
||||||
fastify.post(
|
fastify.post('/api/me/orders/:id/pay', { preHandler: [fastify.authenticate] }, async (request, reply) => {
|
||||||
'/api/me/orders/:id/pay',
|
|
||||||
{ preHandler: [fastify.authenticate] },
|
|
||||||
async (request, reply) => {
|
|
||||||
const userId = request.user.sub
|
const userId = request.user.sub
|
||||||
const userEmail = request.user.email
|
const userEmail = request.user.email
|
||||||
|
|
||||||
@@ -93,13 +90,9 @@ export async function registerUserPaymentRoutes(fastify) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return { confirmationUrl: result.confirmationUrl }
|
return { confirmationUrl: result.confirmationUrl }
|
||||||
},
|
})
|
||||||
)
|
|
||||||
|
|
||||||
fastify.get(
|
fastify.get('/api/me/orders/:orderId/payment', { preHandler: [fastify.authenticate] }, async (request, reply) => {
|
||||||
'/api/me/orders/:orderId/payment',
|
|
||||||
{ preHandler: [fastify.authenticate] },
|
|
||||||
async (request, reply) => {
|
|
||||||
const userId = request.user.sub
|
const userId = request.user.sub
|
||||||
const { orderId } = request.params
|
const { orderId } = request.params
|
||||||
|
|
||||||
@@ -146,6 +139,5 @@ export async function registerUserPaymentRoutes(fastify) {
|
|||||||
} catch {
|
} catch {
|
||||||
return { status: payment.status, paid: payment.status === 'succeeded' }
|
return { status: payment.status, paid: payment.status === 'succeeded' }
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { prisma } from '../lib/prisma.js'
|
|
||||||
import { NOTIFICATION_EVENTS } from '../../../shared/constants/notification-events.js'
|
import { NOTIFICATION_EVENTS } from '../../../shared/constants/notification-events.js'
|
||||||
|
import { prisma } from '../lib/prisma.js'
|
||||||
import { validateWebhook } from '../lib/yookassa.js'
|
import { validateWebhook } from '../lib/yookassa.js'
|
||||||
|
|
||||||
export async function registerYookassaWebhookRoute(fastify) {
|
export async function registerYookassaWebhookRoute(fastify) {
|
||||||
|
|||||||
Reference in New Issue
Block a user