import gql from 'graphql-tag'; import { startSessionAnonymously } from 'test/graphql'; import { getCustomRepository } from 'typeorm'; import { AggregateProductVariantRepository, AggregateProductVariantSavesListRepository, } from '@/repositories'; describe('Query:aggregateProductVariant', () => { const query = gql` query ($input: AggregateProductVariantInput!) { aggregateProductVariant(input: $input) { aggregateProductVariant { id name numberOfSaves } } } `; test('should return aggregate product variants', async () => { const { execute, user } = await startSessionAnonymously(); const aggregateProductVariantRepo = getCustomRepository( AggregateProductVariantRepository ); const aggregateProductVariantSavesListRepo = getCustomRepository( AggregateProductVariantSavesListRepository ); const { aggregateProductVariantId } = await aggregateProductVariantRepo.upsert({ productIdentifiers: ['test'], variantIdentifiers: [], 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 1', }, }); await aggregateProductVariantSavesListRepo.create( { variantIds: [aggregateProductVariantId], }, user ); const response = await execute({ query: query, variables: { input: { id: aggregateProductVariantId, }, }, }); expect(response.errors?.length).toBeFalsy(); expect( response.data?.aggregateProductVariant.aggregateProductVariant.id ).toBe(aggregateProductVariantId); expect( response.data?.aggregateProductVariant.aggregateProductVariant .numberOfSaves ).toBe(1); }); });