first commit
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
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
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
|
||||
import nock from 'nock';
|
||||
|
||||
import {
|
||||
getAlbum,
|
||||
getAlbumTracks,
|
||||
getArtist,
|
||||
getNewReleases,
|
||||
searchForAlbum,
|
||||
} from './apiResponses';
|
||||
|
||||
describe('Spotify', () => {
|
||||
describe('Run workflow', () => {
|
||||
beforeAll(() => {
|
||||
const mock = nock('https://api.spotify.com/v1');
|
||||
mock
|
||||
.get('/search')
|
||||
.query({ q: 'From Xero', type: 'album', limit: 2 })
|
||||
.reply(200, searchForAlbum);
|
||||
mock.get('/browse/new-releases').query({ limit: 2 }).reply(200, getNewReleases);
|
||||
mock.get('/albums/4R6FV9NSzhPihHR0h4pI93/tracks').reply(200, getAlbumTracks);
|
||||
mock.get('/albums/4R6FV9NSzhPihHR0h4pI93').reply(200, getAlbum);
|
||||
mock.get('/artists/12Chz98pHFMPJEknJQMWvI').reply(200, getArtist);
|
||||
});
|
||||
|
||||
new NodeTestHarness().setupTests();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user