Files
alighasami 3d5eaf9445
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

63 lines
1.7 KiB
TypeScript

import type { IExecuteFunctions, IHookFunctions } from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import { spotifyApiRequest } from '../GenericFunctions';
describe('Spotify -> GenericFunctions', () => {
let mockThis: IHookFunctions | IExecuteFunctions;
beforeEach(() => {
mockThis = {
helpers: {
httpRequestWithAuthentication: jest.fn(),
},
getNode: jest.fn().mockReturnValue({}),
} as unknown as IHookFunctions | IExecuteFunctions;
});
it('should make a request with the correct options', async () => {
const method = 'GET';
const endpoint = '/me';
const body = {};
const query = { limit: 10 };
const response = { data: 'test' };
(mockThis.helpers.httpRequestWithAuthentication as jest.Mock).mockResolvedValue(response);
const result = await spotifyApiRequest.call(mockThis, method, endpoint, body, query);
expect(mockThis.helpers.httpRequestWithAuthentication).toHaveBeenCalledWith(
'spotifyOAuth2Api',
{
method,
headers: {
'User-Agent': 'n8n',
'Content-Type': 'text/plain',
Accept: ' application/json',
},
qs: query,
url: `https://api.spotify.com/v1${endpoint}`,
json: true,
},
);
expect(result).toEqual(response);
});
it('should throw a NodeApiError on request failure', async () => {
const method = 'GET';
const endpoint = '/me';
const body = {};
const query = { limit: 10 };
const error = new Error('Request failed');
(mockThis.helpers.httpRequestWithAuthentication as jest.Mock).mockRejectedValue(error);
await expect(spotifyApiRequest.call(mockThis, method, endpoint, body, query)).rejects.toThrow(
NodeApiError,
);
expect(mockThis.getNode).toHaveBeenCalled();
});
});