Skip to content

Commit

Permalink
Update scraper test
Browse files Browse the repository at this point in the history
  • Loading branch information
21jake committed Mar 12, 2023
1 parent ebd5855 commit 3ff525f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 4 additions & 0 deletions backend/src/utils/scraper.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export class HttpScraper {

public getOverviewScrapedInfo() {

if (this.keyword.includes('throwerror')) {
throw new Error('This is a test error');
}

if (!this.cheerioAPI) {
throw new Error('No data scraped yet!');
}
Expand Down
5 changes: 4 additions & 1 deletion backend/test/file-upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ScraperService } from 'src/services/scraper.service';
import { Repositories } from 'src/utils/enums/repositories.enum';
import { generateRandomString } from 'src/utils/helpers';
import request from 'supertest';
import { Repository } from 'typeorm';
import { In, Repository } from 'typeorm';
// jest.useRealTimers();
describe('File Upload', () => {

Expand Down Expand Up @@ -146,6 +146,9 @@ describe('File Upload', () => {
};

afterAll(async () => {
const instertedKeywords = getKws(samplePath_1);
await keywordRepository.delete({ name: In(instertedKeywords) });

unlinkSync(path.join(appEnv.CSV_PATH, savedFileName));
await app.close();
});
Expand Down
31 changes: 21 additions & 10 deletions backend/test/scraper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('Scraper', () => {
createdDate: null,
},
{
name: generateRandomString(),
name: `${generateRandomString()}-throwerror`,
batch: batch as any,
fileName: null,
success: null,
Expand Down Expand Up @@ -175,11 +175,16 @@ describe('Scraper', () => {
const { keywords: keywordsAfterScraping } = await getTestBatch();

keywordsAfterScraping.forEach((e) => {
expect(e.success).toBe(true);
expect(e.totalLinks).not.toBeNull();
expect(e.totalAds).not.toBeNull();
expect(e.searchTime).not.toBeNull();
expect(e.fileName).not.toBeNull();
if (e.success === true) {
expect(e.success).toBe(true);
expect(e.totalLinks).not.toBeNull();
expect(e.totalAds).not.toBeNull();
expect(e.searchTime).not.toBeNull();
expect(e.fileName).not.toBeNull();
} else {
expect(e.success).toBe(false);
expect(e.error).not.toBeNull();
}
});
}, 60_000);

Expand All @@ -196,10 +201,16 @@ describe('Scraper', () => {
const successfulKwAfterRescraping = keywordsAfterRecraping.filter((e) => e.success);

successfulKwAfterRescraping.forEach((e) => {
expect(e.success).toBe(true);
expect(e.totalLinks).not.toBeNull();
expect(e.totalAds).not.toBeNull();
expect(e.fileName).not.toBeNull();
if (e.success === true) {
expect(e.success).toBe(true);
expect(e.totalLinks).not.toBeNull();
expect(e.totalAds).not.toBeNull();
expect(e.searchTime).not.toBeNull();
expect(e.fileName).not.toBeNull();
} else {
expect(e.success).toBe(false);
expect(e.error).not.toBeNull();
}
});
}, 60_000);

Expand Down

0 comments on commit 3ff525f

Please sign in to comment.