import { getCustomRepository } from 'typeorm'; import { AggregateProductVariant } from '@/entities'; import { AggregateProductRepository } from '@/repositories/AggregateProductRepository'; import AggregateProductVariantRepository from '../AggregateProductVariantRepository'; describe('AggregateProductVariantRepository', () => { it('should be able to create new populated aggregate product variant', async () => { const aggregateProductRepo = getCustomRepository( AggregateProductRepository ); const aggregateProductVariantRepo = getCustomRepository( AggregateProductVariantRepository ); await aggregateProductRepo.upsert({ identifiers: ['test'], data: { asin: 'asin', colorCode: 'colorCode', annotations: 'annotation', price: 100, description: 'description', dimensions: 'dimensions', discoverable: true, distributor: 'distributor', distributorSKU: 'distributor', imageUrls: ['http://test.com/test.jpg'], isAvailable: true, name: 'test', }, }); const { aggregateProductVariantId } = await aggregateProductVariantRepo.upsert({ productIdentifiers: ['test'], variantIdentifiers: ['test1'], data: { asin: 'asin', colorCode: 'colorCode', annotations: 'annotation', price: 100, description: 'description', dimensions: 'dimensions', discoverable: true, distributor: 'distributor', distributorSKU: 'distributor', imageUrls: ['http://test.com/test.jpg'], isAvailable: true, name: 'test', }, }); const aggregateProductVariant = await AggregateProductVariant.findOneOrFail( aggregateProductVariantId, { relations: ['product'], } ); expect(aggregateProductVariant).toMatchObject({ id: expect.any(String), identifiers: ['test1'], asin: 'asin', colorCode: 'colorCode', annotations: 'annotation', price: 100, description: 'description', dimensions: 'dimensions', discoverable: true, distributor: 'distributor', distributorSKU: 'distributor', imageUrls: ['http://test.com/test.jpg'], isAvailable: true, name: 'test', }); expect(aggregateProductVariant.product).toMatchObject({ id: expect.any(String), identifiers: ['test'], asin: 'asin', colorCode: 'colorCode', annotations: 'annotation', price: 100, description: 'description', dimensions: 'dimensions', discoverable: true, distributor: 'distributor', distributorSKU: 'distributor', imageUrls: ['http://test.com/test.jpg'], isAvailable: true, name: 'test', }); }); });