mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
chore: test baserowApiRequest
This commit is contained in:
parent
2e056e37ea
commit
dae1349138
|
@ -7,8 +7,7 @@ import type {
|
|||
INode,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { baserowFileUploadRequest } from '../GenericFunctions';
|
||||
import { mock } from 'node:test';
|
||||
import { baserowApiRequest, baserowFileUploadRequest } from '../GenericFunctions';
|
||||
|
||||
export const node: INode = {
|
||||
id: 'c4a5ca75-18c7-4cc8-bf7d-5d57bb7d84da',
|
||||
|
@ -23,6 +22,71 @@ export const node: INode = {
|
|||
};
|
||||
|
||||
describe('Baserow', () => {
|
||||
describe('baserowApiRequest', () => {
|
||||
const mockThis = {
|
||||
helpers: {
|
||||
requestWithAuthentication: jest.fn().mockResolvedValue({ statusCode: 200 }),
|
||||
httpRequest: jest.fn(),
|
||||
},
|
||||
getNode() {
|
||||
return node;
|
||||
},
|
||||
getCredentials: jest.fn(),
|
||||
getNodeParameter: jest.fn(),
|
||||
} as unknown as IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions;
|
||||
|
||||
it('should upload a file via url', async () => {
|
||||
mockThis.getCredentials.mockResolvedValue({
|
||||
host: 'https://my-host.com',
|
||||
});
|
||||
|
||||
mockThis.helpers.httpRequest.mockResolvedValue({
|
||||
statusCode: 200,
|
||||
body: {
|
||||
size: 2147483647,
|
||||
mime_type: 'string',
|
||||
is_image: true,
|
||||
image_width: 32767,
|
||||
image_height: 32767,
|
||||
uploaded_at: '2019-08-24T14:15:22Z',
|
||||
url: 'http://example.com',
|
||||
thumbnails: {
|
||||
property1: null,
|
||||
property2: null,
|
||||
},
|
||||
name: 'string',
|
||||
original_name: 'string',
|
||||
},
|
||||
} as IN8nHttpFullResponse | IN8nHttpResponse);
|
||||
|
||||
const jwtToken = 'jwt';
|
||||
const fileUrl = 'http://example.com/image.png';
|
||||
|
||||
const body = {
|
||||
file_url: fileUrl,
|
||||
};
|
||||
|
||||
await baserowApiRequest.call(
|
||||
mockThis,
|
||||
'POST',
|
||||
'/api/user-files/upload-via-url/',
|
||||
jwtToken,
|
||||
body,
|
||||
);
|
||||
|
||||
expect(mockThis.getCredentials).toHaveBeenCalledWith('baserowApi');
|
||||
expect(mockThis.helpers.httpRequest).toHaveBeenCalledWith({
|
||||
headers: {
|
||||
Authorization: `JWT ${jwtToken}`,
|
||||
},
|
||||
method: 'POST',
|
||||
url: 'https://my-host.com/api/user-files/upload-via-url/',
|
||||
body,
|
||||
json: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('baserowFileUploadRequest', () => {
|
||||
const mockThis = {
|
||||
helpers: {
|
||||
|
|
Loading…
Reference in a new issue