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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/todo.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: todo
about: 'task to do '
title: "[TODO]"
title: ""
labels: enhancement
assignees: ''

Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/devs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: CI

on:
pull_request:
branches: [ main ]

jobs:
verify:
name: Install → Build → Lint → Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "20"
cache: npm
- run: npm ci
- run: npm run lint
- run: npm test

e2e:
name: E2E (Cypress via Docker + Next.js)
needs: verify
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

# 1) install JS deps so `next dev` exists:
- name: Install dependencies
run: npm ci

# 2) generate a full .env before starting anything:
- name: Generate Env File
run: |
cat <<EOF > .env
REDIS_DB_ADDRESS=localhost
REDIS_DB_PORT=6379
REDIS_DB_PASSWORD=
REDIS_DB_DATABASE=0
OPENAI_KEY="my key"
NEXTAUTH_SECRET=tZuoxOlhNxw7Q/r3DCiuVKZJ7op1dX/XTLYqG3rEurA=
DRIZZLE_DATABASE_URL=postgres://postgres:root@localhost:5432/dcup
EOF

# 3) spin up your other services (redis, postgres, etc):
- name: Start services with Make
run: |
make docker-run &
sleep 10 # give containers time to initialize

# 4) start your Next.js app in dev mode
- name: Start Next.js
run: |
npm run dev &
sleep 10 # give Next.js time to boot

# 5) wait for both web & db ports
- name: Wait for HTTP & Postgres
run: |
npx wait-on http://localhost:3000
npx wait-on tcp:5432

- name: set up DB
run: npm run generate && npm run pushdb

# 6) run Cypress
- name: Run Cypress E2E
env:
CYPRESS_baseUrl: http://localhost:3000
run: npx cypress run

# 7) teardown your Docker services
- name: Stop services
if: always()
run: make docker-down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Create DB container
docker-run:
@if docker compose -f docker-compose.dev.yml up --build 2>/dev/null; then \
@if docker compose -f docker-compose.dev.yml up 2>/dev/null; then \
: ; \
else \
echo "Falling back to Docker Compose V1"; \
Expand Down
16 changes: 3 additions & 13 deletions auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,12 @@ export const authOptions: NextAuthOptions = {
session: async ({ session, token }) => {
if (session) {
session.user.id = token.id as string;
session.user.name = token.name as string;
session.user.email = token.email as string;
session.user.image = token.picture as string
}
return session;
},
jwt: async ({ user, token }) => {
if (user) {
token.id = user.id;
} else {
const dbUser = await databaseDrizzle.query.users.findFirst({
where: (u, opt) => opt.eq(u.id, token.id as string),
});
if (dbUser) {
token.plan = dbUser.plan;
}
}
return token;
},
},
providers: [
GoogleProvider({
Expand Down
1 change: 1 addition & 0 deletions components/Connectors/Connectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const Connectors = async () => {
{connectors.map(async (connector) => {
return (
<Card
data-test="connection-card"
key={connector.id}
className="p-6 hover:shadow-lg transition-shadow duration-200 w-full max-w-sm mx-auto"
>
Expand Down
35 changes: 35 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { defineConfig } from "cypress";
import { databaseDrizzle } from "./db";
import { users } from "./db/schemas/users";
import * as dotenv from "dotenv";
import { eq } from "drizzle-orm";
dotenv.config({ path: ".env" });

export default defineConfig({
chromeWebSecurity: false,
e2e: {
setupNodeEvents(on) {
on("task", {
async addNewUser({ id, email, name, image }) {
await databaseDrizzle
.insert(users)
.values({ id, email, name, image })
.onConflictDoNothing()

const user = await databaseDrizzle.query.users.findFirst({
where: eq(users.email, email)
})

return { id: user?.id, email, name, image }
}
}
)
},
baseUrl: "http://localhost:3000",
},
env: {
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET!,
NEXTAUTH_URL: "http://localhost:3000",
DRIZZLE_DATABASE_URL: "postgres://postgres:root@127.0.0.1:5432/dcupTest",
}
});
31 changes: 31 additions & 0 deletions cypress/e2e/connections.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe('connect to google drive', () => {
const fakeUser = {
id: "3abd5c17-7f80-4a3e-8c3e-7a24e0185aea",
name: "test man",
email: "tester@dcup.dev",
provider: "google",
image: `https://via.placeholder.com/200/7732bb/c0392b.png?text=tester`,
}

beforeEach(() => {
// login
cy.visit('/')
.location('pathname')
.should('eq', '/login')
.task('addNewUser', fakeUser)
.then((result) => {
cy.loginNextAuth(result as any)
})
.visit('/')
.location('pathname')
.should('eq', '/')
})

it('should create new google drive connection ', () => {
cy.visit("/connections/new")
.get('[data-test="connection-card"]')
.contains("Google Drive", { matchCase: false })
.should("be.visible");
// todo connected
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
78 changes: 78 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { v4 as uuidv4 } from "uuid";
import { encode } from "next-auth/jwt";
import type { JWT } from "next-auth/jwt";

Cypress.Commands.add("loginNextAuth", ({ id, name, email , image}) => {
Cypress.log({
displayName: "NEXT-AUTH LOGIN",
message: [`🔐 Authenticating | ${name}`],
});

const now = Math.floor(Date.now() / 1000);
const expiry = now + 30 * 24 * 60 * 60; // 30 days
const cookieName = "next-auth.session-token";

// Only include the exact fields NextAuth expects:
const tokenPayload: JWT = {
id,
name,
email,
picture:image,
iat: now,
exp: expiry,
jti: uuidv4(),
};

return cy
.wrap(encode({ token: tokenPayload, secret: Cypress.env("NEXTAUTH_SECRET") }))
.then((encrypted) => {
return cy.setCookie(cookieName, encrypted as string, {
log: false,
httpOnly:true,
path: "/",
expiry,
});
});
});




/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
declare global {
namespace Cypress {
interface Chainable {
loginNextAuth({id, name, email, image}: {id:string, name:string, email:string,image:string}): Chainable<Cookie>
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
}
}
}
17 changes: 17 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
30 changes: 30 additions & 0 deletions fileProcessors/connectors/__tests__/dropbox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DropboxAuth } from 'dropbox';
import { authDropbox } from "../dropbox";

jest.mock('dropbox');

process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID = 'CID';
process.env.GOOGLE_CLIENT_SECRET = 'SEC';
process.env.NEXTAUTH_URL = 'https://app.test';

const mockGenerateAuthUrl = jest.fn().mockResolvedValue('https://fake-url');
(DropboxAuth as unknown as jest.Mock).mockImplementation(() => ({
getAuthenticationUrl: mockGenerateAuthUrl,
setCredentials: jest.fn(),
on: jest.fn(),
}));

describe('authDropbox', () => {
it('builds an OAuth2 and returns authUrl', async () => {
const url = await authDropbox();
expect(mockGenerateAuthUrl).toHaveBeenCalledWith(
`${process.env.NEXTAUTH_URL}/api/connections/dropbox/callback`,
undefined,
'code',
'offline',
["files.metadata.read", "files.content.read", "email", "openid", "account_info.read"]
);

expect(url).toBe('https://fake-url&force_reapprove=true');
});
});
Loading