Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use seeding from integration tests in cypress #5881

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ schema.graphql
resolvers.generated.ts

docker/docker-compose.override.yml

vite.config.ts.*.mjs
58 changes: 32 additions & 26 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fs from 'node:fs';
// eslint-disable-next-line import/no-extraneous-dependencies -- cypress SHOULD be a dev dependency
import { defineConfig } from 'cypress';
import { initSeed } from 'integration-tests/testkit/seed.js';
// eslint-disable-next-line import/no-extraneous-dependencies
import pg from 'pg';
import 'integration-tests/local-dev.js';

const isCI = Boolean(process.env.CI);

Expand All @@ -22,6 +24,8 @@ export default defineConfig({
},
e2e: {
setupNodeEvents(on, config) {
const seed = initSeed();

async function connectDB(query: string) {
const dbUrl = new URL(config.env.POSTGRES_URL);
const client = new pg.Client({
Expand Down Expand Up @@ -67,32 +71,34 @@ COMMIT;
firstName?: string;
lastName?: string;
} = {}) {
const response = await fetch('http://localhost:3001/auth-api/signup', {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
formFields: [
{ id: 'email', value: email },
{ id: 'password', value: password },
{ id: 'firstName', value: firstName },
{ id: 'lastName', value: lastName },
],
}),
});
const data = await response.json();
if (response.status !== 200 || data.status === 'FIELD_ERROR') {
throw new Error(
`${response.status}: ${response.statusText}\n\n${JSON.stringify(data, null, 2)}`,
);
}
const result: Token = {
sAccessToken: response.headers.get('st-access-token')!,
sFrontToken: response.headers.get('front-token')!,
sRefreshToken: response.headers.get('st-refresh-token')!,
};
return result;
const { createOrg, ownerToken } = seed.createOwner(email);

// const response = await fetch('http://localhost:3001/auth-api/signup', {
// method: 'POST',
// headers: {
// 'content-type': 'application/json',
// },
// body: JSON.stringify({
// formFields: [
// { id: 'email', value: email },
// { id: 'password', value: password },
// { id: 'firstName', value: firstName },
// { id: 'lastName', value: lastName },
// ],
// }),
// });
// const data = await response.json();
// if (response.status !== 200 || data.status === 'FIELD_ERROR') {
// throw new Error(
// `${response.status}: ${response.statusText}\n\n${JSON.stringify(data, null, 2)}`,
// );
// }
// const result: Token = {
// sAccessToken: response.headers.get('st-access-token')!,
// sFrontToken: response.headers.get('front-token')!,
// sRefreshToken: response.headers.get('st-refresh-token')!,
// };
// return result;
},
async login() {
const response = await fetch('http://localhost:3001/auth-api/signin', {
Expand Down
7 changes: 5 additions & 2 deletions integration-tests/local-dev.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFileSync } from 'fs';
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { parse } from 'dotenv';

function applyEnv(env: Record<string, string>) {
Expand All @@ -7,7 +8,9 @@ function applyEnv(env: Record<string, string>) {
}
}

const serverEnvVars = parse(readFileSync('../packages/services/server/.env', 'utf-8'));
const envPath = path.join(process.cwd(), 'packages', 'services', 'server', '.env');

const serverEnvVars = parse(readFileSync(envPath, 'utf-8'));

applyEnv({
SUPERTOKENS_CONNECTION_URI: serverEnvVars.SUPERTOKENS_CONNECTION_URI,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/testkit/schema-policy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RuleInstanceSeverityLevel, SchemaPolicyInput } from 'testkit/gql/graphql';
import { RuleInstanceSeverityLevel, SchemaPolicyInput } from './gql/graphql';
import { graphql } from './gql';

export const OrganizationAndProjectsWithSchemaPolicy = graphql(`
Expand Down
8 changes: 3 additions & 5 deletions integration-tests/testkit/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
RegistryModel,
SchemaPolicyInput,
TargetAccessScope,
TargetSelectorInput,
} from 'testkit/gql/graphql';
} from './gql/graphql';
import { authenticate, userEmail } from './auth';
import {
CreateCollectionMutation,
Expand Down Expand Up @@ -83,10 +82,9 @@ export function initSeed() {
},
};
},
authenticate: authenticate,
authenticate,
generateEmail: () => userEmail(generateUnique()),
async createOwner() {
const ownerEmail = userEmail(generateUnique());
async createOwner(ownerEmail = userEmail(generateUnique())) {
const ownerToken = await authenticate(ownerEmail).then(r => r.access_token);

return {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"release": "pnpm build:libraries && changeset publish",
"seed": "tsx scripts/seed-local-env.ts",
"start": "pnpm run local:setup",
"pretest:e2e":"pnpm --filter integration-tests start",
"test": "vitest",
"test:e2e": "CYPRESS_BASE_URL=$HIVE_APP_BASE_URL cypress run",
"test:integration": "cd integration-tests && pnpm test:integration",
Expand Down
Loading