diff --git a/apps-portfolio/src/app/articles/[slug]/page.test.tsx b/apps-portfolio/src/app/articles/[slug]/page.test.tsx
new file mode 100644
index 0000000..88f5c39
--- /dev/null
+++ b/apps-portfolio/src/app/articles/[slug]/page.test.tsx
@@ -0,0 +1,15 @@
+// src/app/articles/[slug]/page.test.tsx
+import { getArticle } from '../../lib/data';
+
+describe('ArticlePage', () => {
+ it('should return an article for a valid slug', async () => {
+ const article = await getArticle('2020-12-31-the-art-of-slos');
+ expect(article).toBeDefined();
+ expect(article?.title).toBe('The Art of SLOs');
+ });
+
+ it('should return undefined for an invalid slug', async () => {
+ const article = await getArticle('invalid-slug');
+ expect(article).toBeUndefined();
+ });
+});
diff --git a/apps-portfolio/src/app/lib/data.ts b/apps-portfolio/src/app/lib/data.ts
index 1952ac2..2c3ed9c 100644
--- a/apps-portfolio/src/app/lib/data.ts
+++ b/apps-portfolio/src/app/lib/data.ts
@@ -1,7 +1,7 @@
// src/app/lib/data.ts
import { db } from '../../lib/db';
-import { slugify } from '../../lib/utils';
+import { slugify, formatDate } from '../../lib/utils';
// Server-side function
export async function getTalks() {
@@ -13,7 +13,7 @@ export async function getTalks() {
});
return talks.map((talk) => ({
...talk,
- slug: `${talk.date}-${slugify(talk.title)}`
+ slug: `${formatDate(talk.date)}-${slugify(talk.title)}`
}));
} catch (error) {
console.error('Error fetching talks:', error);
@@ -31,7 +31,7 @@ export async function getArticles() {
});
return articles.map((article) => ({
...article,
- slug: `${article.publish_date}-${slugify(article.title)}`,
+ slug: `${formatDate(new Date(article.publish_date))}-${slugify(article.title)}`,
type: 'article'
}));
} catch (error) {
@@ -62,13 +62,13 @@ export async function getFutureTalks() {
},
where: {
date: {
- gte: new Date().toISOString().split('T')[0],
+ gte: new Date()
}
}
});
return talks.map((talk) => ({
...talk,
- slug: `${talk.date}-${slugify(talk.title)}`
+ slug: `${formatDate(talk.date)}-${slugify(talk.title)}`
}));
}
@@ -79,13 +79,13 @@ export async function getPastTalks() {
},
where: {
date: {
- lt: new Date().toISOString().split('T')[0],
+ lt: new Date()
}
}
});
return talks.map((talk) => ({
...talk,
- slug: `${talk.date}-${slugify(talk.title)}`
+ slug: `${formatDate(talk.date)}-${slugify(talk.title)}`
}));
}
@@ -104,7 +104,7 @@ export async function getHighlightedTalks() {
});
return talks.map((talk) => ({
...talk,
- slug: `${talk.date}-${slugify(talk.title)}`
+ slug: `${formatDate(talk.date)}-${slugify(talk.title)}`
}));
}
@@ -122,7 +122,6 @@ export async function getHighlightedArticles() {
});
return articles.map((article) => ({
...article,
- slug: `${article.publish_date}-${slugify(article.title)}`
+ slug: `${formatDate(new Date(article.publish_date))}-${slugify(article.title)}`
}));
-}
-
+}
\ No newline at end of file
diff --git a/apps-portfolio/src/app/talks/[slug]/page.test.tsx b/apps-portfolio/src/app/talks/[slug]/page.test.tsx
index e2e753f..a5e0040 100644
--- a/apps-portfolio/src/app/talks/[slug]/page.test.tsx
+++ b/apps-portfolio/src/app/talks/[slug]/page.test.tsx
@@ -1,70 +1,15 @@
-import { render, screen } from '@testing-library/react';
-import TalkPage from './page';
-import { getTalk } from '../../lib/data'; // Import getTalk directly
-import { notFound } from 'next/navigation';
-import { vi } from 'vitest';
-
-// Mock the next/navigation notFound function
-vi.mock('next/navigation', () => ({
- notFound: vi.fn(() => { throw new Error('notFound called'); }),
-}));
-
-// Mock the getTalk function from src/app/lib/data.ts
-vi.mock('../../lib/data', () => ({
- getTalk: vi.fn(),
- // Ensure other exports from data.ts are also mocked if used by getTalk
- getTalks: vi.fn(),
- getArticles: vi.fn(),
- getFutureTalks: vi.fn(),
- getHighlightedTalks: vi.fn(),
- getHighlightedArticles: vi.fn(),
-}));
-
-describe.skip('TalkPage', () => {
- const mockTalk = {
- id: 1,
- title: 'Test Talk Title',
- event: 'Test Event',
- date: '2025-01-01',
- location: 'Test Location',
- country_code: 'us',
- session_url: 'http://example.com/session',
- video_url: 'http://example.com/video',
- slides_url: 'http://example.com/slides',
- status: 'delivered',
- tags: 'tag1,tag2',
- image: '/images/placeholder-image.png',
- event_description: 'Event description.',
- talk_description: 'Talk description.',
- slug: '2025-01-01-test-talk-title',
- };
-
- beforeEach(() => {
- // Reset mocks before each test
- (getTalk as vi.Mock).mockReset(); // Use getTalk directly
- (notFound as vi.Mock).mockReset();
- });
-
- it('renders talk details when talk is found', async () => {
- // Mock getTalk to return the mockTalk
- (getTalk as vi.Mock).mockResolvedValue(mockTalk);
-
- await render();
-
- // Assert that the talk title is displayed
- expect(screen.getByText(mockTalk.title)).toBeInTheDocument();
- expect(screen.getByText(`${mockTalk.event} - ${mockTalk.date}`)).toBeInTheDocument();
- expect(screen.queryByText('404: This page could not be found.')).not.toBeInTheDocument();
- expect(notFound).not.toHaveBeenCalled();
+// src/app/talks/[slug]/page.test.tsx
+import { getTalk } from '../../lib/data';
+
+describe('TalkPage', () => {
+ it('should return a talk for a valid slug', async () => {
+ const talk = await getTalk('2025-11-08-agenti-in-volo-unanalisi-approfondita-sulla-creazione-di-un-agente-di-viaggio-in-tempo-reale');
+ expect(talk).toBeDefined();
+ expect(talk?.title).toBe("Agenti in Volo: Un'Analisi Approfondita sulla Creazione di un Agente di Viaggio in Tempo Reale ✈️");
});
- it('calls notFound when talk is not found', async () => {
- // Mock getTalk to return undefined (talk not found)
- (getTalk as vi.Mock).mockResolvedValue(undefined); // Simulate talk not found
-
- await render();
-
- // Assert that notFound was called
- expect(notFound).toHaveBeenCalled();
+ it('should return undefined for an invalid slug', async () => {
+ const talk = await getTalk('invalid-slug');
+ expect(talk).toBeUndefined();
});
-});
+});
\ No newline at end of file
diff --git a/apps-portfolio/src/lib/utils.ts b/apps-portfolio/src/lib/utils.ts
index ca25a11..78dae3a 100644
--- a/apps-portfolio/src/lib/utils.ts
+++ b/apps-portfolio/src/lib/utils.ts
@@ -1,4 +1,10 @@
// src/lib/utils.ts
+
+export const formatDate = (date: Date): string => {
+ if (!date) return '';
+ return new Date(date).toISOString().split('T')[0];
+};
+
export const slugify = (str: string) => {
if (!str) return '';
const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúúūǘůűųẃẍÿýžźż·/_,:;'
@@ -30,6 +36,4 @@ export function extractYouTubeVideoId(url: string) {
export function parseDateString(dateString: string): Date {
const [year, month, day] = dateString.split('-').map(Number);
return new Date(year, month - 1, day);
-}
-
-
+}
\ No newline at end of file