Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 56a56e590e | |||
| 9a6188b2ae | |||
| fea0585a75 | |||
| 820b1d8d84 | |||
| 48b524ef84 | |||
| e602e83642 | |||
| ac8562ea51 | |||
| b1c4e9a0ce | |||
| 413ebaeaee | |||
| f27efebd82 | |||
| 30ea4e4e86 | |||
| 75cb6ed29d | |||
| fa13ed86c9 | |||
| 66e574d5ec | |||
| a9138cfbe4 |
@@ -8,7 +8,6 @@ on:
|
|||||||
- "Dockerfile.ci-base"
|
- "Dockerfile.ci-base"
|
||||||
- "package.json"
|
- "package.json"
|
||||||
- "bun.lock"
|
- "bun.lock"
|
||||||
- "package-lock.json"
|
|
||||||
- ".gitea/workflows/build-ci-images.yml"
|
- ".gitea/workflows/build-ci-images.yml"
|
||||||
schedule:
|
schedule:
|
||||||
# Weekly rebuild to get latest Playwright/Bun versions
|
# Weekly rebuild to get latest Playwright/Bun versions
|
||||||
@@ -53,13 +52,14 @@ jobs:
|
|||||||
|
|
||||||
- name: Build and push CI base image
|
- name: Build and push CI base image
|
||||||
run: |
|
run: |
|
||||||
|
WORKSPACE_DIR="$GITHUB_WORKSPACE"
|
||||||
|
# Build with multiple tags
|
||||||
docker build \
|
docker build \
|
||||||
--file Dockerfile.ci-base \
|
--context "$WORKSPACE_DIR" \
|
||||||
|
--file "$WORKSPACE_DIR/Dockerfile.ci-base" \
|
||||||
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:latest \
|
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:latest \
|
||||||
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:playwright-${{ steps.meta.outputs.playwright_version }} \
|
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:playwright-${{ steps.meta.outputs.playwright_version }} \
|
||||||
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:${{ github.sha }} \
|
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:${{ github.sha }} \
|
||||||
--push \
|
|
||||||
.
|
|
||||||
|
|
||||||
- name: Clean up
|
- name: Clean up
|
||||||
if: always()
|
if: always()
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ jobs:
|
|||||||
|
|
||||||
# Wait for production site to be healthy
|
# Wait for production site to be healthy
|
||||||
echo "Waiting for production site to be healthy..."
|
echo "Waiting for production site to be healthy..."
|
||||||
for i in {1..6}; do
|
for i in {1..30}; do
|
||||||
if curl -sf https://euchre.notsosm.art/api/health > /dev/null 2>&1; then
|
if curl -sf https://euchre.notsosm.art/api/health > /dev/null 2>&1; then
|
||||||
echo "✅ Production successfully deployed with version ${VERSION}"
|
echo "✅ Production successfully deployed with version ${VERSION}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
sleep 15
|
sleep 0.5
|
||||||
done
|
done
|
||||||
echo "❌ Production deployment failed"
|
echo "❌ Production deployment failed"
|
||||||
docker compose logs app
|
docker compose logs app
|
||||||
|
|||||||
+19
-22
@@ -15,21 +15,21 @@ jobs:
|
|||||||
container:
|
container:
|
||||||
image: docker.notsosm.art/euchre-camp/ci-base:latest
|
image: docker.notsosm.art/euchre-camp/ci-base:latest
|
||||||
options: --user root
|
options: --user root
|
||||||
env:
|
|
||||||
DATABASE_URL: postgresql://user:pass@localhost:5432/dummy
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci --legacy-peer-deps
|
run: bun install
|
||||||
|
|
||||||
- name: Generate Prisma client
|
- name: Generate Prisma client
|
||||||
run: npx prisma generate
|
run: bun x prisma generate
|
||||||
|
env:
|
||||||
|
DATABASE_URL: postgresql://user:pass@localhost:5432/dummy
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
run: npm test
|
run: bun test src/__tests__/unit/ src/__tests__/*.test.tsx src/__tests__/auth-simple.test.ts
|
||||||
|
|
||||||
build-and-deploy-ci:
|
build-and-deploy-ci:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -37,20 +37,16 @@ jobs:
|
|||||||
container:
|
container:
|
||||||
image: docker.notsosm.art/euchre-camp/ci-base:latest
|
image: docker.notsosm.art/euchre-camp/ci-base:latest
|
||||||
options: --user root
|
options: --user root
|
||||||
volumes:
|
|
||||||
- /var/lib/casaos/apps:/apps
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# Required for acceptance tests - they import prisma via @/ path alias
|
|
||||||
# and @cucumber/cucumber for cucumber-e2e tests
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci --legacy-peer-deps
|
run: bun install
|
||||||
|
|
||||||
- name: Generate Prisma client
|
- name: Generate Prisma client
|
||||||
run: npx prisma generate
|
run: bun x prisma generate
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: postgresql://user:pass@localhost:5432/dummy
|
DATABASE_URL: postgresql://user:pass@localhost:5432/dummy
|
||||||
|
|
||||||
@@ -62,12 +58,15 @@ jobs:
|
|||||||
|
|
||||||
- name: Build Docker image for PR
|
- name: Build Docker image for PR
|
||||||
run: |
|
run: |
|
||||||
|
WORKSPACE_DIR="$GITHUB_WORKSPACE"
|
||||||
IMAGE_TAG="pr-${{ steps.info.outputs.pr_number }}-${{ steps.info.outputs.short_sha }}"
|
IMAGE_TAG="pr-${{ steps.info.outputs.pr_number }}-${{ steps.info.outputs.short_sha }}"
|
||||||
docker build \
|
docker build \
|
||||||
|
--context "$WORKSPACE_DIR" \
|
||||||
|
--file "$WORKSPACE_DIR/Dockerfile" \
|
||||||
--target runner \
|
--target runner \
|
||||||
--build-arg GIT_COMMIT=$GITHUB_SHA \
|
--build-arg GIT_COMMIT=$GITHUB_SHA \
|
||||||
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${IMAGE_TAG} \
|
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${IMAGE_TAG} \
|
||||||
.
|
"$WORKSPACE_DIR"
|
||||||
|
|
||||||
- name: Update CI site compose and restart
|
- name: Update CI site compose and restart
|
||||||
run: |
|
run: |
|
||||||
@@ -77,34 +76,33 @@ jobs:
|
|||||||
# Update the image tag in the compose file
|
# Update the image tag in the compose file
|
||||||
sed -i "s|image: docker.notsosm.art/euchre-camp:[a-zA-Z0-9.-]*|image: docker.notsosm.art/euchre-camp:${IMAGE_TAG}|" ${COMPOSE_FILE}
|
sed -i "s|image: docker.notsosm.art/euchre-camp:[a-zA-Z0-9.-]*|image: docker.notsosm.art/euchre-camp:${IMAGE_TAG}|" ${COMPOSE_FILE}
|
||||||
|
|
||||||
# Image was built locally in the previous step; compose uses it without pulling
|
# Pull the new image and restart the CI stack
|
||||||
cd /apps/euchre_camp_ci
|
cd /apps/euchre_camp_ci
|
||||||
|
docker compose pull app
|
||||||
docker compose up -d app
|
docker compose up -d app
|
||||||
|
|
||||||
- name: Wait for CI site to be ready
|
- name: Wait for CI site to be healthy
|
||||||
run: |
|
run: |
|
||||||
echo "Waiting for Next.js to start..."
|
for i in {1..30}; do
|
||||||
sleep 20
|
|
||||||
for i in {1..6}; do
|
|
||||||
if curl -sf https://euchre-ci.notsosm.art/api/health > /dev/null 2>&1; then
|
if curl -sf https://euchre-ci.notsosm.art/api/health > /dev/null 2>&1; then
|
||||||
echo "CI site is healthy"
|
echo "CI site is healthy"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
sleep 15
|
sleep 0.5
|
||||||
done
|
done
|
||||||
echo "CI site failed to become healthy after 90 seconds"
|
echo "CI site failed to become healthy after 15 seconds"
|
||||||
docker compose -f /apps/euchre_camp_ci/docker-compose.yml logs app
|
docker compose -f /apps/euchre_camp_ci/docker-compose.yml logs app
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
- name: Run acceptance tests
|
- name: Run acceptance tests
|
||||||
run: DATABASE_URL="${{ secrets.CI_DATABASE_URL }}" npx playwright test e2e/
|
run: DATABASE_URL="${{ secrets.CI_DATABASE_URL }}" bun test:acceptance
|
||||||
env:
|
env:
|
||||||
CI: true
|
CI: true
|
||||||
|
|
||||||
- name: Cleanup PR images
|
- name: Cleanup PR images
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
docker rmi --force ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ steps.info.outputs.pr_number }}-${{ steps.info.outputs.short_sha }} || true
|
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ steps.info.outputs.pr_number }}-${{ steps.info.outputs.short_sha }} || true
|
||||||
|
|
||||||
analyze-bump-type:
|
analyze-bump-type:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -148,7 +146,6 @@ jobs:
|
|||||||
echo "reason=$REASON" >> $GITHUB_OUTPUT
|
echo "reason=$REASON" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Comment bump type on PR
|
- name: Comment bump type on PR
|
||||||
if: github.event_name == 'pull_request'
|
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ jobs:
|
|||||||
echo "Bumping version: $BUMP"
|
echo "Bumping version: $BUMP"
|
||||||
|
|
||||||
# Run the bump script
|
# Run the bump script
|
||||||
node scripts/bump-version.js "$BUMP" --yes
|
bun run scripts/bump-version.js "$BUMP" --yes
|
||||||
|
|
||||||
# Get new version
|
# Get new version
|
||||||
NEW_VERSION=$(node -e "console.log(require('./package.json').version)")
|
NEW_VERSION=$(bun -e "console.log(require('./package.json').version)")
|
||||||
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||||
echo "New version: $NEW_VERSION"
|
echo "New version: $NEW_VERSION"
|
||||||
|
|
||||||
@@ -110,30 +110,35 @@ jobs:
|
|||||||
- name: Build test-capable image
|
- name: Build test-capable image
|
||||||
if: steps.commit.outputs.committed == 'true'
|
if: steps.commit.outputs.committed == 'true'
|
||||||
run: |
|
run: |
|
||||||
|
WORKSPACE_DIR="$GITHUB_WORKSPACE"
|
||||||
docker build \
|
docker build \
|
||||||
|
--context "$WORKSPACE_DIR" \
|
||||||
|
--file "$WORKSPACE_DIR/Dockerfile" \
|
||||||
--target test-runner \
|
--target test-runner \
|
||||||
--build-arg GIT_COMMIT=${{ github.sha }} \
|
--build-arg GIT_COMMIT=${{ github.sha }} \
|
||||||
-t ${{ env.IMAGE_NAME }}-test:${{ steps.version.outputs.new_version }} \
|
-t ${{ env.IMAGE_NAME }}-test:${{ steps.version.outputs.new_version }} \
|
||||||
.
|
"$WORKSPACE_DIR"
|
||||||
|
|
||||||
- name: Run tests inside test-capable container
|
- name: Run tests inside test-capable container
|
||||||
if: steps.commit.outputs.committed == 'true'
|
if: steps.commit.outputs.committed == 'true'
|
||||||
run: |
|
run: |
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
-e DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" \
|
-e DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" \
|
||||||
-e NODE_ENV=test \
|
|
||||||
${{ env.IMAGE_NAME }}-test:${{ steps.version.outputs.new_version }} \
|
${{ env.IMAGE_NAME }}-test:${{ steps.version.outputs.new_version }} \
|
||||||
npm test
|
bun test 'src/__tests__/unit/**' 'src/__tests__/*.test.tsx' 'src/__tests__/auth-simple.test.ts'
|
||||||
|
|
||||||
- name: Build production image
|
- name: Build production image
|
||||||
if: steps.commit.outputs.committed == 'true'
|
if: steps.commit.outputs.committed == 'true'
|
||||||
run: |
|
run: |
|
||||||
|
WORKSPACE_DIR="$GITHUB_WORKSPACE"
|
||||||
docker build \
|
docker build \
|
||||||
|
--context "$WORKSPACE_DIR" \
|
||||||
|
--file "$WORKSPACE_DIR/Dockerfile" \
|
||||||
--target runner \
|
--target runner \
|
||||||
--build-arg GIT_COMMIT=${{ github.sha }} \
|
--build-arg GIT_COMMIT=${{ github.sha }} \
|
||||||
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.new_version }} \
|
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.new_version }} \
|
||||||
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
|
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
|
||||||
.
|
"$WORKSPACE_DIR"
|
||||||
|
|
||||||
- name: Push Docker images
|
- name: Push Docker images
|
||||||
if: steps.commit.outputs.committed == 'true'
|
if: steps.commit.outputs.committed == 'true'
|
||||||
@@ -177,12 +182,12 @@ jobs:
|
|||||||
|
|
||||||
# Wait for container to be healthy
|
# Wait for container to be healthy
|
||||||
echo "Waiting for dev site to be healthy..."
|
echo "Waiting for dev site to be healthy..."
|
||||||
for i in {1..6}; do
|
for i in {1..30}; do
|
||||||
if curl -sf https://euchre-dev.notsosm.art/api/health > /dev/null 2>&1; then
|
if curl -sf https://euchre-dev.notsosm.art/api/health > /dev/null 2>&1; then
|
||||||
echo "✅ Dev environment successfully deployed with version ${{ steps.version.outputs.new_version }}"
|
echo "✅ Dev environment successfully deployed with version ${{ steps.version.outputs.new_version }}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
sleep 15
|
sleep 0.5
|
||||||
done
|
done
|
||||||
echo "❌ Dev environment deployment failed"
|
echo "❌ Dev environment deployment failed"
|
||||||
docker compose logs app
|
docker compose logs app
|
||||||
|
|||||||
+11
-11
@@ -4,7 +4,7 @@
|
|||||||
FROM oven/bun:alpine AS builder
|
FROM oven/bun:alpine AS builder
|
||||||
|
|
||||||
# Install dependencies (needed for native modules)
|
# Install dependencies (needed for native modules)
|
||||||
RUN apk add --no-cache python3 make g++ nodejs npm
|
RUN apk add --no-cache python3 make g++
|
||||||
|
|
||||||
# Set working directory
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -13,14 +13,14 @@ WORKDIR /app
|
|||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
# Install dependencies (including dev dependencies for building)
|
# Install dependencies (including dev dependencies for building)
|
||||||
RUN npm ci --legacy-peer-deps
|
RUN bun install
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Generate Prisma client (with dummy PostgreSQL DATABASE_URL for build-time generation)
|
# Generate Prisma client (with dummy PostgreSQL DATABASE_URL for build-time generation)
|
||||||
# Note: A dummy URL is used since the real database is not available during build
|
# Note: A dummy URL is used since the real database is not available during build
|
||||||
RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma generate
|
RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" bun x prisma generate
|
||||||
|
|
||||||
# Build the application (with dummy DATABASE_URL for static page generation and git commit)
|
# Build the application (with dummy DATABASE_URL for static page generation and git commit)
|
||||||
ARG GIT_COMMIT=unknown
|
ARG GIT_COMMIT=unknown
|
||||||
@@ -30,7 +30,7 @@ RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:
|
|||||||
FROM oven/bun:alpine AS test-runner
|
FROM oven/bun:alpine AS test-runner
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN apk add --no-cache python3 make g++ git nodejs npm
|
RUN apk add --no-cache python3 make g++ git
|
||||||
|
|
||||||
# Set working directory
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -39,19 +39,19 @@ WORKDIR /app
|
|||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
# Install ALL dependencies (including dev dependencies for testing)
|
# Install ALL dependencies (including dev dependencies for testing)
|
||||||
RUN npm ci --legacy-peer-deps
|
RUN bun install
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Generate Prisma client
|
# Generate Prisma client
|
||||||
RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma generate
|
RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" bun x prisma generate
|
||||||
|
|
||||||
# Stage 3: Production runner
|
# Stage 3: Production runner
|
||||||
FROM oven/bun:alpine AS runner
|
FROM oven/bun:alpine AS runner
|
||||||
|
|
||||||
# Install dumb-init and npm for production install
|
# Install dumb-init for proper signal handling
|
||||||
RUN apk add --no-cache dumb-init nodejs npm
|
RUN apk add --no-cache dumb-init
|
||||||
|
|
||||||
# Create non-root user
|
# Create non-root user
|
||||||
RUN addgroup --system --gid 1001 euchre && \
|
RUN addgroup --system --gid 1001 euchre && \
|
||||||
@@ -64,15 +64,15 @@ WORKDIR /app
|
|||||||
COPY --from=builder --chown=euchre:euchre /app/.next ./.next
|
COPY --from=builder --chown=euchre:euchre /app/.next ./.next
|
||||||
COPY --from=builder --chown=euchre:euchre /app/public ./public
|
COPY --from=builder --chown=euchre:euchre /app/public ./public
|
||||||
COPY --from=builder --chown=euchre:euchre /app/package.json ./package.json
|
COPY --from=builder --chown=euchre:euchre /app/package.json ./package.json
|
||||||
COPY --from=builder --chown=euchre:euchre /app/package-lock.json ./package-lock.json
|
COPY --from=builder --chown=euchre:euchre /app/bun.lock ./bun.lock
|
||||||
COPY --from=builder --chown=euchre:euchre /app/prisma ./prisma
|
COPY --from=builder --chown=euchre:euchre /app/prisma ./prisma
|
||||||
|
|
||||||
# Install only production dependencies
|
# Install only production dependencies
|
||||||
RUN npm ci --legacy-peer-deps --omit=dev
|
RUN bun install --production
|
||||||
|
|
||||||
# Generate Prisma client
|
# Generate Prisma client
|
||||||
# Note: We need to set DATABASE_URL even for generation because prisma.config.ts requires it
|
# Note: We need to set DATABASE_URL even for generation because prisma.config.ts requires it
|
||||||
RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma generate
|
RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" bun x prisma generate
|
||||||
|
|
||||||
# Switch to non-root user
|
# Switch to non-root user
|
||||||
USER euchre
|
USER euchre
|
||||||
|
|||||||
@@ -259,12 +259,12 @@ deploy-prod version:
|
|||||||
docker compose pull app && \
|
docker compose pull app && \
|
||||||
docker compose up -d app && \
|
docker compose up -d app && \
|
||||||
echo "Waiting for production site to be healthy..." && \
|
echo "Waiting for production site to be healthy..." && \
|
||||||
for i in {1..6}; do \
|
for i in {1..30}; do \
|
||||||
if curl -sf https://euchre.notsosm.art/api/health > /dev/null 2>&1; then \
|
if curl -sf https://euchre.notsosm.art/api/health > /dev/null 2>&1; then \
|
||||||
echo "✅ Production successfully deployed with version {{version}}"; \
|
echo "✅ Production successfully deployed with version {{version}}"; \
|
||||||
exit 0; \
|
exit 0; \
|
||||||
fi; \
|
fi; \
|
||||||
sleep 15; \
|
sleep 0.5; \
|
||||||
done && \
|
done && \
|
||||||
echo "❌ Production deployment failed - health check timed out"; \
|
echo "❌ Production deployment failed - health check timed out"; \
|
||||||
docker compose logs app; \
|
docker compose logs app; \
|
||||||
|
|||||||
Generated
-10473
File diff suppressed because it is too large
Load Diff
@@ -47,7 +47,9 @@ describe('getSession', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns null when an error occurs', async () => {
|
it('returns null when an error occurs', async () => {
|
||||||
mockFetch.mockRejectedValue(new Error('Network error'))
|
mockFetch.mockImplementation(async () => {
|
||||||
|
throw new Error('Network error')
|
||||||
|
})
|
||||||
|
|
||||||
const result = await getSession()
|
const result = await getSession()
|
||||||
|
|
||||||
|
|||||||
@@ -3,37 +3,17 @@
|
|||||||
* Tests the allowTies field is properly saved when updating tournaments
|
* Tests the allowTies field is properly saved when updating tournaments
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, expect, mock, beforeEach,} from 'bun:test';
|
import { describe, it, expect, mock, beforeEach, afterAll } from 'bun:test';
|
||||||
|
|
||||||
// Create mock functions at module level
|
// Create mock functions at module level
|
||||||
const eventFindUniqueMock = mock(async () => ({}));
|
const eventFindUniqueMock = mock(async () => ({}));
|
||||||
const eventUpdateMock = mock(async () => ({}));
|
const eventUpdateMock = mock(async () => ({}));
|
||||||
const userFindUniqueMock = mock(async () => ({
|
const canManageTournamentMock = mock(async () => ({ allowed: true }));
|
||||||
id: 'admin-1',
|
const canDeleteTournamentMock = mock(async () => ({ allowed: true }));
|
||||||
email: 'admin@example.com',
|
|
||||||
role: 'club_admin',
|
|
||||||
emailVerified: false,
|
|
||||||
name: null,
|
|
||||||
image: null,
|
|
||||||
playerId: null,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Mock auth-simple to return a valid session
|
// Mock prisma first
|
||||||
mock.module('@/lib/auth-simple', () => ({
|
|
||||||
getSession: mock(async () => ({
|
|
||||||
user: { id: 'admin-1', email: 'admin@example.com' },
|
|
||||||
session: { token: 'test', expiresAt: new Date() }
|
|
||||||
})),
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Mock prisma with user and event
|
|
||||||
mock.module('@/lib/prisma', () => ({
|
mock.module('@/lib/prisma', () => ({
|
||||||
prisma: {
|
prisma: {
|
||||||
user: {
|
|
||||||
findUnique: userFindUniqueMock,
|
|
||||||
},
|
|
||||||
event: {
|
event: {
|
||||||
findUnique: eventFindUniqueMock,
|
findUnique: eventFindUniqueMock,
|
||||||
update: eventUpdateMock,
|
update: eventUpdateMock,
|
||||||
@@ -41,6 +21,17 @@ mock.module('@/lib/prisma', () => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Mock the permissions module
|
||||||
|
mock.module('@/lib/permissions', () => ({
|
||||||
|
canManageTournament: canManageTournamentMock,
|
||||||
|
canDeleteTournament: canDeleteTournamentMock,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Cleanup after all tests in this file
|
||||||
|
afterAll(() => {
|
||||||
|
mock.restore('module');
|
||||||
|
});
|
||||||
|
|
||||||
// Import the route handler after mocking
|
// Import the route handler after mocking
|
||||||
import { PUT } from '@/app/api/tournaments/[id]/route';
|
import { PUT } from '@/app/api/tournaments/[id]/route';
|
||||||
import { prisma } from '@/lib/prisma';
|
import { prisma } from '@/lib/prisma';
|
||||||
@@ -50,7 +41,8 @@ describe('Tournament Update API', () => {
|
|||||||
// Clear all mock history before each test
|
// Clear all mock history before each test
|
||||||
eventFindUniqueMock.mockClear();
|
eventFindUniqueMock.mockClear();
|
||||||
eventUpdateMock.mockClear();
|
eventUpdateMock.mockClear();
|
||||||
userFindUniqueMock.mockClear();
|
canManageTournamentMock.mockClear();
|
||||||
|
canDeleteTournamentMock.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update allowTies field when provided', async () => {
|
it('should update allowTies field when provided', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user