refactor: update environment variables and dependencies

This commit is contained in:
2025-02-23 14:42:06 +01:00
parent 23a145b37e
commit 69f254c791
12 changed files with 116 additions and 143 deletions

View File

@@ -18,8 +18,8 @@ afterAll(() => {
beforeEach(() => {
nodemailermock.mock.reset();
process.env.NEXT_PUBLIC_MY_EMAIL = 'test@dki.one';
process.env.NEXT_PUBLIC_MY_PASSWORD = 'test-password';
process.env.MY_EMAIL = 'test@dki.one';
process.env.MY_PASSWORD = 'test-password';
});
describe('POST /api/email', () => {
@@ -43,8 +43,8 @@ describe('POST /api/email', () => {
});
it('should return an error if EMAIL or PASSWORD is missing', async () => {
delete process.env.NEXT_PUBLIC_MY_EMAIL;
delete process.env.NEXT_PUBLIC_MY_PASSWORD;
delete process.env.MY_EMAIL;
delete process.env.MY_PASSWORD;
const mockRequest = {
json: jest.fn().mockResolvedValue({

View File

@@ -1,6 +1,43 @@
import { GET } from '@/app/api/fetchAllProjects/route';
import { NextResponse } from 'next/server';
import { mockFetch } from '@/app/__tests__/__mocks__/mock-fetch';
// Wir mocken node-fetch direkt
jest.mock('node-fetch', () => {
return jest.fn(() =>
Promise.resolve({
json: () =>
Promise.resolve({
posts: [
{
id: '67ac8dfa709c60000117d312',
title: 'Just Doing Some Testing',
meta_description: 'Hello bla bla bla bla',
slug: 'just-doing-some-testing',
updated_at: '2025-02-13T14:25:38.000+00:00',
},
{
id: '67aaffc3709c60000117d2d9',
title: 'Blockchain Based Voting System',
meta_description:
'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.',
slug: 'blockchain-based-voting-system',
updated_at: '2025-02-13T16:54:42.000+00:00',
},
],
meta: {
pagination: {
limit: 'all',
next: null,
page: 1,
pages: 1,
prev: null,
total: 2,
},
},
}),
})
);
});
jest.mock('next/server', () => ({
NextResponse: {
@@ -10,48 +47,27 @@ jest.mock('next/server', () => ({
describe('GET /api/fetchAllProjects', () => {
beforeAll(() => {
process.env.NEXT_PUBLIC_GHOST_API_URL = 'http://localhost:2368';
process.env.NEXT_PUBLIC_GHOST_API_KEY = 'some-key';
global.fetch = mockFetch({
posts: [
{
id: '67ac8dfa709c60000117d312',
title: 'Just Doing Some Testing',
meta_description: 'Hello bla bla bla bla',
slug: 'just-doing-some-testing',
updated_at: '2025-02-13T14:25:38.000+00:00',
},
{
id: '67aaffc3709c60000117d2d9',
title: 'Blockchain Based Voting System',
meta_description: 'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.',
slug: 'blockchain-based-voting-system',
updated_at: '2025-02-13T16:54:42.000+00:00',
},
],
});
process.env.GHOST_API_URL = 'http://localhost:2368';
process.env.GHOST_API_KEY = 'some-key';
});
it('should return a list of projects', async () => {
it('should return a list of projects (partial match)', async () => {
await GET();
expect(NextResponse.json).toHaveBeenCalledWith({
posts: [
{
// Den tatsächlichen Argumentwert extrahieren
const responseArg = (NextResponse.json as jest.Mock).mock.calls[0][0];
expect(responseArg).toMatchObject({
posts: expect.arrayContaining([
expect.objectContaining({
id: '67ac8dfa709c60000117d312',
title: 'Just Doing Some Testing',
meta_description: 'Hello bla bla bla bla',
slug: 'just-doing-some-testing',
updated_at: '2025-02-13T14:25:38.000+00:00',
},
{
}),
expect.objectContaining({
id: '67aaffc3709c60000117d2d9',
title: 'Blockchain Based Voting System',
meta_description: 'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.',
slug: 'blockchain-based-voting-system',
updated_at: '2025-02-13T16:54:42.000+00:00',
},
],
}),
]),
});
});
});

View File

@@ -10,8 +10,8 @@ jest.mock('next/server', () => ({
describe('GET /api/fetchProject', () => {
beforeAll(() => {
process.env.NEXT_PUBLIC_GHOST_API_URL = 'http://localhost:2368';
process.env.NEXT_PUBLIC_GHOST_API_KEY = 'some-key';
process.env.GHOST_API_URL = 'http://localhost:2368';
process.env.GHOST_API_KEY = 'some-key';
global.fetch = mockFetch({
posts: [

View File

@@ -7,8 +7,8 @@ jest.mock('next/server', () => ({
describe('GET /api/sitemap', () => {
beforeAll(() => {
process.env.NEXT_PUBLIC_GHOST_API_URL = 'http://localhost:2368';
process.env.NEXT_PUBLIC_GHOST_API_KEY = 'test-api-key';
process.env.GHOST_API_URL = 'http://localhost:2368';
process.env.GHOST_API_KEY = 'test-api-key';
process.env.NEXT_PUBLIC_BASE_URL = 'https://dki.one';
global.fetch = mockFetch({
posts: [

View File

@@ -6,8 +6,8 @@ import { mockFetch } from '@/app/__tests__/__mocks__/mock-fetch';
describe('Projects', () => {
beforeAll(() => {
process.env.NEXT_PUBLIC_GHOST_API_URL = 'http://localhost:2368';
process.env.NEXT_PUBLIC_GHOST_API_KEY = 'some-key';
process.env.GHOST_API_URL = 'http://localhost:2368';
process.env.GHOST_API_KEY = 'some-key';
global.fetch = mockFetch({
posts: [
{

View File

@@ -13,8 +13,8 @@ jest.mock('next/navigation', () => ({
describe('ProjectDetails', () => {
beforeAll(() => {
process.env.NEXT_PUBLIC_GHOST_API_URL = 'http://localhost:2368';
process.env.NEXT_PUBLIC_GHOST_API_KEY = 'some-key';
process.env.GHOST_API_URL = 'http://localhost:2368';
process.env.GHOST_API_KEY = 'some-key';
global.fetch = mockFetch({
posts: [
{

View File

@@ -12,8 +12,8 @@ interface ProjectsData {
export const dynamic = "force-dynamic";
export const runtime = "nodejs"; // Force Node runtime
const GHOST_API_URL = process.env.NEXT_PUBLIC_GHOST_API_URL;
const GHOST_API_KEY = process.env.NEXT_PUBLIC_GHOST_API_KEY;
const GHOST_API_URL = process.env.GHOST_API_URL;
const GHOST_API_KEY = process.env.GHOST_API_KEY;
// Funktion, um die XML für die Sitemap zu generieren
function generateXml(sitemapRoutes: { url: string; lastModified: string }[]) {