|
| 1 | +import { |
| 2 | + AddProductVariantOperation, |
| 3 | + AddProductVariantOperationSchema, |
| 4 | + DeleteProductVariantOperation, |
| 5 | + DeleteProductVariantOperationSchema, |
| 6 | + UpdateProductVariantOperation, |
| 7 | + UpdateProductVariantOperationSchema, |
| 8 | + UpsertProductVariantOperation, |
| 9 | + UpsertProductVariantOperationSchema, |
| 10 | +} from '../../src/mass-operation/product-variant'; |
| 11 | +import { describe, expect, it } from 'vitest'; |
| 12 | + |
| 13 | +describe('Mass Operations - Product Variant', {}, async () => { |
| 14 | + it('accepts a minimal add variant operation', () => { |
| 15 | + const operation: AddProductVariantOperation = { |
| 16 | + intent: 'product/variant/create', |
| 17 | + language: 'en', |
| 18 | + productId: '604f7655a16b91dea030895b', |
| 19 | + sku: 'sku-1', |
| 20 | + name: 'Variant 1', |
| 21 | + }; |
| 22 | + expect(AddProductVariantOperationSchema.safeParse(operation)).toEqual({ |
| 23 | + success: true, |
| 24 | + data: operation, |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + it('accepts an add variant operation with references', () => { |
| 29 | + const operation: AddProductVariantOperation = { |
| 30 | + intent: 'product/variant/create', |
| 31 | + language: 'en', |
| 32 | + productId: '604f7655a16b91dea030895b', |
| 33 | + sku: 'sku-1', |
| 34 | + name: 'Variant 1', |
| 35 | + isDefault: true, |
| 36 | + attributes: [{ attribute: 'color', value: 'red' }], |
| 37 | + priceVariants: [{ identifier: 'default', price: 19.99 }], |
| 38 | + stockLocations: [{ identifier: 'warehouse-eu', stock: 10 }], |
| 39 | + }; |
| 40 | + expect(AddProductVariantOperationSchema.safeParse(operation).success).toBe(true); |
| 41 | + }); |
| 42 | + |
| 43 | + it('rejects an add variant operation without sku', () => { |
| 44 | + const invalid = { |
| 45 | + intent: 'product/variant/create', |
| 46 | + language: 'en', |
| 47 | + productId: '604f7655a16b91dea030895b', |
| 48 | + name: 'Variant 1', |
| 49 | + }; |
| 50 | + expect(AddProductVariantOperationSchema.safeParse(invalid).success).toBe(false); |
| 51 | + }); |
| 52 | + |
| 53 | + it('rejects an add variant operation without productId', () => { |
| 54 | + const invalid = { |
| 55 | + intent: 'product/variant/create', |
| 56 | + language: 'en', |
| 57 | + sku: 'sku-1', |
| 58 | + name: 'Variant 1', |
| 59 | + }; |
| 60 | + expect(AddProductVariantOperationSchema.safeParse(invalid).success).toBe(false); |
| 61 | + }); |
| 62 | + |
| 63 | + it('accepts a partial update variant operation', () => { |
| 64 | + const operation: UpdateProductVariantOperation = { |
| 65 | + intent: 'product/variant/update', |
| 66 | + language: 'en', |
| 67 | + sku: 'sku-1', |
| 68 | + priceVariants: [{ identifier: 'default', price: 24.99 }], |
| 69 | + }; |
| 70 | + expect(UpdateProductVariantOperationSchema.safeParse(operation)).toEqual({ |
| 71 | + success: true, |
| 72 | + data: operation, |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + it('rejects an update variant operation without sku', () => { |
| 77 | + const invalid = { |
| 78 | + intent: 'product/variant/update', |
| 79 | + language: 'en', |
| 80 | + name: 'New name', |
| 81 | + }; |
| 82 | + expect(UpdateProductVariantOperationSchema.safeParse(invalid).success).toBe(false); |
| 83 | + }); |
| 84 | + |
| 85 | + it('accepts a minimal upsert variant operation', () => { |
| 86 | + const operation: UpsertProductVariantOperation = { |
| 87 | + intent: 'product/variant/upsert', |
| 88 | + language: 'en', |
| 89 | + productId: '604f7655a16b91dea030895b', |
| 90 | + sku: 'sku-1', |
| 91 | + name: 'Variant 1', |
| 92 | + }; |
| 93 | + expect(UpsertProductVariantOperationSchema.safeParse(operation)).toEqual({ |
| 94 | + success: true, |
| 95 | + data: operation, |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + it('rejects an upsert variant operation without sku', () => { |
| 100 | + const invalid = { |
| 101 | + intent: 'product/variant/upsert', |
| 102 | + language: 'en', |
| 103 | + productId: '604f7655a16b91dea030895b', |
| 104 | + name: 'Variant 1', |
| 105 | + }; |
| 106 | + expect(UpsertProductVariantOperationSchema.safeParse(invalid).success).toBe(false); |
| 107 | + }); |
| 108 | + |
| 109 | + it('accepts a delete variant operation', () => { |
| 110 | + const operation: DeleteProductVariantOperation = { |
| 111 | + intent: 'product/variant/delete', |
| 112 | + sku: 'sku-1', |
| 113 | + }; |
| 114 | + expect(DeleteProductVariantOperationSchema.safeParse(operation)).toEqual({ |
| 115 | + success: true, |
| 116 | + data: operation, |
| 117 | + }); |
| 118 | + }); |
| 119 | + |
| 120 | + it('rejects a delete variant operation without sku', () => { |
| 121 | + const invalid = { intent: 'product/variant/delete' }; |
| 122 | + expect(DeleteProductVariantOperationSchema.safeParse(invalid).success).toBe(false); |
| 123 | + }); |
| 124 | +}); |
0 commit comments