n8n/packages/nodes-base/nodes/Twitter/test/Twitter.test.ts

89 lines
3.3 KiB
TypeScript
Raw Normal View History

import { getWorkflowFilenames, testWorkflows } from '@test/nodes/Helpers';
feat(Twitter Node): Node overhaul (#4788) * First node set up. * Progress: all Resources and Operations updated * Upsates to all resources. * Updated tooltip for Tweet > Search > Tweet fields. * Upodate to resource locator items in User > Search. * Added e.g. to placeholders and minor copy tweaks. * Fixed Operations sorting. * Added a couple of operations back. * Removed 'Authorized API Call'. * Remove authorization header when empty * Import pkce * Add OAuth2 with new grant type to Twitter * Add pkce logic auto assign authorization code if pkce not defined * Add pkce to ui and interfaces * Fix scopes for Oauth2 twitter * Deubg + pass it through header * Add debug console, add airtable cred * Remove all console.logs, make PKCE in th body only when it exists * Remove invalid character ~ * Remove more console.logs * remove body inside query * Remove useless grantype check * Hide oauth2 twitter waiting for overhaul * Remove redundant header removal * Remove more console.logs * Add V2 twitter * Add V1 * Fix description V1, V2 * Fix description for V1 * Add Oauth2 request * Add user lookup * Add search username by ID * Search tweet feat * Wip create tweet * Generic function for returning ID * Add like and retweet feat * Add delete tweet feat * Fix Location tweets * Fix type * Feat List add members * Add scopes for dm and list * Add direct message feature * Improve response data * Fix regex * Add unit test to Twitter v2 * Fix unit test * Remove console.logs * Remove more console.logs * Handle @ in username * Minor copy tweaks. * Add return all logic * Add error for api permission error * Update message api error * Add error for date error * Add notice for TwitterOAuth2 api link * Fix display names location * fix List RLC * Fix like endpoint * Fix error message check * fix(core): Fix OAuth2 callback for grantType=clientCredentials * Improve fix for callback * update pnpm * Fix iso time for end time * sync oauth2Credential * remove unused codeVerifer in Server.ts * Add location and attachments notice * Add notice to oauth1 * Improve notice for twitter * moved credentials notice to TwitterOAuth1Api.credentials.ts --------- Co-authored-by: agobrech <ael.gobrecht@gmail.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in> Co-authored-by: Marcus <marcus@n8n.io>
2023-06-28 03:19:25 -07:00
import nock from 'nock';
const searchResult = {
data: [
{
edit_history_tweet_ids: ['1666357334740811776'],
id: '1666357334740811776',
text: 'RT @business: Extreme heat is happening earlier than usual this year in Asia. Thats posing a grave risk to agriculture and industrial acti…',
},
{
edit_history_tweet_ids: ['1666357331276230656'],
id: '1666357331276230656',
text:
'@ROBVME @sheepsleepdeep @mattxiv Bit like Bloomberg, but then for an incredible average beer brand, to which grown ass adults have some deeply emotional attachment to and going through a teenage break-up with, because a tiktok.\n' +
'Got it.',
},
{
edit_history_tweet_ids: ['1666357319381180417'],
id: '1666357319381180417',
text: "The global economy is set for a weak recovery from the shocks of Covid and Russias war in Ukraine, dogged by persistent inflation and central banks' restrictive policies, the OECD warns https://t.co/HPtelXu8iR https://t.co/rziWHhr8Np",
},
{
edit_history_tweet_ids: ['1666357315946303488'],
id: '1666357315946303488',
text:
'RT @lukedepulford: Love this so much. Variations of “Glory to Hong Kong” are THE WHOLE TOP TEN of the most downloaded song on iTunes.\n' +
'\n' +
'✊\n' +
'\n' +
'h…',
},
{
edit_history_tweet_ids: ['1666357265320869891'],
id: '1666357265320869891',
text: 'RT @business: The SEC said its seeking to freeze https://t.co/35sr7lifRXs assets and protect customer funds, including through the repatr…',
},
{
edit_history_tweet_ids: ['1666357244760555520'],
id: '1666357244760555520',
text: 'RT @BloombergJapan: オプション市場で日経平均先高観強まる、万4000円に備える買い急増 https://t.co/mIcdkgokYj',
},
{
edit_history_tweet_ids: ['1666357239710359552'],
id: '1666357239710359552',
text: "Twitter'a mı girdim bloomberg mi anlamadım,dolar euro altın..maşallahları var,tl mi onun anası sikilmiş.",
},
{
edit_history_tweet_ids: ['1666357235340165120'],
id: '1666357235340165120',
text: 'RT @business: These charts show why Germany needs mass migration https://t.co/rvZixuwwnu',
},
{
edit_history_tweet_ids: ['1666357210409213952'],
id: '1666357210409213952',
text: 'RT @elonmusk: @MattWalshBlog View count is actually understated, as it does not include anything from our API, for example tweets you see i…',
},
{
edit_history_tweet_ids: ['1666357208983166976'],
id: '1666357208983166976',
text: 'RT @coinbureau: There we go. Without proving in a court of law that these tokens are "securities" the SEC may be able to restrict access to…',
},
],
};
const meResult = {
data: { id: '1285192200213626880', name: 'Integration-n8n', username: 'IntegrationN8n' },
};
describe('Test Twitter Request Node', () => {
beforeAll(() => {
const baseUrl = 'https://api.twitter.com/2';
nock.disableNetConnect();
//GET
nock(baseUrl).get('/users/me').reply(200, meResult);
nock(baseUrl)
.get('/tweets/search/recent?query=bloomberg&max_results=10')
.reply(200, searchResult);
});
afterEach(() => {
nock.restore();
});
const workflows = getWorkflowFilenames(__dirname);
testWorkflows(workflows);
});