Update index.test.ts

This commit is contained in:
rafaelsideguide 2024-07-02 11:04:09 -03:00
parent 7b7154ba1e
commit 96de948d6b

View File

@ -546,46 +546,51 @@ describe("E2E Tests for API Routes", () => {
expect(childrenLinks.length).toBe(completedResponse.body.data.length); expect(childrenLinks.length).toBe(completedResponse.body.data.length);
}, 180000); // 120 seconds }, 180000); // 120 seconds
it.concurrent('should return a successful response for a valid crawl job with PDF files without explicit .pdf extension ', async () => { // TODO: review the test below
const crawlResponse = await request(TEST_URL) // it.concurrent('should return a successful response for a valid crawl job with PDF files without explicit .pdf extension ', async () => {
.post('/v0/crawl') // const crawlResponse = await request(TEST_URL)
.set('Authorization', `Bearer ${process.env.TEST_API_KEY}`) // .post('/v0/crawl')
.set('Content-Type', 'application/json') // .set('Authorization', `Bearer ${process.env.TEST_API_KEY}`)
.send({ url: 'https://arxiv.org/pdf/astro-ph/9301001', crawlerOptions: { limit: 10, excludes: [ 'list/*', 'login', 'abs/*', 'static/*', 'about/*', 'archive/*' ] }}); // .set('Content-Type', 'application/json')
expect(crawlResponse.statusCode).toBe(200); // .send({ url: 'https://arxiv.org/list/astro-ph/1993-01',
// crawlerOptions: {
// limit: 10,
// returnOnlyUrls: true
// }});
// expect(crawlResponse.statusCode).toBe(200);
let isCompleted = false; // let isCompleted = false;
let completedResponse; // let completedResponse;
while (!isCompleted) { // while (!isCompleted) {
const response = await request(TEST_URL) // const response = await request(TEST_URL)
.get(`/v0/crawl/status/${crawlResponse.body.jobId}`) // .get(`/v0/crawl/status/${crawlResponse.body.jobId}`)
.set('Authorization', `Bearer ${process.env.TEST_API_KEY}`); // .set('Authorization', `Bearer ${process.env.TEST_API_KEY}`);
expect(response.statusCode).toBe(200); // expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('status'); // expect(response.body).toHaveProperty('status');
if (response.body.status === 'completed') { // if (response.body.status === 'completed') {
isCompleted = true; // isCompleted = true;
completedResponse = response; // completedResponse = response;
} else { // } else {
await new Promise((r) => setTimeout(r, 1000)); // Wait for 1 second before checking again // await new Promise((r) => setTimeout(r, 1000)); // Wait for 1 second before checking again
} // }
} // }
expect(completedResponse.body.status).toBe('completed'); // expect(completedResponse.body.status).toBe('completed');
expect(completedResponse.body).toHaveProperty('data'); // expect(completedResponse.body).toHaveProperty('data');
expect(completedResponse.body.data.length).toEqual(1); // expect(completedResponse.body.data.length).toEqual(1);
expect(completedResponse.body.data).toEqual( // expect(completedResponse.body.data).toEqual(
expect.arrayContaining([ // expect.arrayContaining([
expect.objectContaining({ // expect.objectContaining({
content: expect.stringContaining('asymmetries might represent, for instance, preferred source orientations to our line of sight.') // content: expect.stringContaining('asymmetries might represent, for instance, preferred source orientations to our line of sight.')
}) // })
]) // ])
); // );
expect(completedResponse.body.data[0]).toHaveProperty("metadata"); // expect(completedResponse.body.data[0]).toHaveProperty("metadata");
expect(completedResponse.body.data[0].metadata.pageStatusCode).toBe(200); // expect(completedResponse.body.data[0].metadata.pageStatusCode).toBe(200);
expect(completedResponse.body.data[0].metadata.pageError).toBeUndefined(); // expect(completedResponse.body.data[0].metadata.pageError).toBeUndefined();
}, 180000); // 120 seconds // }, 180000); // 120 seconds
it.concurrent("If someone cancels a crawl job, it should turn into failed status", async () => { it.concurrent("If someone cancels a crawl job, it should turn into failed status", async () => {
const crawlResponse = await request(TEST_URL) const crawlResponse = await request(TEST_URL)