Skip to content

Commit

Permalink
fix: deps
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Nov 15, 2024
1 parent 0b640dd commit 2828210
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 69 deletions.
5 changes: 3 additions & 2 deletions packages/backend/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"test:coverage": "c8 ava --concurrency 1 --serial",
"test:copilot:e2e:coverage": "c8 ava --timeout=5m \"tests/**/copilot-*.e2e.ts\"",
"test:copilot:spec:coverage": "c8 ava --timeout=5m \"tests/**/copilot-*.spec.ts\"",
"test:copilot:e2e:cron": "TS_NODE_PROJECT=\"./tests/tsconfig.e2e.json\" ava \"tests/**/copilot-*.e2e.ts\"",
"postinstall": "prisma generate",
"data-migration": "node --loader ts-node/esm/transpile-only.mjs ./src/data/index.ts",
"predeploy": "yarn prisma migrate deploy && node --import ./scripts/register.js ./dist/data/index.js run",
Expand Down Expand Up @@ -89,6 +90,7 @@
"ses": "^1.4.1",
"socket.io": "^4.7.5",
"stripe": "^17.0.0",
"supertest": "^7.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.6.3",
"yjs": "patch:yjs@npm%3A13.6.18#~/.yarn/patches/yjs-npm-13.6.18-ad0d5f7c43.patch",
Expand All @@ -112,8 +114,7 @@
"@types/supertest": "^6.0.2",
"c8": "^10.0.0",
"nodemon": "^3.1.0",
"sinon": "^19.0.0",
"supertest": "^7.0.0"
"sinon": "^19.0.0"
},
"ava": {
"timeout": "1m",
Expand Down
20 changes: 20 additions & 0 deletions packages/backend/server/tests/tsconfig.e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ES2022",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"rootDir": ".",
"outDir": "../lib/tests",
"verbatimModuleSyntax": false,
"tsBuildInfoFile": "../lib/tests/.tsbuildinfo"
},
"include": [".", "utils"],
"exclude": [],
"ts-node": {
"esm": true,
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node"
}
}
}
12 changes: 6 additions & 6 deletions packages/backend/server/tests/utils/blobs.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { INestApplication } from '@nestjs/common';
import request from 'supertest';

import { gql } from './common';
import { gqlEndpoint } from './common';

export async function listBlobs(
app: INestApplication,
token: string,
workspaceId: string
): Promise<string[]> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -29,7 +29,7 @@ export async function getWorkspaceBlobsSize(
workspaceId: string
): Promise<number> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.send({
query: `
Expand All @@ -49,7 +49,7 @@ export async function collectAllBlobSizes(
token: string
): Promise<number> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.send({
query: `
Expand All @@ -71,7 +71,7 @@ export async function checkBlobSize(
size: number
): Promise<number> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.send({
query: `query checkBlobSize($workspaceId: String!, $size: SafeInt!) {
Expand All @@ -92,7 +92,7 @@ export async function setBlob(
buffer: Buffer
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.field(
Expand Down
38 changes: 37 additions & 1 deletion packages/backend/server/tests/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
export const gql = '/graphql';
import { INestApplication } from '@nestjs/common';
import type { Response } from 'supertest';
import supertest from 'supertest';

export function handleGraphQLError(resp: Response) {
const { errors } = resp.body;
if (errors) {
const cause = errors[0];
const stacktrace = cause.extensions?.stacktrace;
throw new Error(
stacktrace
? Array.isArray(stacktrace)
? stacktrace.join('\n')
: String(stacktrace)
: cause.message,
cause
);
}
}

export function gql(app: INestApplication, query?: string) {
const req = supertest(app.getHttpServer())
.post('/graphql')
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' });

if (query) {
return req.send({ query });
}

return req;
}

export const gqlEndpoint = '/graphql';

export async function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
11 changes: 5 additions & 6 deletions packages/backend/server/tests/utils/copilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import {
WorkflowNodeType,
WorkflowParams,
} from '../../src/plugins/copilot/workflow/types';
import { gql } from './common';
import { handleGraphQLError, sleep } from './utils';
import { gqlEndpoint, handleGraphQLError, sleep } from './common';

// @ts-expect-error no error
export class MockCopilotTestProvider
Expand Down Expand Up @@ -167,7 +166,7 @@ export async function createCopilotSession(
promptName: string
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -194,7 +193,7 @@ export async function forkCopilotSession(
latestMessageId: string
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand Down Expand Up @@ -224,7 +223,7 @@ export async function createCopilotMessage(
params?: Record<string, string>
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand Down Expand Up @@ -366,7 +365,7 @@ export async function getHistories(
}
): Promise<History[]> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/server/tests/utils/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { INestApplication } from '@nestjs/common';
import request from 'supertest';

import type { InvitationType } from '../../src/core/workspaces';
import { gql } from './common';
import { gqlEndpoint } from './common';

export async function inviteUser(
app: INestApplication,
Expand All @@ -13,7 +13,7 @@ export async function inviteUser(
sendInviteMail = false
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -34,7 +34,7 @@ export async function acceptInviteById(
sendAcceptMail = false
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
query: `
Expand All @@ -54,7 +54,7 @@ export async function leaveWorkspace(
sendLeaveMail = false
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -75,7 +75,7 @@ export async function revokeUser(
userId: string
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -95,7 +95,7 @@ export async function getInviteInfo(
inviteId: string
): Promise<InvitationType> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand Down
14 changes: 7 additions & 7 deletions packages/backend/server/tests/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../../src/core/auth';
import { sessionUser } from '../../src/core/auth/service';
import { UserService, type UserType } from '../../src/core/user';
import { gql } from './common';
import { gqlEndpoint } from './common';

export async function internalSignIn(app: INestApplication, userId: string) {
const auth = app.get(AuthService);
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function signUp(

export async function currentUser(app: INestApplication, token: string) {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -90,7 +90,7 @@ export async function sendChangeEmail(
callbackUrl: string
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -112,7 +112,7 @@ export async function sendSetPasswordEmail(
callbackUrl: string
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -134,7 +134,7 @@ export async function changePassword(
password: string
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
query: `
Expand All @@ -156,7 +156,7 @@ export async function sendVerifyChangeEmail(
callbackUrl: string
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -178,7 +178,7 @@ export async function changeEmail(
email: string
): Promise<UserType & { token: ClientTokenType }> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand Down
34 changes: 0 additions & 34 deletions packages/backend/server/tests/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { Test, TestingModuleBuilder } from '@nestjs/testing';
import { PrismaClient } from '@prisma/client';
import cookieParser from 'cookie-parser';
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
import type { Response } from 'supertest';
import supertest from 'supertest';

import { AppModule, FunctionalityModules } from '../../src/app.module';
import { AuthGuard, AuthModule } from '../../src/core/auth';
Expand Down Expand Up @@ -152,35 +150,3 @@ export async function createTestingApp(moduleDef: TestingModuleMeatdata = {}) {
app,
};
}

export function handleGraphQLError(resp: Response) {
const { errors } = resp.body;
if (errors) {
const cause = errors[0];
const stacktrace = cause.extensions?.stacktrace;
throw new Error(
stacktrace
? Array.isArray(stacktrace)
? stacktrace.join('\n')
: String(stacktrace)
: cause.message,
cause
);
}
}

export function gql(app: INestApplication, query?: string) {
const req = supertest(app.getHttpServer())
.post('/graphql')
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' });

if (query) {
return req.send({ query });
}

return req;
}

export async function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Loading

0 comments on commit 2828210

Please sign in to comment.