Skip to content

Commit

Permalink
uupdate newsroom function
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Oct 18, 2024
1 parent 9d38d41 commit 08a8970
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions scripts/build-newsroom-videos.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const { writeFileSync } = require('fs');
const { resolve } = require('path');
const { writeFileSync, mkdirSync, existsSync } = require('fs');
const { resolve, dirname } = require('path');
const fetch = require('node-fetch-2');

async function buildNewsroomVideos(writePath) {
try {
const dir = dirname(writePath);
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true });
}
const response = await fetch('https://youtube.googleapis.com/youtube/v3/search?' + new URLSearchParams({
key: process.env.YOUTUBE_TOKEN,
part: 'snippet',
Expand Down
6 changes: 3 additions & 3 deletions tests/build-newsroom-videos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ describe('buildNewsroomVideos', () => {
const testFilePath = resolve(testDir, 'newsroom_videos.json');

beforeAll(() => {
if (!existsSync(testDir)) {
mkdirSync(testDir, { recursive: true });
}
process.env.YOUTUBE_TOKEN = 'testkey';
});

Expand All @@ -24,6 +21,9 @@ describe('buildNewsroomVideos', () => {
});

beforeEach(() => {
if (!existsSync(testDir)) {
mkdirSync(testDir, { recursive: true });
}
fetch.mockClear();
});

Expand Down

0 comments on commit 08a8970

Please sign in to comment.