letsbe-hub/src/__tests__/fixtures/orders.ts

247 lines
7.2 KiB
TypeScript

import { Order, OrderStatus, AutomationMode, LogLevel, ProvisioningLog, SubscriptionTier } from '@prisma/client'
import { customerUser, customerUser2 } from './users'
// Payment confirmed order (just created)
export const paymentConfirmedOrder: Order = {
id: 'order-001',
userId: customerUser.id,
domain: 'test.letsbe.cloud',
tier: SubscriptionTier.HUB_DASHBOARD,
status: OrderStatus.PAYMENT_CONFIRMED,
automationMode: AutomationMode.MANUAL,
serverIp: null,
serverPasswordEncrypted: null,
sshPort: 22,
netcupServerId: null,
tools: ['orchestrator', 'sysadmin-agent'],
configJson: {},
failureReason: null,
provisioningStartedAt: null,
completedAt: null,
customer: 'Test Customer',
companyName: 'Test Company',
licenseKey: null,
automationPausedAt: null,
automationPausedReason: null,
source: null,
portainerUrl: null,
dashboardUrl: null,
portainerUsername: null,
portainerPasswordEnc: null,
credentialsSyncedAt: null,
serverReadyAt: null,
dnsVerifiedAt: null,
createdAt: new Date('2024-01-20T10:00:00Z'),
updatedAt: new Date('2024-01-20T10:00:00Z'),
}
// Server ready order
export const serverReadyOrder: Order = {
id: 'order-002',
userId: customerUser.id,
domain: 'ready.letsbe.cloud',
tier: SubscriptionTier.ADVANCED,
status: OrderStatus.SERVER_READY,
automationMode: AutomationMode.MANUAL,
serverIp: '192.168.1.100',
serverPasswordEncrypted: 'encrypted-password-here',
sshPort: 22,
netcupServerId: 'netcup-12345',
tools: ['orchestrator', 'sysadmin-agent', 'nextcloud'],
configJson: {},
failureReason: null,
provisioningStartedAt: null,
completedAt: null,
customer: 'Test Customer',
companyName: 'Test Company',
licenseKey: null,
automationPausedAt: null,
automationPausedReason: null,
source: null,
portainerUrl: null,
dashboardUrl: null,
portainerUsername: null,
portainerPasswordEnc: null,
credentialsSyncedAt: null,
serverReadyAt: new Date('2024-01-21T12:00:00Z'),
dnsVerifiedAt: null,
createdAt: new Date('2024-01-21T10:00:00Z'),
updatedAt: new Date('2024-01-21T14:00:00Z'),
}
// Order currently provisioning
export const provisioningOrder: Order = {
id: 'order-003',
userId: customerUser.id,
domain: 'provisioning.letsbe.cloud',
tier: SubscriptionTier.ADVANCED,
status: OrderStatus.PROVISIONING,
automationMode: AutomationMode.MANUAL,
serverIp: '192.168.1.101',
serverPasswordEncrypted: 'encrypted-password-here',
sshPort: 22,
netcupServerId: 'netcup-12346',
tools: ['orchestrator', 'sysadmin-agent', 'nextcloud', 'keycloak'],
configJson: {},
failureReason: null,
provisioningStartedAt: new Date('2024-01-22T10:00:00Z'),
completedAt: null,
customer: 'Test Customer',
companyName: 'Test Company',
licenseKey: 'lb_inst_abc123',
automationPausedAt: null,
automationPausedReason: null,
source: null,
portainerUrl: null,
dashboardUrl: null,
portainerUsername: null,
portainerPasswordEnc: null,
credentialsSyncedAt: null,
serverReadyAt: new Date('2024-01-22T09:30:00Z'),
dnsVerifiedAt: null,
createdAt: new Date('2024-01-22T09:00:00Z'),
updatedAt: new Date('2024-01-22T10:00:00Z'),
}
// Successfully fulfilled order
export const fulfilledOrder: Order = {
id: 'order-004',
userId: customerUser2.id,
domain: 'complete.letsbe.cloud',
tier: SubscriptionTier.HUB_DASHBOARD,
status: OrderStatus.FULFILLED,
automationMode: AutomationMode.MANUAL,
serverIp: '192.168.1.102',
serverPasswordEncrypted: null, // Cleared after provisioning
sshPort: 22022, // Updated after provisioning
netcupServerId: 'netcup-12347',
tools: ['orchestrator', 'sysadmin-agent'],
configJson: {},
failureReason: null,
provisioningStartedAt: new Date('2024-01-19T10:00:00Z'),
completedAt: new Date('2024-01-19T10:30:00Z'),
customer: 'Another Customer',
companyName: 'Another Company',
licenseKey: 'lb_inst_def456',
automationPausedAt: null,
automationPausedReason: null,
source: null,
portainerUrl: 'https://portainer.complete.letsbe.cloud',
dashboardUrl: 'https://dashboard.complete.letsbe.cloud',
portainerUsername: 'admin-complete',
portainerPasswordEnc: 'encrypted-portainer-password',
credentialsSyncedAt: new Date('2024-01-19T10:30:00Z'),
serverReadyAt: new Date('2024-01-19T09:30:00Z'),
dnsVerifiedAt: new Date('2024-01-19T09:45:00Z'),
createdAt: new Date('2024-01-19T09:00:00Z'),
updatedAt: new Date('2024-01-19T10:30:00Z'),
}
// Failed order
export const failedOrder: Order = {
id: 'order-005',
userId: customerUser.id,
domain: 'failed.letsbe.cloud',
tier: SubscriptionTier.ADVANCED,
status: OrderStatus.FAILED,
automationMode: AutomationMode.MANUAL,
serverIp: '192.168.1.103',
serverPasswordEncrypted: 'encrypted-password-here',
sshPort: 22,
netcupServerId: 'netcup-12348',
tools: ['orchestrator', 'sysadmin-agent'],
configJson: {},
failureReason: 'SSH connection timeout after 3 retries',
provisioningStartedAt: new Date('2024-01-18T10:00:00Z'),
completedAt: null,
customer: 'Test Customer',
companyName: 'Test Company',
licenseKey: null,
automationPausedAt: null,
automationPausedReason: null,
source: null,
portainerUrl: null,
dashboardUrl: null,
portainerUsername: null,
portainerPasswordEnc: null,
credentialsSyncedAt: null,
serverReadyAt: new Date('2024-01-18T09:30:00Z'),
dnsVerifiedAt: null,
createdAt: new Date('2024-01-18T09:00:00Z'),
updatedAt: new Date('2024-01-18T10:15:00Z'),
}
// All orders
export const allOrders: Order[] = [
paymentConfirmedOrder,
serverReadyOrder,
provisioningOrder,
fulfilledOrder,
failedOrder,
]
// Sample provisioning logs
export const provisioningLogs: ProvisioningLog[] = [
{
id: 'log-001',
orderId: provisioningOrder.id,
level: LogLevel.INFO,
message: 'Starting provisioning for provisioning.letsbe.cloud',
step: 'init',
timestamp: new Date('2024-01-22T10:00:00Z'),
},
{
id: 'log-002',
orderId: provisioningOrder.id,
level: LogLevel.INFO,
message: 'SSH connection established',
step: 'ssh-connect',
timestamp: new Date('2024-01-22T10:00:05Z'),
},
{
id: 'log-003',
orderId: provisioningOrder.id,
level: LogLevel.INFO,
message: 'Running server hardening playbook',
step: 'hardening',
timestamp: new Date('2024-01-22T10:00:10Z'),
},
]
// Factory function for creating custom orders
export function createOrder(overrides: Partial<Order> = {}): Order {
return {
id: `order-${Date.now()}`,
userId: customerUser.id,
domain: `test-${Date.now()}.letsbe.cloud`,
tier: SubscriptionTier.HUB_DASHBOARD,
status: OrderStatus.PAYMENT_CONFIRMED,
automationMode: AutomationMode.MANUAL,
serverIp: null,
serverPasswordEncrypted: null,
sshPort: 22,
netcupServerId: null,
tools: ['orchestrator', 'sysadmin-agent'],
configJson: {},
failureReason: null,
provisioningStartedAt: null,
completedAt: null,
customer: 'Test Customer',
companyName: 'Test Company',
licenseKey: null,
automationPausedAt: null,
automationPausedReason: null,
source: null,
portainerUrl: null,
dashboardUrl: null,
portainerUsername: null,
portainerPasswordEnc: null,
credentialsSyncedAt: null,
serverReadyAt: null,
dnsVerifiedAt: null,
createdAt: new Date(),
updatedAt: new Date(),
...overrides,
}
}