|
| 1 | +import { |
| 2 | + calculateEstimatedCredits, |
| 3 | + getTaskTypePricing, |
| 4 | + TRIPO3D_PRICING, |
| 5 | +} from './pricing'; |
| 6 | + |
| 7 | +describe('Tripo3D Pricing', () => { |
| 8 | + describe('calculateEstimatedCredits', () => { |
| 9 | + it('should return base cost for known task types', () => { |
| 10 | + expect(calculateEstimatedCredits('text_to_3d')).toBe(10); |
| 11 | + expect(calculateEstimatedCredits('image_to_3d')).toBe(10); |
| 12 | + expect(calculateEstimatedCredits('refine_model')).toBe(5); |
| 13 | + expect(calculateEstimatedCredits('animate')).toBe(15); |
| 14 | + expect(calculateEstimatedCredits('convert')).toBe(2); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should return default cost for unknown task types', () => { |
| 18 | + expect(calculateEstimatedCredits('unknown_task_type')).toBe(5); |
| 19 | + expect(calculateEstimatedCredits('')).toBe(5); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should add texture quality modifiers', () => { |
| 23 | + expect( |
| 24 | + calculateEstimatedCredits('text_to_3d', { texture_quality: 'standard' }) |
| 25 | + ).toBe(10); |
| 26 | + expect( |
| 27 | + calculateEstimatedCredits('text_to_3d', { texture_quality: 'high' }) |
| 28 | + ).toBe(15); |
| 29 | + expect( |
| 30 | + calculateEstimatedCredits('text_to_3d', { texture_quality: 'ultra' }) |
| 31 | + ).toBe(20); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should add PBR feature modifier', () => { |
| 35 | + expect(calculateEstimatedCredits('text_to_3d', { pbr: true })).toBe(12); |
| 36 | + expect(calculateEstimatedCredits('text_to_3d', { pbr: false })).toBe(10); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should add quad topology modifier', () => { |
| 40 | + expect(calculateEstimatedCredits('text_to_3d', { quad: true })).toBe(13); |
| 41 | + expect(calculateEstimatedCredits('text_to_3d', { quad: false })).toBe(10); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should add animation modifiers', () => { |
| 45 | + expect( |
| 46 | + calculateEstimatedCredits('text_to_3d', { with_animation: true }) |
| 47 | + ).toBe(15); |
| 48 | + expect( |
| 49 | + calculateEstimatedCredits('text_to_3d', { bake_animation: true }) |
| 50 | + ).toBe(12); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should add texture processing modifiers', () => { |
| 54 | + expect(calculateEstimatedCredits('text_to_3d', { pack_uv: true })).toBe( |
| 55 | + 11 |
| 56 | + ); |
| 57 | + expect(calculateEstimatedCredits('text_to_3d', { bake: true })).toBe(12); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should combine multiple modifiers', () => { |
| 61 | + const params = { |
| 62 | + texture_quality: 'high', |
| 63 | + pbr: true, |
| 64 | + quad: true, |
| 65 | + with_animation: true, |
| 66 | + pack_uv: true, |
| 67 | + bake: true, |
| 68 | + }; |
| 69 | + // base (10) + high quality (5) + pbr (2) + quad (3) + animation (5) + pack_uv (1) + bake (2) = 28 |
| 70 | + expect(calculateEstimatedCredits('text_to_3d', params)).toBe(28); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should return minimum of 1 credit', () => { |
| 74 | + // Even if we had a task with 0 base cost, it should return at least 1 |
| 75 | + const zeroBaseCost = { ...TRIPO3D_PRICING }; |
| 76 | + zeroBaseCost.baseCosts.test_task = 0; |
| 77 | + |
| 78 | + // Our current minimum is handled in the function |
| 79 | + expect(calculateEstimatedCredits('test_task')).toBe(5); // Returns default |
| 80 | + }); |
| 81 | + |
| 82 | + it('should handle empty parameters object', () => { |
| 83 | + expect(calculateEstimatedCredits('text_to_3d', {})).toBe(10); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should ignore unknown parameters', () => { |
| 87 | + const params = { |
| 88 | + unknown_param: true, |
| 89 | + another_unknown: 'value', |
| 90 | + texture_quality: 'high', |
| 91 | + }; |
| 92 | + expect(calculateEstimatedCredits('text_to_3d', params)).toBe(15); // base + high quality only |
| 93 | + }); |
| 94 | + }); |
| 95 | + |
| 96 | + describe('getTaskTypePricing', () => { |
| 97 | + it('should return pricing info for known task types', () => { |
| 98 | + const pricing = getTaskTypePricing('text_to_3d'); |
| 99 | + expect(pricing).toEqual({ |
| 100 | + taskType: 'text_to_3d', |
| 101 | + baseCost: 10, |
| 102 | + availableModifiers: expect.arrayContaining([ |
| 103 | + 'pbr', |
| 104 | + 'quad', |
| 105 | + 'with_animation', |
| 106 | + ]), |
| 107 | + textureQualityOptions: expect.arrayContaining([ |
| 108 | + 'standard', |
| 109 | + 'high', |
| 110 | + 'ultra', |
| 111 | + ]), |
| 112 | + }); |
| 113 | + }); |
| 114 | + |
| 115 | + it('should return default pricing for unknown task types', () => { |
| 116 | + const pricing = getTaskTypePricing('unknown_task'); |
| 117 | + expect(pricing).toEqual({ |
| 118 | + taskType: 'unknown_task', |
| 119 | + baseCost: 5, |
| 120 | + availableModifiers: expect.arrayContaining([ |
| 121 | + 'pbr', |
| 122 | + 'quad', |
| 123 | + 'with_animation', |
| 124 | + ]), |
| 125 | + textureQualityOptions: expect.arrayContaining([ |
| 126 | + 'standard', |
| 127 | + 'high', |
| 128 | + 'ultra', |
| 129 | + ]), |
| 130 | + }); |
| 131 | + }); |
| 132 | + }); |
| 133 | + |
| 134 | + describe('TRIPO3D_PRICING configuration', () => { |
| 135 | + it('should have all required pricing sections', () => { |
| 136 | + expect(TRIPO3D_PRICING).toHaveProperty('baseCosts'); |
| 137 | + expect(TRIPO3D_PRICING).toHaveProperty('modifiers'); |
| 138 | + expect(TRIPO3D_PRICING.modifiers).toHaveProperty('texture_quality'); |
| 139 | + expect(TRIPO3D_PRICING.modifiers).toHaveProperty('features'); |
| 140 | + }); |
| 141 | + |
| 142 | + it('should have default task type', () => { |
| 143 | + expect(TRIPO3D_PRICING.baseCosts).toHaveProperty('default'); |
| 144 | + expect(typeof TRIPO3D_PRICING.baseCosts.default).toBe('number'); |
| 145 | + }); |
| 146 | + |
| 147 | + it('should have standard texture quality as baseline', () => { |
| 148 | + expect(TRIPO3D_PRICING.modifiers.texture_quality).toHaveProperty( |
| 149 | + 'standard' |
| 150 | + ); |
| 151 | + expect(TRIPO3D_PRICING.modifiers.texture_quality.standard).toBe(0); |
| 152 | + }); |
| 153 | + }); |
| 154 | +}); |
0 commit comments