import { NodeTestHarness } from '@nodes-testing/node-test-harness'; import nock from 'nock'; import { parse as parseUrl } from 'url'; describe('Test HTTP Request Node', () => { const baseUrl = 'https://dummyjson.com'; beforeAll(async () => { function getPaginationReturnData(this: nock.ReplyFnContext, limit = 10, skip = 0) { const nextUrl = `${baseUrl}/users?skip=${skip + limit}&limit=${limit}`; const response = []; for (let i = skip; i < skip + limit; i++) { if (i > 14) { break; } response.push({ id: i, }); } if (!response.length) { return [ 404, response, { 'next-url': nextUrl, 'content-type': this.req.headers['content-type'] || 'application/json', }, ]; } return [ 200, response, { 'next-url': nextUrl, 'content-type': this.req.headers['content-type'] || 'application/json', }, ]; } //GET nock(baseUrl).get('/todos/1').reply(200, { id: 1, todo: 'Do something nice for someone I care about', completed: true, userId: 26, }); nock(baseUrl).get('/todos/1').reply(200, { id: 1, todo: 'Do something nice for someone I care about', completed: true, userId: 26, }); nock(baseUrl).matchHeader('Authorization', 'Bearer 12345').get('/todos/3').reply(200, { id: 3, todo: 'Watch a classic movie', completed: false, userId: 4, }); nock(baseUrl) .get('/todos?limit=2&skip=10') .reply(200, { todos: [ { id: 11, todo: "Text a friend I haven't talked to in a long time", completed: false, userId: 39, }, { id: 12, todo: 'Organize pantry', completed: true, userId: 39, }, ], total: 150, skip: 10, limit: 2, }); //POST nock(baseUrl) .post('/todos/add', { todo: 'Use DummyJSON in the project', completed: false, userId: '5', }) .reply(200, { id: 151, todo: 'Use DummyJSON in the project', completed: false, userId: '5', }); nock(baseUrl) .post('/todos/add2', { todo: 'Use DummyJSON in the project', completed: false, userId: 15, }) .reply(200, { id: 151, todo: 'Use DummyJSON in the project', completed: false, userId: 15, }); nock(baseUrl).get('/html').reply(200, '