Compare commits

...

4 commits

Author SHA1 Message Date
Lukasz Ostrowski
722e1ce5cc readme 2023-04-14 13:21:56 +02:00
Lukasz Ostrowski
8cb9cbfbae cleanup 2023-04-14 13:21:55 +02:00
Lukasz Ostrowski
458835c731 Created app 2023-04-14 13:21:26 +02:00
Lukasz Ostrowski
7ab001ecd6 Setup e2e package with app template 2023-04-14 13:21:04 +02:00
20 changed files with 74204 additions and 217 deletions

View file

@ -0,0 +1,5 @@
---
"e2e-toolkit": major
---
Introduce e2e-toolkit package (cli) with a single feature - removing all apps from provided env

View file

@ -0,0 +1,4 @@
{
"root": true,
"extends": ["saleor"]
}

1
packages/e2e-toolkit/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
dist/

View file

@ -0,0 +1,16 @@
schema: graphql/schema.graphql
documents: [graphql/**/*.graphql, src/**/*.ts, src/**/*.tsx]
extensions:
codegen:
overwrite: true
generates:
generated/graphql.ts:
config:
dedupeFragments: true
plugins:
- typescript
- typescript-operations
- typed-document-node
generated/schema.graphql:
plugins:
- schema-ast

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,5 @@
mutation Authorize($email: String!, $password: String!) {
tokenCreate(email: $email, password: $password) {
token
}
}

View file

@ -0,0 +1,10 @@
mutation UninstallApp($appId: ID!) {
appDelete(id: $appId) {
app {
id
}
errors {
message
}
}
}

View file

@ -0,0 +1,11 @@
query FetchAllApps {
apps(first: 100) {
edges {
node {
id
name
appUrl
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,42 @@
{
"name": "e2e-toolkit",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "pnpm generate && tsup src/cli.ts --watch",
"build": "pnpm generate && tsup src/cli.ts",
"start": "node dist/cli.ts",
"lint": "next lint",
"fetch-schema": "curl https://raw.githubusercontent.com/saleor/saleor/${npm_package_saleor_schemaVersion}/saleor/graphql/schema.graphql > graphql/schema.graphql",
"generate": "graphql-codegen",
"test": "vitest"
},
"saleor": {
"schemaVersion": "3.10"
},
"dependencies": {
"@urql/exchange-auth": "^1.0.0",
"@vitejs/plugin-react": "^3.0.1",
"commander": "^10.0.0",
"graphql": "^16.6.0",
"graphql-tag": "^2.12.6",
"jsdom": "^20.0.3",
"tsup": "^6.7.0",
"vite": "^4.0.4",
"vitest": "^0.27.1",
"graphql-request": "^6.0.0"
},
"devDependencies": {
"@graphql-codegen/cli": "2.13.3",
"@graphql-codegen/introspection": "2.2.1",
"@graphql-codegen/typed-document-node": "^2.3.3",
"@graphql-codegen/typescript": "2.7.3",
"@graphql-codegen/typescript-operations": "2.5.3",
"@graphql-typed-document-node/core": "^3.1.1",
"@types/node": "^18.11.18",
"eslint": "8.31.0",
"eslint-config-saleor": "workspace:*",
"typescript": "4.9.4"
}
}

View file

@ -0,0 +1,5 @@
# Usage
1. `pnpm install`
2. `pnpm build --filter="e2e-toolkit"`
3. `pnpm start --filter="e2e-toolkit" remove-apps --email [your email] --password [your password] --saleor [saleor graphql/ url]`

View file

@ -0,0 +1,95 @@
import { Command } from "commander";
import { GraphQLClient } from "graphql-request";
import {
AuthorizeDocument,
FetchAllAppsDocument,
UninstallAppDocument,
} from "../generated/graphql";
const program = new Command();
program
.name("e2e-util")
.description("Perform operations for e2e test orchestration")
.version("0.0.0");
program
.command("remove-apps")
.description("Removes all apps from provided env")
.requiredOption("--email <type>", "Email for user with MANAGE_APPS permission")
.requiredOption("--password <type>", "Password for the user")
.requiredOption("--saleor <type>", "saleor api URL ending with /graphql/")
.action(async (fields: { email: string; password: string; saleor: string }) => {
const { email, password, saleor } = fields;
const client = new GraphQLClient(saleor);
const tokenResponse = await client
.request(AuthorizeDocument, {
email,
password,
})
.catch((e) => {
console.error("Failed with authorization, check params");
console.error(e);
process.exit(1);
});
const token = tokenResponse.tokenCreate?.token;
if (!token) {
console.error("Cant fetch token, check auth");
process.exit(1);
}
client.setHeader("Authorization", `Bearer ${token}`);
const allAppsResponse = await client.request(FetchAllAppsDocument).catch((e) => {
console.error(e);
process.exit(1);
});
console.log("Fetch apps");
const apps = allAppsResponse.apps?.edges;
if (!apps) {
console.error("Can fetch apps");
process.exit(1);
}
if (apps.length === 0) {
console.log("No apps installed");
process.exit(0);
}
const appsNodes = apps.map((appEdge) => appEdge.node);
appsNodes.forEach((app) => {
console.log(`[${app.id}] ${app.name}`);
});
await Promise.all(
appsNodes.map((appNode) => {
return client
.request(UninstallAppDocument, { appId: appNode.id })
.then((resp) => {
if (resp && resp.appDelete?.app?.id) {
console.log(`Uninstalled ${appNode.id}`);
} else {
throw new Error("Failed removing app");
}
return resp;
})
.catch((e) => {
console.error(`Failed uninstalling ${appNode.id}`);
return;
});
})
);
console.log("Removed apps");
});
program.parse();

View file

@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}

View file

@ -0,0 +1,13 @@
import react from "@vitejs/plugin-react";
import { defineConfig } from "vitest/config";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
test: {
passWithNoTests: true,
environment: "jsdom",
setupFiles: "./src/setup-tests.ts",
css: false,
},
});

File diff suppressed because it is too large Load diff