fix(userapi): подтягивать стоимость VPS Macloud/VDSina из тарифных планов
Docker / build (push) Has been cancelled

При синке UserAPI цена и период берутся по server-plan.id из индекса тарифов, а не остаются нулевыми.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Denozordec
2026-06-29 02:23:34 +07:00
co-authored by Cursor
parent 87ab13e9f6
commit 6c5eb04fae
5 changed files with 186 additions and 12 deletions
+21 -2
View File
@@ -10,12 +10,14 @@ vi.mock('./operations.js', () => ({
fetchServersWithDetails: vi.fn(),
fetchBalance: vi.fn(),
fetchTariffList: vi.fn(),
fetchPlanCostIndex: vi.fn(),
fetchOperations: vi.fn(),
}))
import {
fetchBalance,
fetchOperations,
fetchPlanCostIndex,
fetchServersWithDetails,
fetchTariffList,
} from './operations.js'
@@ -56,7 +58,7 @@ describe('syncFromUserApi', () => {
ip: { ip: '1.2.3.4', type: '4' },
template: { name: 'Debian 12' },
datacenter: { id: 1, name: 'DC1', country: 'ru' },
'server-plan': { name: '2 RAM / 1 CPU / 40 NVMe' },
'server-plan': { id: 13, name: '2 RAM / 1 CPU / 40 NVMe' },
data: { cpu: { value: 1 }, ram: { value: 2 }, disk: { value: 40 } },
},
])
@@ -85,6 +87,19 @@ describe('syncFromUserApi', () => {
price: '1.55 ₽/день',
},
])
vi.mocked(fetchPlanCostIndex).mockResolvedValue(
new Map([
[
'13',
{
id: 13,
name: '2 RAM / 1 CPU / 40 NVMe',
cost: 1.55,
period: 'day',
},
],
]),
)
vi.mocked(fetchOperations).mockResolvedValue([
{
id: 999,
@@ -122,11 +137,15 @@ describe('syncFromUserApi', () => {
expect(result.tariffsCount).toBe(1)
expect(result.balance?.balance).toBe(500)
const vps = getSqlite().prepare('SELECT id, notes FROM vps WHERE id = ?').get('vps-macloud-acc-macloud-100') as {
const vps = getSqlite().prepare('SELECT id, notes, dailyRate, tariffType FROM vps WHERE id = ?').get('vps-macloud-acc-macloud-100') as {
id: string
notes: string
dailyRate: number
tariffType: string
}
expect(vps.notes).toContain('macloud-100')
expect(vps.dailyRate).toBe(1.55)
expect(vps.tariffType).toBe('daily')
})
it('syncs vdsina account with vdsina id prefix', async () => {