mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Added more specific errors
This commit is contained in:
parent
81ce5c69d6
commit
9801c907fc
|
@ -3,7 +3,7 @@ import { NodeConnectionType } from 'n8n-workflow';
|
|||
|
||||
import { containerFields, containerOperations } from './descriptions/ContainerDescription';
|
||||
import { itemFields, itemOperations } from './descriptions/ItemDescription';
|
||||
import { getDynamicFields, searchCollections, searchItems } from './GenericFunctions';
|
||||
import { getProperties, searchContainers, searchItems } from './GenericFunctions';
|
||||
|
||||
export class CosmosDb implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
|
@ -62,9 +62,9 @@ export class CosmosDb implements INodeType {
|
|||
|
||||
methods = {
|
||||
listSearch: {
|
||||
searchCollections,
|
||||
searchContainers,
|
||||
searchItems,
|
||||
getDynamicFields,
|
||||
getProperties,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -199,7 +199,7 @@ export const getFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'searchCollections',
|
||||
searchListMethod: 'searchContainers',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
@ -248,7 +248,7 @@ export const deleteFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'searchCollections',
|
||||
searchListMethod: 'searchContainers',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -182,7 +182,7 @@ export const createFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'searchCollections',
|
||||
searchListMethod: 'searchContainers',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
@ -266,7 +266,7 @@ export const deleteFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'searchCollections',
|
||||
searchListMethod: 'searchContainers',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
@ -379,7 +379,7 @@ export const getFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'searchCollections',
|
||||
searchListMethod: 'searchContainers',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
@ -492,7 +492,7 @@ export const getAllFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'searchCollections',
|
||||
searchListMethod: 'searchContainers',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
@ -577,7 +577,7 @@ export const queryFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'searchCollections',
|
||||
searchListMethod: 'searchContainers',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
@ -692,7 +692,7 @@ export const updateFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'searchCollections',
|
||||
searchListMethod: 'searchContainers',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
@ -814,7 +814,7 @@ export const updateFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getDynamicFields',
|
||||
searchListMethod: 'getProperties',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
@ -847,7 +847,7 @@ export const updateFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getDynamicFields',
|
||||
searchListMethod: 'getProperties',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
@ -880,7 +880,7 @@ export const updateFields: INodeProperties[] = [
|
|||
name: 'list',
|
||||
type: 'list',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getDynamicFields',
|
||||
searchListMethod: 'getProperties',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import type { ILoadOptionsFunctions } from 'n8n-workflow';
|
||||
|
||||
import { searchCollections } from '../GenericFunctions';
|
||||
import { searchContainers } from '../GenericFunctions';
|
||||
|
||||
describe('GenericFunctions - searchCollections', () => {
|
||||
describe('GenericFunctions - searchContainers', () => {
|
||||
const mockRequestWithAuthentication = jest.fn();
|
||||
|
||||
const mockContext = {
|
||||
|
@ -17,7 +17,7 @@ describe('GenericFunctions - searchCollections', () => {
|
|||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should make a GET request to fetch collections and return results', async () => {
|
||||
it('should make a GET request to fetch containers and return results', async () => {
|
||||
(mockContext.getCredentials as jest.Mock).mockResolvedValueOnce({
|
||||
account: 'us-east-1',
|
||||
database: 'first_database_1',
|
||||
|
@ -28,7 +28,7 @@ describe('GenericFunctions - searchCollections', () => {
|
|||
DocumentCollections: [{ id: 'Collection1' }, { id: 'Collection2' }],
|
||||
});
|
||||
|
||||
const response = await searchCollections.call(mockContext);
|
||||
const response = await searchContainers.call(mockContext);
|
||||
|
||||
expect(mockRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'microsoftCosmosDbSharedKeyApi',
|
||||
|
@ -52,7 +52,7 @@ describe('GenericFunctions - searchCollections', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should filter collections by the provided filter string', async () => {
|
||||
it('should filter containers by the provided filter string', async () => {
|
||||
(mockContext.getCredentials as jest.Mock).mockResolvedValueOnce({
|
||||
account: 'us-east-1',
|
||||
database: 'first_database_1',
|
||||
|
@ -63,7 +63,7 @@ describe('GenericFunctions - searchCollections', () => {
|
|||
DocumentCollections: [{ id: 'Test-Col-1' }, { id: 'Prod-Col-1' }],
|
||||
});
|
||||
|
||||
const response = await searchCollections.call(mockContext, 'Test');
|
||||
const response = await searchContainers.call(mockContext, 'Test');
|
||||
|
||||
expect(mockRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'microsoftCosmosDbSharedKeyApi',
|
||||
|
@ -84,7 +84,7 @@ describe('GenericFunctions - searchCollections', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should sort collections alphabetically by name', async () => {
|
||||
it('should sort containers alphabetically by name', async () => {
|
||||
(mockContext.getCredentials as jest.Mock).mockResolvedValueOnce({ account: 'us-east-1' });
|
||||
(mockContext.getNodeParameter as jest.Mock).mockReturnValueOnce('db-id-1');
|
||||
|
||||
|
@ -92,7 +92,7 @@ describe('GenericFunctions - searchCollections', () => {
|
|||
DocumentCollections: [{ id: 'z-col' }, { id: 'a-col' }, { id: 'm-col' }],
|
||||
});
|
||||
|
||||
const response = await searchCollections.call(mockContext);
|
||||
const response = await searchContainers.call(mockContext);
|
||||
|
||||
expect(response).toEqual({
|
||||
results: [
|
||||
|
@ -103,7 +103,7 @@ describe('GenericFunctions - searchCollections', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should handle empty results when no collections are returned', async () => {
|
||||
it('should handle empty results when no containers are returned', async () => {
|
||||
(mockContext.getCredentials as jest.Mock).mockResolvedValueOnce({ account: 'us-east-1' });
|
||||
(mockContext.getNodeParameter as jest.Mock).mockReturnValueOnce('db-id-1');
|
||||
|
||||
|
@ -111,19 +111,19 @@ describe('GenericFunctions - searchCollections', () => {
|
|||
DocumentCollections: [],
|
||||
});
|
||||
|
||||
const response = await searchCollections.call(mockContext);
|
||||
const response = await searchContainers.call(mockContext);
|
||||
|
||||
expect(response).toEqual({ results: [] });
|
||||
});
|
||||
|
||||
it('should handle missing Collections property', async () => {
|
||||
it('should handle missing DocumentCollections property', async () => {
|
||||
(mockContext.getCredentials as jest.Mock).mockResolvedValueOnce({ account: 'us-east-1' });
|
||||
(mockContext.getNodeParameter as jest.Mock).mockReturnValueOnce('db-id-1');
|
||||
|
||||
mockRequestWithAuthentication.mockResolvedValueOnce({
|
||||
unexpectedkey: 'value',
|
||||
});
|
||||
const response = await searchCollections.call(mockContext);
|
||||
const response = await searchContainers.call(mockContext);
|
||||
|
||||
expect(response).toEqual({ results: [] });
|
||||
});
|
||||
|
|
|
@ -116,9 +116,9 @@ describe('GenericFunctions - searchItems', () => {
|
|||
expect(response).toEqual({ results: [] });
|
||||
});
|
||||
|
||||
it('should throw an error when collection ID is missing', async () => {
|
||||
it('should throw an error when container ID is missing', async () => {
|
||||
(mockContext.getNodeParameter as jest.Mock).mockReturnValueOnce({ mode: 'list', value: '' });
|
||||
|
||||
await expect(searchItems.call(mockContext)).rejects.toThrow('Collection ID is required.');
|
||||
await expect(searchItems.call(mockContext)).rejects.toThrow('Container is required');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue