mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 09:04:07 -08:00
6d6e2488c6
Depends on: #7092 | Story: [PAY-768](https://linear.app/n8n/issue/PAY-768) This PR: - Generalizes the `IBinaryDataManager` interface. - Adjusts `Filesystem.ts` to satisfy the interface. - Sets up an S3 client stub to be filled in in the next PR. - Turns `BinaryDataManager` into an injectable service. - Adjusts the config schema and adds new validators. Note that the PR looks large but all the main changes are in `packages/core/src/binaryData`. Out of scope: - `BinaryDataManager` (now `BinaryDataService`) and `Filesystem.ts` (now `fs.client.ts`) were slightly refactored for maintainability, but fully overhauling them is **not** the focus of this PR, which is meant to clear the way for the S3 implementation. Future improvements for these two should include setting up a backwards-compatible dir structure that makes it easier to locate binary data files to delete, removing duplication, simplifying cloning methods, using integers for binary data size instead of `prettyBytes()`, writing tests for existing binary data logic, etc. --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
133 lines
2.8 KiB
TypeScript
133 lines
2.8 KiB
TypeScript
import {
|
|
initBinaryDataService,
|
|
setup,
|
|
equalityTest,
|
|
workflowToTests,
|
|
getWorkflowFilenames,
|
|
} from '@test/nodes/Helpers';
|
|
|
|
import nock from 'nock';
|
|
|
|
describe('Test HTTP Request Node', () => {
|
|
const workflows = getWorkflowFilenames(__dirname);
|
|
const tests = workflowToTests(workflows);
|
|
|
|
const baseUrl = 'https://dummyjson.com';
|
|
|
|
beforeAll(async () => {
|
|
await initBinaryDataService();
|
|
nock.disableNetConnect();
|
|
|
|
//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).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,
|
|
});
|
|
|
|
//PUT
|
|
nock(baseUrl).put('/todos/10', { userId: '42' }).reply(200, {
|
|
id: 10,
|
|
todo: 'Have a football scrimmage with some friends',
|
|
completed: false,
|
|
userId: '42',
|
|
});
|
|
|
|
//PATCH
|
|
nock(baseUrl)
|
|
.patch('/products/1', '{"title":"iPhone 12"}')
|
|
.reply(200, {
|
|
id: 1,
|
|
title: 'iPhone 12',
|
|
price: 549,
|
|
stock: 94,
|
|
rating: 4.69,
|
|
images: [
|
|
'https://i.dummyjson.com/data/products/1/1.jpg',
|
|
'https://i.dummyjson.com/data/products/1/2.jpg',
|
|
'https://i.dummyjson.com/data/products/1/3.jpg',
|
|
'https://i.dummyjson.com/data/products/1/4.jpg',
|
|
'https://i.dummyjson.com/data/products/1/thumbnail.jpg',
|
|
],
|
|
thumbnail: 'https://i.dummyjson.com/data/products/1/thumbnail.jpg',
|
|
description: 'An apple mobile which is nothing like apple',
|
|
brand: 'Apple',
|
|
category: 'smartphones',
|
|
});
|
|
|
|
//DELETE
|
|
nock(baseUrl).delete('/todos/1').reply(200, {
|
|
id: 1,
|
|
todo: 'Do something nice for someone I care about',
|
|
completed: true,
|
|
userId: 26,
|
|
isDeleted: true,
|
|
deletedOn: '2023-02-09T05:37:31.720Z',
|
|
});
|
|
});
|
|
|
|
afterAll(() => {
|
|
nock.restore();
|
|
});
|
|
|
|
const nodeTypes = setup(tests);
|
|
|
|
for (const testData of tests) {
|
|
test(testData.description, async () => equalityTest(testData, nodeTypes));
|
|
}
|
|
});
|