Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ API_KEY="YOUR_KEY"

# How many events to show per page
DEFAULT_EVENTS_PER_PAGE=7
VITE_DEFAULT_EVENTS_PER_PAGE=7

# Port to run the Vercel dev server on
VERCEL_DEV_PORT=3000
NEXT_PUBLIC_DEFAULT_EVENTS_PER_PAGE=7

# Search radius settings
RADIUS=50
RADIUS_UNIT=miles

# Which hostnames to allow the Vite dev server to respond to
ALLOWED_HOSTNAMES="musemeter.your.domain"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ dist
dist-ssr
*.local

# Next.js
.next/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
Expand All @@ -30,6 +33,5 @@ dist-ssr
# private docs
private/


# testing
coverage/
85 changes: 23 additions & 62 deletions __tests__/api/attractionDetails.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect, beforeEach, afterEach, jest } from '@jest/globals';
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
import nock from 'nock';
import handler from '../../api/attractions/[id].js';
import { GET } from '../../app/api/attractions/[id]/route.ts';
import { NextRequest } from 'next/server';

describe('GET /api/attractions/[id]', () => {
const mockAttraction = {
Expand Down Expand Up @@ -28,13 +29,9 @@ describe('GET /api/attractions/[id]', () => {
};

beforeEach(() => {
// Set required environment variables
process.env.API_KEY = 'test-api-key';

// Clean up any existing nock interceptors
nock.cleanAll();

// Mock the Ticketmaster API
nock('https://app.ticketmaster.com')
.get('/discovery/v2/attractions/1')
.query(true)
Expand All @@ -46,39 +43,21 @@ describe('GET /api/attractions/[id]', () => {
});

it('should return attraction details', async () => {
const req = {
method: 'GET',
query: { id: '1' }
};

const res = {
setHeader: jest.fn(),
status: jest.fn().mockReturnThis(),
json: jest.fn()
};

await handler(req, res);
const request = new NextRequest('http://localhost:3000/api/attractions/1');
const response = await GET(request, { params: Promise.resolve({ id: '1' }) });
const data = await response.json();

expect(res.status).toHaveBeenCalledWith(200);
expect(res.json).toHaveBeenCalledWith(mockAttraction);
expect(response.status).toBe(200);
expect(data).toEqual(mockAttraction);
});

it('should handle missing attraction ID', async () => {
const req = {
method: 'GET',
query: {}
};

const res = {
setHeader: jest.fn(),
status: jest.fn().mockReturnThis(),
json: jest.fn()
};

await handler(req, res);
const request = new NextRequest('http://localhost:3000/api/attractions/');
const response = await GET(request, { params: Promise.resolve({ id: '' }) });
const data = await response.json();

expect(res.status).toHaveBeenCalledWith(400);
expect(res.json).toHaveBeenCalledWith({
expect(response.status).toBe(400);
expect(data).toEqual({
error: 'Attraction ID is required'
});
});
Expand All @@ -90,21 +69,12 @@ describe('GET /api/attractions/[id]', () => {
.query(true)
.reply(500, { error: 'Internal Server Error' });

const req = {
method: 'GET',
query: { id: '1' }
};
const request = new NextRequest('http://localhost:3000/api/attractions/1');
const response = await GET(request, { params: Promise.resolve({ id: '1' }) });
const data = await response.json();

const res = {
setHeader: jest.fn(),
status: jest.fn().mockReturnThis(),
json: jest.fn()
};

await handler(req, res);

expect(res.status).toHaveBeenCalledWith(500);
expect(res.json).toHaveBeenCalledWith(expect.objectContaining({
expect(response.status).toBe(500);
expect(data).toEqual(expect.objectContaining({
error: expect.any(String)
}));
});
Expand All @@ -116,21 +86,12 @@ describe('GET /api/attractions/[id]', () => {
.query(true)
.reply(404, { error: 'Not Found' });

const req = {
method: 'GET',
query: { id: '999' }
};

const res = {
setHeader: jest.fn(),
status: jest.fn().mockReturnThis(),
json: jest.fn()
};

await handler(req, res);
const request = new NextRequest('http://localhost:3000/api/attractions/999');
const response = await GET(request, { params: Promise.resolve({ id: '999' }) });
const data = await response.json();

expect(res.status).toHaveBeenCalledWith(404);
expect(res.json).toHaveBeenCalledWith({
expect(response.status).toBe(404);
expect(data).toEqual({
error: 'Attraction not found'
});
});
Expand Down
84 changes: 23 additions & 61 deletions __tests__/api/attractions.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect, beforeEach, afterEach, jest } from '@jest/globals';
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
import nock from 'nock';
import handler from '../../api/attractions.js';
import { GET } from '../../app/api/attractions/route.ts';
import { NextRequest } from 'next/server';

describe('GET /api/attractions', () => {
const mockAttractions = {
Expand Down Expand Up @@ -46,14 +47,10 @@ describe('GET /api/attractions', () => {
};

beforeEach(() => {
// Set required environment variables
process.env.API_KEY = 'test-api-key';
process.env.DEFAULT_EVENTS_PER_PAGE = '2';

// Clean up any existing nock interceptors
nock.cleanAll();

// Mock the Ticketmaster API
nock('https://app.ticketmaster.com')
.get('/discovery/v2/attractions.json')
.query(true)
Expand All @@ -65,38 +62,21 @@ describe('GET /api/attractions', () => {
});

it('should return a list of attractions for a keyword search', async () => {
const req = {
method: 'GET',
query: { keyword: 'Taylor Swift' }
};

const res = {
setHeader: jest.fn(),
status: jest.fn().mockReturnThis(),
json: jest.fn()
};

await handler(req, res);
const request = new NextRequest('http://localhost:3000/api/attractions?keyword=Taylor+Swift');
const response = await GET(request);
const data = await response.json();

expect(res.status).toHaveBeenCalledWith(200);
expect(res.json).toHaveBeenCalledWith(mockAttractions);
expect(response.status).toBe(200);
expect(data).toEqual(mockAttractions);
});

it('should handle missing keyword parameter', async () => {
const req = {
method: 'GET',
query: {}
};

const res = {
setHeader: jest.fn(),
status: jest.fn().mockReturnThis(),
json: jest.fn()
};

await handler(req, res);
const request = new NextRequest('http://localhost:3000/api/attractions');
const response = await GET(request);
const data = await response.json();

expect(res.json).toHaveBeenCalledWith(expect.objectContaining({
expect(response.status).toBe(400);
expect(data).toEqual(expect.objectContaining({
error: 'Keyword parameter is required'
}));
});
Expand All @@ -108,21 +88,12 @@ describe('GET /api/attractions', () => {
.query(true)
.reply(500, { error: 'Internal Server Error' });

const req = {
method: 'GET',
query: { keyword: 'Taylor Swift' }
};
const request = new NextRequest('http://localhost:3000/api/attractions?keyword=Taylor+Swift');
const response = await GET(request);
const data = await response.json();

const res = {
setHeader: jest.fn(),
status: jest.fn().mockReturnThis(),
json: jest.fn()
};

await handler(req, res);

expect(res.status).toHaveBeenCalledWith(500);
expect(res.json).toHaveBeenCalledWith(expect.objectContaining({
expect(response.status).toBe(500);
expect(data).toEqual(expect.objectContaining({
error: expect.any(String)
}));
});
Expand All @@ -134,21 +105,12 @@ describe('GET /api/attractions', () => {
.query(true)
.reply(429, { error: 'Rate limit exceeded' });

const req = {
method: 'GET',
query: { keyword: 'Taylor Swift' }
};

const res = {
setHeader: jest.fn(),
status: jest.fn().mockReturnThis(),
json: jest.fn()
};

await handler(req, res);
const request = new NextRequest('http://localhost:3000/api/attractions?keyword=Taylor+Swift');
const response = await GET(request);
const data = await response.json();

expect(res.status).toHaveBeenCalledWith(429);
expect(res.json).toHaveBeenCalledWith(expect.objectContaining({
expect(response.status).toBe(429);
expect(data).toEqual(expect.objectContaining({
error: expect.stringContaining('Rate limit exceeded')
}));
});
Expand Down
Loading
Loading