From e1246ab65cd2d8ae19fd69ce4c3a61dfce4c53f5 Mon Sep 17 00:00:00 2001 From: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com> Date: Mon, 14 Apr 2025 10:05:05 +0100 Subject: [PATCH] test(YouTube Node): Add tests for YouTube Node (#14459) Co-authored-by: Roman Davydchuk --- .../GenericFunctions.test.ts | 0 .../__test__/node/YouTube.node.test.ts | 185 ++++++ .../__test__/node/channels.workflow.json | 446 +++++++++++++++ .../__test__/node/fixtures/categories.json | 32 ++ .../__test__/node/fixtures/channels.json | 217 +++++++ .../__test__/node/fixtures/playlistItems.json | 104 ++++ .../__test__/node/fixtures/playlists.json | 59 ++ .../__test__/node/playlistItems.workflow.json | 412 ++++++++++++++ .../__test__/node/playlists.workflow.json | 536 ++++++++++++++++++ .../node/videoCategories.workflow.json | 106 ++++ .../test/nodes/FakeCredentialsMap.ts | 19 + packages/nodes-base/test/nodes/Helpers.ts | 2 +- 12 files changed, 2117 insertions(+), 1 deletion(-) rename packages/nodes-base/nodes/Google/YouTube/{test => __test__}/GenericFunctions.test.ts (100%) create mode 100644 packages/nodes-base/nodes/Google/YouTube/__test__/node/YouTube.node.test.ts create mode 100644 packages/nodes-base/nodes/Google/YouTube/__test__/node/channels.workflow.json create mode 100644 packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/categories.json create mode 100644 packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/channels.json create mode 100644 packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/playlistItems.json create mode 100644 packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/playlists.json create mode 100644 packages/nodes-base/nodes/Google/YouTube/__test__/node/playlistItems.workflow.json create mode 100644 packages/nodes-base/nodes/Google/YouTube/__test__/node/playlists.workflow.json create mode 100644 packages/nodes-base/nodes/Google/YouTube/__test__/node/videoCategories.workflow.json diff --git a/packages/nodes-base/nodes/Google/YouTube/test/GenericFunctions.test.ts b/packages/nodes-base/nodes/Google/YouTube/__test__/GenericFunctions.test.ts similarity index 100% rename from packages/nodes-base/nodes/Google/YouTube/test/GenericFunctions.test.ts rename to packages/nodes-base/nodes/Google/YouTube/__test__/GenericFunctions.test.ts diff --git a/packages/nodes-base/nodes/Google/YouTube/__test__/node/YouTube.node.test.ts b/packages/nodes-base/nodes/Google/YouTube/__test__/node/YouTube.node.test.ts new file mode 100644 index 0000000000..705820ac94 --- /dev/null +++ b/packages/nodes-base/nodes/Google/YouTube/__test__/node/YouTube.node.test.ts @@ -0,0 +1,185 @@ +import nock from 'nock'; + +import { testWorkflows } from '@test/nodes/Helpers'; + +import categories from './fixtures/categories.json'; +import channels from './fixtures/channels.json'; +import playlistItems from './fixtures/playlistItems.json'; +import playlists from './fixtures/playlists.json'; + +describe('Test YouTube Node', () => { + const youtubeNock = nock('https://www.googleapis.com/youtube'); + beforeAll(() => { + jest + .useFakeTimers({ doNotFake: ['setImmediate', 'nextTick'] }) + .setSystemTime(new Date('2024-12-16 12:34:56.789Z')); + }); + + describe('Channel', () => { + beforeAll(() => { + youtubeNock + .get('/v3/channels') + .query({ + part: 'brandingSettings,contentDetails,contentOwnerDetails,id,localizations,snippet,statistics,status,topicDetails', + mine: 'true', + maxResults: '25', + }) + .reply(200, { items: channels }); + youtubeNock + .get('/v3/channels') + .query({ + part: 'brandingSettings,contentDetails,contentOwnerDetails,id,localizations,snippet,statistics,status,topicDetails', + id: 'UCabc123def456ghi789jkl', + }) + .reply(200, { items: [channels[0]] }); + youtubeNock + .put('/v3/channels', (body) => { + return ( + body.id === 'UCabc123def456ghi789jkl' && + body.brandingSettings?.channel?.description === 'Test' + ); + }) + .query({ part: 'brandingSettings' }) + .reply(200, { + kind: 'youtube#channel', + etag: 'someEtag', + id: 'UCabc123def456ghi789jkl', + brandingSettings: { + channel: { + description: 'Test', + }, + image: {}, + }, + }); + nock.emitter.on('no match', (req) => { + console.error('Unmatched request:', req); + }); + }); + + testWorkflows(['nodes/Google/YouTube/__test__/node/channels.workflow.json']); + + it('should make the correct network calls', () => { + youtubeNock.done(); + }); + }); + + describe('Playlist', () => { + beforeAll(() => { + youtubeNock + .post('/v3/playlists', { + snippet: { title: 'Playlist 1', privacyStatus: 'public', defaultLanguage: 'en' }, + }) + .query({ part: 'snippet' }) + .reply(200, playlists[0]); + youtubeNock + .put('/v3/playlists', { + id: 'playlist_id_1', + snippet: { title: 'Test Updated', description: 'This description is updated' }, + status: { privacyStatus: 'private' }, + }) + .query({ part: 'snippet, status' }) + .reply(200, { + ...playlists[0], + snippet: { + ...playlists[0].snippet, + title: 'The title is updated', + description: 'The description is updated', + localized: { + ...playlists[0].snippet.localized, + title: 'The title is updated', + description: 'The description is updated', + }, + }, + }); + youtubeNock + .get('/v3/playlists') + .query({ + part: 'contentDetails,id,localizations,player,snippet,status', + id: 'playlist_id_1', + }) + .reply(200, { items: [playlists[0]] }); + youtubeNock + .get('/v3/playlists') + .query({ + part: 'contentDetails,id,localizations,player,snippet,status', + mine: true, + maxResults: 25, + }) + .reply(200, { items: playlists }); + youtubeNock.delete('/v3/playlists', { id: 'playlist_id_1' }).reply(200, { success: true }); + nock.emitter.on('no match', (req) => { + console.error('Unmatched request:', req); + }); + }); + + testWorkflows(['nodes/Google/YouTube/__test__/node/playlists.workflow.json']); + + it('should make the correct network calls', () => { + youtubeNock.done(); + }); + }); + + describe('Video Categories', () => { + beforeAll(() => { + youtubeNock + .get('/v3/videoCategories') + .query({ + part: 'snippet', + regionCode: 'GB', + }) + .reply(200, { items: categories }); + nock.emitter.on('no match', (req) => { + console.error('Unmatched request:', req); + }); + }); + + testWorkflows(['nodes/Google/YouTube/__test__/node/videoCategories.workflow.json']); + + it('should make the correct network calls', () => { + youtubeNock.done(); + }); + }); + describe('Playlist Item', () => { + beforeAll(() => { + youtubeNock + .get('/v3/playlistItems') + .query({ + part: 'contentDetails,id,snippet,status', + id: 'fakePlaylistItemId1', + }) + .reply(200, { items: playlistItems[0] }); + youtubeNock + .get('/v3/playlistItems') + .query({ + playlistId: 'PLXXXXFAKEPLAYLISTID01', + part: 'contentDetails,id,snippet,status', + maxResults: 3, + }) + .reply(200, { items: playlistItems }); + youtubeNock + .post('/v3/playlistItems', { + snippet: { + playlistId: 'PLXXXXFAKEPLAYLISTID01', + resourceId: { kind: 'youtube#video', videoId: 'FAKEVIDID1' }, + }, + contentDetails: {}, + }) + .query({ part: 'snippet, contentDetails' }) + .reply(200, playlistItems[0]); + youtubeNock + .delete('/v3/playlistItems', (body) => { + return body.id === 'UExWUDRtV2RxbGFhNWlwZEJRWXZVaFgyNk9RTENJRlV2cS41NkI0NEY2RDEwNTU3Q0M2'; + }) + .reply(200, {}); + nock.emitter.on('no match', (req) => { + console.error('Unmatched request:', req); + }); + }); + + testWorkflows(['nodes/Google/YouTube/__test__/node/playlistItems.workflow.json']); + + // it('should make the correct network calls', () => { + // youtubeNock.done(); + // }); + }); +}); diff --git a/packages/nodes-base/nodes/Google/YouTube/__test__/node/channels.workflow.json b/packages/nodes-base/nodes/Google/YouTube/__test__/node/channels.workflow.json new file mode 100644 index 0000000000..28e1978673 --- /dev/null +++ b/packages/nodes-base/nodes/Google/YouTube/__test__/node/channels.workflow.json @@ -0,0 +1,446 @@ +{ + "nodes": [ + { + "parameters": {}, + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [320, 1980], + "id": "ca093a4e-81cb-445a-980c-dcdacbb1cc36", + "name": "When clicking ‘Test workflow’" + }, + { + "parameters": { + "filters": {}, + "options": {} + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [540, 1780], + "id": "a36477d2-f98b-48b9-a392-0f615527a7e6", + "name": "YouTube", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": { + "operation": "get", + "channelId": "UCabc123def456ghi789jkl" + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [540, 1980], + "id": "afcfc3bb-a16a-4890-a4b3-692f843b9103", + "name": "YouTube1", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": { + "operation": "update", + "channelId": "UCabc123def456ghi789jkl", + "updateFields": { + "brandingSettingsUi": { + "channelSettingsValues": { + "channel": { + "description": "Test" + } + } + } + } + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [540, 2180], + "id": "3a5f1c72-7dd1-4a76-958f-b9ecf7f8afbe", + "name": "YouTube2", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [760, 1780], + "id": "0ef3bfeb-6772-4eae-b4f6-5a8a05678861", + "name": "Channel Get All" + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [760, 1980], + "id": "9af6133d-2a77-4245-83a7-1fb137997f3a", + "name": "Channel Get" + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [760, 2180], + "id": "0d316d95-7e49-4497-a31c-9e56b1a7fda3", + "name": "Channel Update" + } + ], + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "YouTube", + "type": "main", + "index": 0 + }, + { + "node": "YouTube2", + "type": "main", + "index": 0 + }, + { + "node": "YouTube1", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube": { + "main": [ + [ + { + "node": "Channel Get All", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube1": { + "main": [ + [ + { + "node": "Channel Get", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube2": { + "main": [ + [ + { + "node": "Channel Update", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "pinData": { + "Channel Get All": [ + { + "json": { + "kind": "youtube#channel", + "etag": "etag_123456", + "id": "UCabc123def456ghi789jkl", + "snippet": { + "title": "Tech Insights", + "description": "Latest tech reviews and industry insights.", + "customUrl": "@techinsights", + "publishedAt": "2015-06-15T09:30:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_tech1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_tech1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_tech1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Tech Insights", + "description": "Latest tech reviews and industry insights." + } + }, + "statistics": { + "viewCount": "1250000", + "subscriberCount": "45000", + "hiddenSubscriberCount": false, + "videoCount": "320" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + } + }, + { + "json": { + "kind": "youtube#channel", + "etag": "etag_654321", + "id": "UCxyz987uvw654rst321mno", + "snippet": { + "title": "Daily Vlogs", + "description": "Sharing daily experiences and adventures.", + "customUrl": "@dailyvlogs", + "publishedAt": "2018-03-10T14:20:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_vlog1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_vlog1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_vlog1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Daily Vlogs", + "description": "Sharing daily experiences and adventures." + } + }, + "statistics": { + "viewCount": "530000", + "subscriberCount": "12000", + "hiddenSubscriberCount": false, + "videoCount": "540" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + } + }, + { + "json": { + "kind": "youtube#channel", + "etag": "etag_987654", + "id": "UCopq135stu864vwx579yzb", + "snippet": { + "title": "Fitness Pro", + "description": "Workout tips and health advice.", + "customUrl": "@fitnesspro", + "publishedAt": "2017-08-22T07:45:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_fitness1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_fitness1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_fitness1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Fitness Pro", + "description": "Workout tips and health advice." + } + }, + "statistics": { + "viewCount": "850000", + "subscriberCount": "30000", + "hiddenSubscriberCount": false, + "videoCount": "215" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + } + }, + { + "json": { + "kind": "youtube#channel", + "etag": "etag_246810", + "id": "UCghi123stu456vwx789yzc", + "snippet": { + "title": "Gamer's Den", + "description": "Game walkthroughs, reviews, and tips.", + "customUrl": "@gamersden", + "publishedAt": "2016-12-05T12:10:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_gamer1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_gamer1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_gamer1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Gamer's Den", + "description": "Game walkthroughs, reviews, and tips." + } + }, + "statistics": { + "viewCount": "1950000", + "subscriberCount": "80000", + "hiddenSubscriberCount": false, + "videoCount": "640" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + } + }, + { + "json": { + "kind": "youtube#channel", + "etag": "etag_135790", + "id": "UCjkl987stu654vwx321mno", + "snippet": { + "title": "Cooking Mastery", + "description": "Delicious recipes and cooking tips.", + "customUrl": "@cookingmastery", + "publishedAt": "2019-04-17T16:55:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_cooking1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_cooking1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_cooking1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Cooking Mastery", + "description": "Delicious recipes and cooking tips." + } + }, + "statistics": { + "viewCount": "650000", + "subscriberCount": "25000", + "hiddenSubscriberCount": false, + "videoCount": "190" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + } + } + ], + "Channel Get": [ + { + "json": { + "kind": "youtube#channel", + "etag": "etag_123456", + "id": "UCabc123def456ghi789jkl", + "snippet": { + "title": "Tech Insights", + "description": "Latest tech reviews and industry insights.", + "customUrl": "@techinsights", + "publishedAt": "2015-06-15T09:30:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_tech1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_tech1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_tech1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Tech Insights", + "description": "Latest tech reviews and industry insights." + } + }, + "statistics": { + "viewCount": "1250000", + "subscriberCount": "45000", + "hiddenSubscriberCount": false, + "videoCount": "320" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + } + } + ], + "Channel Update": [ + { + "json": { + "kind": "youtube#channel", + "etag": "someEtag", + "id": "UCabc123def456ghi789jkl", + "brandingSettings": { + "channel": { + "description": "Test" + }, + "image": {} + } + } + } + ] + }, + "meta": { + "instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4" + } +} diff --git a/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/categories.json b/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/categories.json new file mode 100644 index 0000000000..2c8c07a8ab --- /dev/null +++ b/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/categories.json @@ -0,0 +1,32 @@ +[ + { + "kind": "youtube#videoCategory", + "etag": "grPOPYEUUZN3ltuDUGEWlrTR90U", + "id": "1", + "snippet": { + "title": "Film & Animation", + "assignable": true, + "channelId": "UCFAKE1234567890TEST" + } + }, + { + "kind": "youtube#videoCategory", + "etag": "Q0xgUf8BFM8rW3W0R9wNq809xyA", + "id": "2", + "snippet": { + "title": "Autos & Vehicles", + "assignable": true, + "channelId": "UCFAKE1234567890TEST" + } + }, + { + "kind": "youtube#videoCategory", + "etag": "qnpwjh5QlWM5hrnZCvHisquztC4", + "id": "10", + "snippet": { + "title": "Music", + "assignable": true, + "channelId": "UCFAKE1234567890TEST" + } + } +] diff --git a/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/channels.json b/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/channels.json new file mode 100644 index 0000000000..3aa29f1ac1 --- /dev/null +++ b/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/channels.json @@ -0,0 +1,217 @@ +[ + { + "kind": "youtube#channel", + "etag": "etag_123456", + "id": "UCabc123def456ghi789jkl", + "snippet": { + "title": "Tech Insights", + "description": "Latest tech reviews and industry insights.", + "customUrl": "@techinsights", + "publishedAt": "2015-06-15T09:30:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_tech1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_tech1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_tech1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Tech Insights", + "description": "Latest tech reviews and industry insights." + } + }, + "statistics": { + "viewCount": "1250000", + "subscriberCount": "45000", + "hiddenSubscriberCount": false, + "videoCount": "320" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + }, + { + "kind": "youtube#channel", + "etag": "etag_654321", + "id": "UCxyz987uvw654rst321mno", + "snippet": { + "title": "Daily Vlogs", + "description": "Sharing daily experiences and adventures.", + "customUrl": "@dailyvlogs", + "publishedAt": "2018-03-10T14:20:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_vlog1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_vlog1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_vlog1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Daily Vlogs", + "description": "Sharing daily experiences and adventures." + } + }, + "statistics": { + "viewCount": "530000", + "subscriberCount": "12000", + "hiddenSubscriberCount": false, + "videoCount": "540" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + }, + { + "kind": "youtube#channel", + "etag": "etag_987654", + "id": "UCopq135stu864vwx579yzb", + "snippet": { + "title": "Fitness Pro", + "description": "Workout tips and health advice.", + "customUrl": "@fitnesspro", + "publishedAt": "2017-08-22T07:45:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_fitness1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_fitness1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_fitness1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Fitness Pro", + "description": "Workout tips and health advice." + } + }, + "statistics": { + "viewCount": "850000", + "subscriberCount": "30000", + "hiddenSubscriberCount": false, + "videoCount": "215" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + }, + { + "kind": "youtube#channel", + "etag": "etag_246810", + "id": "UCghi123stu456vwx789yzc", + "snippet": { + "title": "Gamer's Den", + "description": "Game walkthroughs, reviews, and tips.", + "customUrl": "@gamersden", + "publishedAt": "2016-12-05T12:10:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_gamer1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_gamer1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_gamer1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Gamer's Den", + "description": "Game walkthroughs, reviews, and tips." + } + }, + "statistics": { + "viewCount": "1950000", + "subscriberCount": "80000", + "hiddenSubscriberCount": false, + "videoCount": "640" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + }, + { + "kind": "youtube#channel", + "etag": "etag_135790", + "id": "UCjkl987stu654vwx321mno", + "snippet": { + "title": "Cooking Mastery", + "description": "Delicious recipes and cooking tips.", + "customUrl": "@cookingmastery", + "publishedAt": "2019-04-17T16:55:00Z", + "thumbnails": { + "default": { + "url": "https://yt3.ggpht.com/ytc/AIdro_cooking1=s88-c-k-c0x00ffffff-no-rj", + "width": 88, + "height": 88 + }, + "medium": { + "url": "https://yt3.ggpht.com/ytc/AIdro_cooking1=s240-c-k-c0x00ffffff-no-rj", + "width": 240, + "height": 240 + }, + "high": { + "url": "https://yt3.ggpht.com/ytc/AIdro_cooking1=s800-c-k-c0x00ffffff-no-rj", + "width": 800, + "height": 800 + } + }, + "localized": { + "title": "Cooking Mastery", + "description": "Delicious recipes and cooking tips." + } + }, + "statistics": { + "viewCount": "650000", + "subscriberCount": "25000", + "hiddenSubscriberCount": false, + "videoCount": "190" + }, + "status": { + "privacyStatus": "public", + "isLinked": true, + "longUploadsStatus": "eligible" + } + } +] diff --git a/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/playlistItems.json b/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/playlistItems.json new file mode 100644 index 0000000000..26860f77f8 --- /dev/null +++ b/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/playlistItems.json @@ -0,0 +1,104 @@ +[ + { + "kind": "youtube#playlistItem", + "etag": "etag1", + "id": "fakePlaylistItemId1", + "snippet": { + "publishedAt": "2023-02-12T11:15:49Z", + "channelId": "UCXXXXCHANNELID01", + "title": "Video Title 1", + "description": "This is a fake video description for testing.", + "thumbnails": { + "default": { "url": "https://example.com/thumb1.jpg", "width": 120, "height": 90 }, + "medium": { "url": "https://example.com/thumb1.jpg", "width": 320, "height": 180 }, + "high": { "url": "https://example.com/thumb1.jpg", "width": 480, "height": 360 }, + "standard": { "url": "https://example.com/thumb1.jpg", "width": 640, "height": 480 }, + "maxres": { "url": "https://example.com/thumb1.jpg", "width": 1280, "height": 720 } + }, + "channelTitle": "Fake Channel 1", + "playlistId": "PLXXXXFAKEPLAYLISTID01", + "position": 0, + "resourceId": { + "kind": "youtube#video", + "videoId": "FAKEVIDID1" + }, + "videoOwnerChannelTitle": "FakeOwner1", + "videoOwnerChannelId": "UCOWNERCHANNELID01" + }, + "contentDetails": { + "videoId": "FAKEVIDID1", + "videoPublishedAt": "2023-01-13T00:00:09Z" + }, + "status": { + "privacyStatus": "public" + } + }, + { + "kind": "youtube#playlistItem", + "etag": "etag2", + "id": "fakePlaylistItemId2", + "snippet": { + "publishedAt": "2023-02-12T11:16:16Z", + "channelId": "UCXXXXCHANNELID02", + "title": "Video Title 2", + "description": "Another test video description.", + "thumbnails": { + "default": { "url": "https://example.com/thumb2.jpg", "width": 120, "height": 90 }, + "medium": { "url": "https://example.com/thumb2.jpg", "width": 320, "height": 180 }, + "high": { "url": "https://example.com/thumb2.jpg", "width": 480, "height": 360 }, + "standard": { "url": "https://example.com/thumb2.jpg", "width": 640, "height": 480 }, + "maxres": { "url": "https://example.com/thumb2.jpg", "width": 1280, "height": 720 } + }, + "channelTitle": "Fake Channel 2", + "playlistId": "PLXXXXFAKEPLAYLISTID02", + "position": 1, + "resourceId": { + "kind": "youtube#video", + "videoId": "FAKEVIDID2" + }, + "videoOwnerChannelTitle": "FakeOwner2", + "videoOwnerChannelId": "UCOWNERCHANNELID02" + }, + "contentDetails": { + "videoId": "FAKEVIDID2", + "videoPublishedAt": "2016-06-23T11:41:12Z" + }, + "status": { + "privacyStatus": "public" + } + }, + { + "kind": "youtube#playlistItem", + "etag": "etag3", + "id": "fakePlaylistItemId3", + "snippet": { + "publishedAt": "2023-02-12T11:18:13Z", + "channelId": "UCXXXXCHANNELID03", + "title": "Video Title 3", + "description": "Yet another placeholder video description.", + "thumbnails": { + "default": { "url": "https://example.com/thumb3.jpg", "width": 120, "height": 90 }, + "medium": { "url": "https://example.com/thumb3.jpg", "width": 320, "height": 180 }, + "high": { "url": "https://example.com/thumb3.jpg", "width": 480, "height": 360 }, + "standard": { "url": "https://example.com/thumb3.jpg", "width": 640, "height": 480 }, + "maxres": { "url": "https://example.com/thumb3.jpg", "width": 1280, "height": 720 } + }, + "channelTitle": "Fake Channel 3", + "playlistId": "PLXXXXFAKEPLAYLISTID03", + "position": 2, + "resourceId": { + "kind": "youtube#video", + "videoId": "FAKEVIDID3" + }, + "videoOwnerChannelTitle": "FakeOwner3", + "videoOwnerChannelId": "UCOWNERCHANNELID03" + }, + "contentDetails": { + "videoId": "FAKEVIDID3", + "videoPublishedAt": "2017-02-18T17:18:00Z" + }, + "status": { + "privacyStatus": "public" + } + } +] diff --git a/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/playlists.json b/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/playlists.json new file mode 100644 index 0000000000..b6b3cfca88 --- /dev/null +++ b/packages/nodes-base/nodes/Google/YouTube/__test__/node/fixtures/playlists.json @@ -0,0 +1,59 @@ +[ + { + "kind": "youtube#playlist", + "etag": "etag_placeholder_1", + "id": "playlist_id_1", + "snippet": { + "publishedAt": "2024-11-22T12:40:13Z", + "channelId": "channel_id_placeholder", + "title": "Playlist 1", + "description": "Description for Playlist 1.", + "thumbnails": { + "default": { "url": "https://example.com/default.jpg", "width": 120, "height": 90 }, + "medium": { "url": "https://example.com/mqdefault.jpg", "width": 320, "height": 180 }, + "high": { "url": "https://example.com/hqdefault.jpg", "width": 480, "height": 360 }, + "standard": { "url": "https://example.com/sddefault.jpg", "width": 640, "height": 480 }, + "maxres": { "url": "https://example.com/maxresdefault.jpg", "width": 1280, "height": 720 } + }, + "channelTitle": "Channel Placeholder", + "defaultLanguage": "en", + "localized": { + "title": "Playlist 1", + "description": "Description for Playlist 1." + } + }, + "status": { "privacyStatus": "public" }, + "contentDetails": { "itemCount": 16 }, + "player": { + "embedHtml": "" + } + }, + { + "kind": "youtube#playlist", + "etag": "etag_placeholder_2", + "id": "playlist_id_2", + "snippet": { + "publishedAt": "2024-08-30T18:23:41Z", + "channelId": "channel_id_placeholder", + "title": "Playlist 2", + "description": "Description for Playlist 2.", + "thumbnails": { + "default": { "url": "https://example.com/default.jpg", "width": 120, "height": 90 }, + "medium": { "url": "https://example.com/mqdefault.jpg", "width": 320, "height": 180 }, + "high": { "url": "https://example.com/hqdefault.jpg", "width": 480, "height": 360 }, + "standard": { "url": "https://example.com/sddefault.jpg", "width": 640, "height": 480 }, + "maxres": { "url": "https://example.com/maxresdefault.jpg", "width": 1280, "height": 720 } + }, + "channelTitle": "Channel Placeholder", + "localized": { + "title": "Playlist 2", + "description": "Description for Playlist 2." + } + }, + "status": { "privacyStatus": "public" }, + "contentDetails": { "itemCount": 18 }, + "player": { + "embedHtml": "" + } + } +] diff --git a/packages/nodes-base/nodes/Google/YouTube/__test__/node/playlistItems.workflow.json b/packages/nodes-base/nodes/Google/YouTube/__test__/node/playlistItems.workflow.json new file mode 100644 index 0000000000..f515b734ff --- /dev/null +++ b/packages/nodes-base/nodes/Google/YouTube/__test__/node/playlistItems.workflow.json @@ -0,0 +1,412 @@ +{ + "nodes": [ + { + "parameters": {}, + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [0, 200], + "id": "31e68280-caac-4297-bb03-ca6d548b459e", + "name": "When clicking ‘Test workflow’" + }, + { + "parameters": { + "resource": "playlistItem", + "operation": "getAll", + "playlistId": "PLXXXXFAKEPLAYLISTID01", + "limit": 3, + "options": {} + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [220, -100], + "id": "790afd1a-f8b5-4bc1-b839-9658ee112890", + "name": "YouTube", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [440, -100], + "id": "84ef4be3-8c98-449f-ba1e-b08d1492435e", + "name": "Playlist Item Get All" + }, + { + "parameters": { + "resource": "playlistItem", + "operation": "get", + "playlistItemId": "fakePlaylistItemId1", + "options": {} + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [220, 100], + "id": "e3c6f615-7fc1-48cd-a365-25ba425eb62a", + "name": "YouTube1", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [440, 100], + "id": "2bf72f15-3ca8-4ceb-a558-0fc7426ef564", + "name": "Playlist Item Get" + }, + { + "parameters": { + "resource": "playlistItem", + "playlistId": "PLXXXXFAKEPLAYLISTID01", + "videoId": "FAKEVIDID1", + "options": {} + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [220, 300], + "id": "1a84eae4-fd43-445c-8c2b-c5846c1fa427", + "name": "YouTube2", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [440, 300], + "id": "91cef9b3-843d-4ae9-b946-f2bc705cc528", + "name": "Playlist Item Add" + }, + { + "parameters": { + "resource": "playlistItem", + "operation": "delete", + "playlistItemId": "UExWUDRtV2RxbGFhNWlwZEJRWXZVaFgyNk9RTENJRlV2cS41NkI0NEY2RDEwNTU3Q0M2", + "options": {} + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [220, 500], + "id": "829b494e-2a4e-4ec5-a3e2-2dabeed9ea0b", + "name": "YouTube3", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [440, 500], + "id": "3195a72c-b8bd-4d85-ba37-d24df23b1761", + "name": "Playlist Item Delete" + } + ], + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "YouTube", + "type": "main", + "index": 0 + }, + { + "node": "YouTube1", + "type": "main", + "index": 0 + }, + { + "node": "YouTube3", + "type": "main", + "index": 0 + }, + { + "node": "YouTube2", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube": { + "main": [ + [ + { + "node": "Playlist Item Get All", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube1": { + "main": [ + [ + { + "node": "Playlist Item Get", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube2": { + "main": [ + [ + { + "node": "Playlist Item Add", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube3": { + "main": [ + [ + { + "node": "Playlist Item Delete", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "pinData": { + "Playlist Item Get All": [ + { + "json": { + "kind": "youtube#playlistItem", + "etag": "etag1", + "id": "fakePlaylistItemId1", + "snippet": { + "publishedAt": "2023-02-12T11:15:49Z", + "channelId": "UCXXXXCHANNELID01", + "title": "Video Title 1", + "description": "This is a fake video description for testing.", + "thumbnails": { + "default": { "url": "https://example.com/thumb1.jpg", "width": 120, "height": 90 }, + "medium": { "url": "https://example.com/thumb1.jpg", "width": 320, "height": 180 }, + "high": { "url": "https://example.com/thumb1.jpg", "width": 480, "height": 360 }, + "standard": { "url": "https://example.com/thumb1.jpg", "width": 640, "height": 480 }, + "maxres": { "url": "https://example.com/thumb1.jpg", "width": 1280, "height": 720 } + }, + "channelTitle": "Fake Channel 1", + "playlistId": "PLXXXXFAKEPLAYLISTID01", + "position": 0, + "resourceId": { + "kind": "youtube#video", + "videoId": "FAKEVIDID1" + }, + "videoOwnerChannelTitle": "FakeOwner1", + "videoOwnerChannelId": "UCOWNERCHANNELID01" + }, + "contentDetails": { + "videoId": "FAKEVIDID1", + "videoPublishedAt": "2023-01-13T00:00:09Z" + }, + "status": { + "privacyStatus": "public" + } + } + }, + { + "json": { + "kind": "youtube#playlistItem", + "etag": "etag2", + "id": "fakePlaylistItemId2", + "snippet": { + "publishedAt": "2023-02-12T11:16:16Z", + "channelId": "UCXXXXCHANNELID02", + "title": "Video Title 2", + "description": "Another test video description.", + "thumbnails": { + "default": { "url": "https://example.com/thumb2.jpg", "width": 120, "height": 90 }, + "medium": { "url": "https://example.com/thumb2.jpg", "width": 320, "height": 180 }, + "high": { "url": "https://example.com/thumb2.jpg", "width": 480, "height": 360 }, + "standard": { "url": "https://example.com/thumb2.jpg", "width": 640, "height": 480 }, + "maxres": { "url": "https://example.com/thumb2.jpg", "width": 1280, "height": 720 } + }, + "channelTitle": "Fake Channel 2", + "playlistId": "PLXXXXFAKEPLAYLISTID02", + "position": 1, + "resourceId": { + "kind": "youtube#video", + "videoId": "FAKEVIDID2" + }, + "videoOwnerChannelTitle": "FakeOwner2", + "videoOwnerChannelId": "UCOWNERCHANNELID02" + }, + "contentDetails": { + "videoId": "FAKEVIDID2", + "videoPublishedAt": "2016-06-23T11:41:12Z" + }, + "status": { + "privacyStatus": "public" + } + } + }, + { + "json": { + "kind": "youtube#playlistItem", + "etag": "etag3", + "id": "fakePlaylistItemId3", + "snippet": { + "publishedAt": "2023-02-12T11:18:13Z", + "channelId": "UCXXXXCHANNELID03", + "title": "Video Title 3", + "description": "Yet another placeholder video description.", + "thumbnails": { + "default": { "url": "https://example.com/thumb3.jpg", "width": 120, "height": 90 }, + "medium": { "url": "https://example.com/thumb3.jpg", "width": 320, "height": 180 }, + "high": { "url": "https://example.com/thumb3.jpg", "width": 480, "height": 360 }, + "standard": { "url": "https://example.com/thumb3.jpg", "width": 640, "height": 480 }, + "maxres": { "url": "https://example.com/thumb3.jpg", "width": 1280, "height": 720 } + }, + "channelTitle": "Fake Channel 3", + "playlistId": "PLXXXXFAKEPLAYLISTID03", + "position": 2, + "resourceId": { + "kind": "youtube#video", + "videoId": "FAKEVIDID3" + }, + "videoOwnerChannelTitle": "FakeOwner3", + "videoOwnerChannelId": "UCOWNERCHANNELID03" + }, + "contentDetails": { + "videoId": "FAKEVIDID3", + "videoPublishedAt": "2017-02-18T17:18:00Z" + }, + "status": { + "privacyStatus": "public" + } + } + } + ], + "Playlist Item Get": [ + { + "json": { + "kind": "youtube#playlistItem", + "etag": "etag1", + "id": "fakePlaylistItemId1", + "snippet": { + "publishedAt": "2023-02-12T11:15:49Z", + "channelId": "UCXXXXCHANNELID01", + "title": "Video Title 1", + "description": "This is a fake video description for testing.", + "thumbnails": { + "default": { + "url": "https://example.com/thumb1.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://example.com/thumb1.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://example.com/thumb1.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://example.com/thumb1.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://example.com/thumb1.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "Fake Channel 1", + "playlistId": "PLXXXXFAKEPLAYLISTID01", + "position": 0, + "resourceId": { + "kind": "youtube#video", + "videoId": "FAKEVIDID1" + }, + "videoOwnerChannelTitle": "FakeOwner1", + "videoOwnerChannelId": "UCOWNERCHANNELID01" + }, + "contentDetails": { + "videoId": "FAKEVIDID1", + "videoPublishedAt": "2023-01-13T00:00:09Z" + }, + "status": { + "privacyStatus": "public" + } + } + } + ], + "Playlist Item Add": [ + { + "json": { + "kind": "youtube#playlistItem", + "etag": "etag1", + "id": "fakePlaylistItemId1", + "snippet": { + "publishedAt": "2023-02-12T11:15:49Z", + "channelId": "UCXXXXCHANNELID01", + "title": "Video Title 1", + "description": "This is a fake video description for testing.", + "thumbnails": { + "default": { "url": "https://example.com/thumb1.jpg", "width": 120, "height": 90 }, + "medium": { "url": "https://example.com/thumb1.jpg", "width": 320, "height": 180 }, + "high": { "url": "https://example.com/thumb1.jpg", "width": 480, "height": 360 }, + "standard": { "url": "https://example.com/thumb1.jpg", "width": 640, "height": 480 }, + "maxres": { "url": "https://example.com/thumb1.jpg", "width": 1280, "height": 720 } + }, + "channelTitle": "Fake Channel 1", + "playlistId": "PLXXXXFAKEPLAYLISTID01", + "position": 0, + "resourceId": { + "kind": "youtube#video", + "videoId": "FAKEVIDID1" + }, + "videoOwnerChannelTitle": "FakeOwner1", + "videoOwnerChannelId": "UCOWNERCHANNELID01" + }, + "contentDetails": { + "videoId": "FAKEVIDID1", + "videoPublishedAt": "2023-01-13T00:00:09Z" + }, + "status": { + "privacyStatus": "public" + } + } + } + ], + "Playlist Item Delete": [ + { + "json": { + "success": true + } + } + ] + }, + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4" + } +} diff --git a/packages/nodes-base/nodes/Google/YouTube/__test__/node/playlists.workflow.json b/packages/nodes-base/nodes/Google/YouTube/__test__/node/playlists.workflow.json new file mode 100644 index 0000000000..403d96ab67 --- /dev/null +++ b/packages/nodes-base/nodes/Google/YouTube/__test__/node/playlists.workflow.json @@ -0,0 +1,536 @@ +{ + "nodes": [ + { + "parameters": {}, + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [580, 1460], + "id": "974c3af2-835d-47c5-b3ee-879daeb475dc", + "name": "When clicking ‘Test workflow’" + }, + { + "parameters": { + "resource": "playlist", + "operation": "create", + "title": "Playlist 1", + "options": { + "description": "Description for Playlist 1.", + "privacyStatus": "public", + "defaultLanguage": "en" + } + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [800, 1060], + "id": "df81d20e-4c27-4839-873c-3a90b1d9356c", + "name": "YouTube", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": { + "resource": "playlist", + "operation": "update", + "playlistId": "playlist_id_1", + "title": "Test Updated", + "updateFields": { + "description": "This description is updated", + "privacyStatus": "private" + } + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [800, 1260], + "id": "ab9110d9-552d-4e7e-bc8f-78763a2a6395", + "name": "YouTube1", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": { + "resource": "playlist", + "operation": "get", + "playlistId": "playlist_id_1", + "options": {} + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [800, 1460], + "id": "e3939be4-1319-421e-96ca-282fea9f0a9e", + "name": "YouTube2", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": { + "resource": "playlist", + "filters": {}, + "options": {} + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [800, 1660], + "id": "4ea4cd62-6f2f-4e71-ae5e-6ef50718956b", + "name": "YouTube3", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": { + "resource": "playlist", + "operation": "delete", + "playlistId": "playlist_id_1", + "options": {} + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [800, 1860], + "id": "8bf6c082-bd4a-45d1-8625-46062fe7aeed", + "name": "YouTube4", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1020, 1060], + "id": "fe18eabc-0dc5-4ac8-8fe3-9a72558811cc", + "name": "Playlist Create" + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1020, 1260], + "id": "be72d8a0-a83e-46e7-94f0-13e11c93e965", + "name": "Playlist Update" + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1020, 1460], + "id": "6555e151-2214-46bf-8ca5-1a03a929236e", + "name": "Playlist Get" + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1020, 1660], + "id": "f9ac55b1-ff4e-4f98-8c75-05c3f456682c", + "name": "Playlist Get All" + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1020, 1860], + "id": "f2091eb1-cc41-468d-9c3b-6217a9124c85", + "name": "Playlist Delete" + } + ], + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "YouTube1", + "type": "main", + "index": 0 + }, + { + "node": "YouTube", + "type": "main", + "index": 0 + }, + { + "node": "YouTube2", + "type": "main", + "index": 0 + }, + { + "node": "YouTube3", + "type": "main", + "index": 0 + }, + { + "node": "YouTube4", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube": { + "main": [ + [ + { + "node": "Playlist Create", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube1": { + "main": [ + [ + { + "node": "Playlist Update", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube2": { + "main": [ + [ + { + "node": "Playlist Get", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube3": { + "main": [ + [ + { + "node": "Playlist Get All", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube4": { + "main": [ + [ + { + "node": "Playlist Delete", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "pinData": { + "Playlist Create": [ + { + "json": { + "kind": "youtube#playlist", + "etag": "etag_placeholder_1", + "id": "playlist_id_1", + "snippet": { + "publishedAt": "2024-11-22T12:40:13Z", + "channelId": "channel_id_placeholder", + "title": "Playlist 1", + "description": "Description for Playlist 1.", + "thumbnails": { + "default": { + "url": "https://example.com/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://example.com/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://example.com/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://example.com/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://example.com/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "Channel Placeholder", + "defaultLanguage": "en", + "localized": { + "title": "Playlist 1", + "description": "Description for Playlist 1." + } + }, + "status": { + "privacyStatus": "public" + }, + "contentDetails": { + "itemCount": 16 + }, + "player": { + "embedHtml": "" + } + } + } + ], + "Playlist Update": [ + { + "json": { + "kind": "youtube#playlist", + "etag": "etag_placeholder_1", + "id": "playlist_id_1", + "snippet": { + "publishedAt": "2024-11-22T12:40:13Z", + "channelId": "channel_id_placeholder", + "title": "The title is updated", + "description": "The description is updated", + "thumbnails": { + "default": { + "url": "https://example.com/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://example.com/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://example.com/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://example.com/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://example.com/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "Channel Placeholder", + "defaultLanguage": "en", + "localized": { + "title": "The title is updated", + "description": "The description is updated" + } + }, + "status": { + "privacyStatus": "public" + }, + "contentDetails": { + "itemCount": 16 + }, + "player": { + "embedHtml": "" + } + } + } + ], + "Playlist Get": [ + { + "json": { + "kind": "youtube#playlist", + "etag": "etag_placeholder_1", + "id": "playlist_id_1", + "snippet": { + "publishedAt": "2024-11-22T12:40:13Z", + "channelId": "channel_id_placeholder", + "title": "Playlist 1", + "description": "Description for Playlist 1.", + "thumbnails": { + "default": { + "url": "https://example.com/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://example.com/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://example.com/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://example.com/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://example.com/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "Channel Placeholder", + "defaultLanguage": "en", + "localized": { + "title": "Playlist 1", + "description": "Description for Playlist 1." + } + }, + "status": { + "privacyStatus": "public" + }, + "contentDetails": { + "itemCount": 16 + }, + "player": { + "embedHtml": "" + } + } + } + ], + "Playlist Get All": [ + { + "json": { + "kind": "youtube#playlist", + "etag": "etag_placeholder_1", + "id": "playlist_id_1", + "snippet": { + "publishedAt": "2024-11-22T12:40:13Z", + "channelId": "channel_id_placeholder", + "title": "Playlist 1", + "description": "Description for Playlist 1.", + "thumbnails": { + "default": { + "url": "https://example.com/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://example.com/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://example.com/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://example.com/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://example.com/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "Channel Placeholder", + "defaultLanguage": "en", + "localized": { + "title": "Playlist 1", + "description": "Description for Playlist 1." + } + }, + "status": { + "privacyStatus": "public" + }, + "contentDetails": { + "itemCount": 16 + }, + "player": { + "embedHtml": "" + } + } + }, + { + "json": { + "kind": "youtube#playlist", + "etag": "etag_placeholder_2", + "id": "playlist_id_2", + "snippet": { + "publishedAt": "2024-08-30T18:23:41Z", + "channelId": "channel_id_placeholder", + "title": "Playlist 2", + "description": "Description for Playlist 2.", + "thumbnails": { + "default": { + "url": "https://example.com/default.jpg", + "width": 120, + "height": 90 + }, + "medium": { + "url": "https://example.com/mqdefault.jpg", + "width": 320, + "height": 180 + }, + "high": { + "url": "https://example.com/hqdefault.jpg", + "width": 480, + "height": 360 + }, + "standard": { + "url": "https://example.com/sddefault.jpg", + "width": 640, + "height": 480 + }, + "maxres": { + "url": "https://example.com/maxresdefault.jpg", + "width": 1280, + "height": 720 + } + }, + "channelTitle": "Channel Placeholder", + "localized": { + "title": "Playlist 2", + "description": "Description for Playlist 2." + } + }, + "status": { + "privacyStatus": "public" + }, + "contentDetails": { + "itemCount": 18 + }, + "player": { + "embedHtml": "" + } + } + } + ], + "Playlist Delete": [ + { + "json": { + "success": true + } + } + ] + }, + "meta": { + "instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4" + } +} diff --git a/packages/nodes-base/nodes/Google/YouTube/__test__/node/videoCategories.workflow.json b/packages/nodes-base/nodes/Google/YouTube/__test__/node/videoCategories.workflow.json new file mode 100644 index 0000000000..5ecb5cea96 --- /dev/null +++ b/packages/nodes-base/nodes/Google/YouTube/__test__/node/videoCategories.workflow.json @@ -0,0 +1,106 @@ +{ + "nodes": [ + { + "parameters": {}, + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [0, 0], + "id": "31e68280-caac-4297-bb03-ca6d548b459e", + "name": "When clicking ‘Test workflow’" + }, + { + "parameters": { + "resource": "videoCategory", + "regionCode": "GB", + "limit": 3 + }, + "type": "n8n-nodes-base.youTube", + "typeVersion": 1, + "position": [220, 0], + "id": "790afd1a-f8b5-4bc1-b839-9658ee112890", + "name": "YouTube", + "credentials": { + "youTubeOAuth2Api": { + "id": "62", + "name": "YouTube OAuth2 creds" + } + } + }, + { + "parameters": {}, + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [440, 0], + "id": "84ef4be3-8c98-449f-ba1e-b08d1492435e", + "name": "Video Category Get All" + } + ], + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "YouTube", + "type": "main", + "index": 0 + } + ] + ] + }, + "YouTube": { + "main": [ + [ + { + "node": "Video Category Get All", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "pinData": { + "Video Category Get All": [ + { + "json": { + "kind": "youtube#videoCategory", + "etag": "grPOPYEUUZN3ltuDUGEWlrTR90U", + "id": "1", + "snippet": { + "title": "Film & Animation", + "assignable": true, + "channelId": "UCFAKE1234567890TEST" + } + } + }, + { + "json": { + "kind": "youtube#videoCategory", + "etag": "Q0xgUf8BFM8rW3W0R9wNq809xyA", + "id": "2", + "snippet": { + "title": "Autos & Vehicles", + "assignable": true, + "channelId": "UCFAKE1234567890TEST" + } + } + }, + { + "json": { + "kind": "youtube#videoCategory", + "etag": "qnpwjh5QlWM5hrnZCvHisquztC4", + "id": "10", + "snippet": { + "title": "Music", + "assignable": true, + "channelId": "UCFAKE1234567890TEST" + } + } + } + ] + }, + "meta": { + "templateCredsSetupCompleted": true, + "instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4" + } +} diff --git a/packages/nodes-base/test/nodes/FakeCredentialsMap.ts b/packages/nodes-base/test/nodes/FakeCredentialsMap.ts index 2c88ce3a99..e3479fc193 100644 --- a/packages/nodes-base/test/nodes/FakeCredentialsMap.ts +++ b/packages/nodes-base/test/nodes/FakeCredentialsMap.ts @@ -213,6 +213,25 @@ BQIDAQAB expires_in: 86400, }, }, + youTubeOAuth2Api: { + grantType: 'authorizationCode', + authUrl: 'https://accounts.google.com/o/oauth2/v2/auth', + accessTokenUrl: 'https://oauth2.googleapis.com/token', + clientId: 'CLIENTID', + clientSecret: 'CLIENTSECRET', + scope: + 'https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtubepartner-channel-audit', + authQueryParameters: 'access_type=offline&prompt=consent', + authentication: 'body', + oauthTokenData: { + access_token: 'ACCESSTOKEN', + refresh_token: 'REFRESHTOKEN', + scope: + 'https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtubepartner-channel-audit', + token_type: 'bearer', + expires_in: 86400, + }, + }, notionApi: { apiKey: 'key123', }, diff --git a/packages/nodes-base/test/nodes/Helpers.ts b/packages/nodes-base/test/nodes/Helpers.ts index 6046616729..a92c742994 100644 --- a/packages/nodes-base/test/nodes/Helpers.ts +++ b/packages/nodes-base/test/nodes/Helpers.ts @@ -98,7 +98,7 @@ export const equalityTest = async (testData: WorkflowTestData) => { } // Convert errors to JSON so tests can compare - if (json.error instanceof Error) { + if (json?.error instanceof Error) { json.error = JSON.parse( JSON.stringify(json.error, ['message', 'name', 'description', 'context']), );