| 1 | import type { AddressInfo } from 'node:net'; |
| 2 | import type { INestApplication |
| 3 | import { Test } |
| 4 | import { AuthService } |
| 5 | |
| 6 | import type { Auth |
| 7 | |
| 8 | export const DATABASE_URL = |
| 9 | export const S3_ENDPOINT = |
| 10 | |
| 11 | export const s3Credentials = |
| 12 | S3_ACCESS_KEY_ID: process.env |
| 13 | S3_SECRET_ACCESS_KEY: process.env |
| 14 | S3_BUCKET: process.env |
| 15 | }; |
| 16 | |
| 17 | /** Suites need a throwaway Postgres and an S3 endpoint (RustFS from compose.yaml works), and are skipped without them. */ |
| 18 | export const hasBackends = |
| 19 | |
| 20 | /** Serves the whole app on a random port, against the database and bucket global-setup.ts prepared. */ |
| 21 | export async function startApp |
| 22 | Object.assign(process |
| 23 | DATABASE_URL, |
| 24 | S3_ENDPOINT, |
| 25 | ...s3Credentials, |
| 26 | BETTER_AUTH_SECRET: 'e2e-secret-e2e-secret-e2e-secret', |
| 27 | BETTER_AUTH_URL: 'http://127.0.0.1', |
| 28 | EMAIL_VERIFICATION_ENABLED: 'false', |
| 29 | // A local .env may configure real delivery; tests must never send mail. |
| 30 | EMAIL_PROXY: '', |
| 31 | MAIL_HOST: '', |
| 32 | ZOEKT_URL: '', |
| 33 | GIT_SSH_HOST_KEY: '', |
| 34 | OTEL_EXPORTER_OTLP_ENDPOINT: '', |
| 35 | PYROSCOPE_SERVER_ADDRESS: '', |
| 36 | }); |
| 37 | |
| 38 | // Imported late so the module reads the environment set above. |
| 39 | const { AppModule |
| 40 | const { configureApp |
| 41 | const moduleRef = |
| 42 | imports: [AppModule], |
| 43 | }).compile(); |
| 44 | const app = |
| 45 | configureApp(app); |
| 46 | await app.listen |
| 47 | |
| 48 | return { |
| 49 | app, |
| 50 | origin: `http://127.0.0.1:${(app |
| 51 | }; |
| 52 | } |
| 53 | |
| 54 | /** A fresh account with a session cookie for the API and an API key for git over HTTP. */ |
| 55 | export async function signUp |
| 56 | const auth = |
| 57 | const email = |
| 58 | const password = |
| 59 | const { user |
| 60 | body: { email, |
| 61 | }); |
| 62 | const { headers |
| 63 | body: { email, |
| 64 | returnHeaders: true, |
| 65 | }); |
| 66 | const { key |
| 67 | |
| 68 | return { cookie: |
| 69 | } |