import { startSession } from 'test/rest'; describe('DataIngestionController', () => { describe('Post /aggregate-products', () => { it('throws errors if no urls are passed in the input', async () => { const { execute } = await startSession({ makeAdmin: true }); const response = await execute({ method: 'post', url: '/v3/aggregate-products', data: {}, }); expect(response.status).toBe(422); expect(response.body.reason).toBe( 'Either retailerUrls or googleShoppingUrl is required' ); }); it('throws errors if empty input is passed', async () => { const { execute } = await startSession({ makeAdmin: true }); const response = await execute({ method: 'post', url: '/v3/aggregate-products', data: { retailerUrls: [], googleShoppingUrl: '', }, }); expect(response.status).toBe(422); expect(response.body.reason).toBe( 'Either retailerUrls or googleShoppingUrl is required' ); }); it('Queues new jobs if either retailerUrls or googleShoppingUrl is proper', async () => { const { execute } = await startSession({ makeAdmin: true }); const inputs: { retailerUrls?: string[]; googleShoppingUrl?: string; }[] = [ { retailerUrls: ['https://www.amazon.com/'], googleShoppingUrl: 'https://www.google.com/', }, { googleShoppingUrl: 'https://www.google.com/', }, { retailerUrls: ['https://www.amazon.com/'], }, ]; for (let index = 0; index < inputs.length; index++) { const element = inputs[index]; const response = await execute({ method: 'post', url: '/v3/aggregate-products', data: element, }); expect(response.status).toBe(201); expect(response.body.status).toBe('queued'); } }, 1000000); }); });