-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcypress.config.ts
More file actions
152 lines (145 loc) · 4.95 KB
/
cypress.config.ts
File metadata and controls
152 lines (145 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { defineConfig } from "cypress";
import { databaseDrizzle } from "./db";
import { apiKeys, users } from "./db/schemas/users";
import * as dotenv from "dotenv";
import { eq } from "drizzle-orm";
import { apiKeyGenerator, hashApiKey } from "./lib/api_key";
import { QdrantClient } from "@qdrant/js-client-rest";
dotenv.config({ path: ".env" });
const qdrant_collection_name = "documents"
const qdrantClient = new QdrantClient({ url: process.env.QDRANT_DB_URL!, apiKey: process.env.QDRANT_DB_KEY });
export default defineConfig({
retries: {
runMode: 3,
openMode: 0
},
chromeWebSecurity: false,
watchForFileChanges: false,
e2e: {
defaultCommandTimeout: 20000,
setupNodeEvents(on) {
on("task", {
async getUserId({ email }: { email: string }) {
const user = await databaseDrizzle.query.users.findFirst({
where: (u, ops) => ops.eq(u.email, email),
columns: {
id: true,
}
})
return user?.id || null
},
async createCollection() {
try {
const { collections } = await qdrantClient.getCollections();
if (!collections.find(col => col.name === qdrant_collection_name)) {
await qdrantClient.createCollection(qdrant_collection_name, {
vectors: { size: 1536, distance: 'Cosine' },
});
}
} catch { }
return null
},
async deleteCollection() {
return await qdrantClient.deleteCollection(qdrant_collection_name)
},
async getPointsById({ chunkIds }: { chunkIds: string[] }) {
return await qdrantClient.retrieve(qdrant_collection_name, {
ids: chunkIds,
with_payload: true,
})
},
async getPointsNumberByFileName({ fileName, userId }: { fileName: string, userId: string }) {
const existingPoints = await qdrantClient.scroll(qdrant_collection_name, {
filter: {
must: [
{ key: "_document_id", match: { value: fileName } },
{ key: "_userId", match: { value: userId } }
]
},
});
return existingPoints.points.length
},
async createApiKey({ id }: { id: string }) {
const apiKey = apiKeyGenerator()
const hashedKey = hashApiKey(apiKey);
await databaseDrizzle.insert(apiKeys).values({
userId: id,
name: id.slice(0, 5),
generatedTime: new Date(),
apiKey: hashedKey,
});
return apiKey
},
async uploadFile({ key, form }) {
const response = await fetch('http://localhost:3000/api/upload', {
method: 'POST',
headers: {
Authorization: `Bearer ${key}`,
},
body: form,
});
const result = await response.json();
return { status: response.status, body: result };
},
async addNewUser({ email, name, image, plan }) {
await databaseDrizzle
.insert(users)
.values({ email, name, image, plan })
.onConflictDoNothing()
const user = await databaseDrizzle.query.users.findFirst({
where: eq(users.email, email)
})
return { id: user?.id, email, name, image }
},
async deleteUser({ email }) {
await databaseDrizzle.delete(users).where(eq(users.email, email))
return { email }
},
async getConnections({ email }) {
const user = await databaseDrizzle.query.users.findFirst({
where: (u, ops) => ops.eq(u.email, email),
with: {
connections: {
where: (c, ops) => ops.isNull(c.jobId),
with: {
files: true,
}
}
}
})
return { conns: user?.connections || [] }
},
async getConnection({ email }) {
while (true) {
const user = await databaseDrizzle.query.users.findFirst({
where: (u, ops) => ops.eq(u.email, email),
with: {
connections: {
where: (c, ops) => ops.isNull(c.jobId),
with: {
files: true,
}
}
}
})
if (user?.connections && user.connections.length > 0) {
return { conns: user.connections }
}
}
}
}
)
},
baseUrl: "http://localhost:3000",
},
env: {
NEXT_PUBLIC_APP_ENV: "TEST",
DCUP_PARSER: "http://localhost:9000",
NEXT_PUBLIC_GOOGLE_CLIENT_ID: "xxxxxxxxx",
GOOGLE_CLIENT_SECRET: "xxxxx",
NEXT_PUBLIC_GOOGLE_API_KEY: "xxx",
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET!,
NEXTAUTH_URL: "http://localhost:3000",
DRIZZLE_DATABASE_URL: "postgres://postgres:root@127.0.0.1:5432/dcupTest",
}
});